DEV Community

Cover image for Day 5 - 100 days 100 python scripts challenge
Ganesh Raja
Ganesh Raja

Posted on

2 1

Day 5 - 100 days 100 python scripts challenge

To Know about the full challenge please go this link.

Click here to read the 100 days 100 Python Scripts Challenge

Day 5: append_read_me

So every day when I create a new script I have to update read.me file manually. But this will automatically read the previous date and last updated file and append it to the readme. Once I give the description, it will also update it with proper spaces.

import glob
import os,sys


pwd=os.getcwd()+r"/"

list_of_files = glob.glob(pwd+'*.py') 
latest_file = max(list_of_files, key=os.path.getctime)

last_updated_python_file_name=latest_file.split(r"/")[-1]

data=[]
with open('README.md') as f:
    data=f.readlines()
last_date=None
is_already_added=False
for c in reversed(data):
    if "## Day " in c:
        if not last_date:
            last_date=c.strip()
        if last_updated_python_file_name in c:
            is_already_added=True
            break
if is_already_added:
    print("Last updated file "+last_updated_python_file_name+" is already added")
    sys.exit(0)

try:
    today_number=int(last_date[7])+1
except:
    pass

new_data="\n\n## Day "+str(today_number)+": "+last_updated_python_file_name+"\n"

desc=input("Please Enter description for "+last_updated_python_file_name+"\n")

new_data=new_data+desc.strip()

with open('README.md',"a+") as file:
    file.write(new_data)
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

Image of Quadratic

Free AI chart generator

Upload data, describe your vision, and get Python-powered, AI-generated charts instantly.

Try Quadratic free

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay