A friend and I, were talking about a problem he had when he was doing #100DaysOfCode Challenge. After a couple of days he’d forget to tweet his progress. He asked me if there is a way to open twitter and post his progress in a specific time. I came with the idea of using NodeJs and create a script and a cron job in Linux to open tweeter in a specific time but we leave that project forgotten.
3 months later I made a script but using python. Here is what it does:
1 - It loads a .json file containing the counter representing your days in the challenge, If it doesn’t exit, It’ll create a new one and started with 1.
2- Gets current date using datetime module
3- creates a URL containing the actual date, #100DaysOfCode hashtag,the current day in the challenge and the increase in one for the next day. Using webbrowser module, opens a web intent in your default browser.
"""Opens a new Web Intent from Twitter to tweet your #100Daysofcode progress""" import webbrowser from datetime import datetime import os import json def save_day_count(file,count): #Saves count for the next day try: with open(file,"w") as file_json: json.dump(count,file_json) except Exception as e: print(e) def getting_day_count(file): #Check if file with current day exist if os.path.isfile(file): try: with open(file) as f_obj: #loads current day days = json.load(f_obj) except FileNotFoundError as ex : print(ex) else: #Incriases one and saves for the next day days += 1 save_day_count(file,days) return days else: #Creates a new file if it doesn't exist and starts the counter in 1 days = 1 save_day_count(file,days) return days days = getting_day_count("counter.json") date = str(datetime.now().date()) #Gets current date url = "https://twitter.com/intent/tweet?hashtags=100DaysofCode%0A" + date + "[Day " + str(days) +"]" webbrowser.open_new_tab(url)
If you are like me, you don't have to forget again to tweet your progress
Like to the CODE
If your liked it share it or if didn't leave a feedback, I'll appreciate it.