DEV Community

Cover image for Day 6 & Day 7 - 100 days 100 Python Scripts Challenge
Ganesh Raja
Ganesh Raja

Posted on

3

Day 6 & Day 7 - 100 days 100 Python Scripts Challenge

Day 6: convert_pdf_to_csv

This script helps you to convert the given PDF into CSV file and stores it in local


from tabula import read_pdf
import pandas as pd

FILE_NAME="" #Ppdf file as input
dest="" #destination csv file name

df= read_pdf(FILE_NAME)
x=df.values
data=pd.DataFrame(data=x[1:,1:],columns=x[0,1:])

data.to_csv(dest,sep=',',encoding="utf-8")
Enter fullscreen mode Exit fullscreen mode

Day 7: push_todays_script

This script will automatically track the updated files and commit those files and push them to the git.

import os,subprocess
from constants import WORKING_DIR

os.chdir(WORKING_DIR)

cmd = "git add ."
subprocess.check_output(cmd, shell=True)  

status= "git status -s"
returned_value = subprocess.check_output(status, shell=True) 

print('updated files:', returned_value)

if not returned_value==b'':
    commit_message='"Done Changed in the following files '
    if len(str(returned_value).split(r'\n'))>0:        
        for file_name in str(returned_value).split(r'\n'):
                    commit_message=commit_message+file_name[5:]+" "
        cmd= "git commit -m "+commit_message+r'"'
        print("Commit message ",subprocess.check_output(cmd, shell=True))
        try:
            cmd= "git push origin master"
            result = subprocess.check_output(cmd, shell=True)
            print(result) 
        except:
            cmd = "git pull"
            returned_value = subprocess.check_output(cmd, shell=True)  
            cmd = "git push origin master"
            result = subprocess.check_output(cmd, shell=True)
            print(result)
Enter fullscreen mode Exit fullscreen mode

Please Visit my Git Repo to check out all the previous day challenges.

https://github.com/ganeshraja10/automated-python-scripts

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Eliminate Context Switching and Maximize Productivity

Pieces.app

Pieces Copilot is your personalized workflow assistant, working alongside your favorite apps. Ask questions about entire repositories, generate contextualized code, save and reuse useful snippets, and streamline your development process.

Learn more