DEV Community

Cristhian Ferreira
Cristhian Ferreira

Posted on • Edited on

3 1

Open Web Intent to Tweet #100DaysOfCode Progress


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.

It will opens something like this


"""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.

Happy Coding!!!

Image of Datadog

How to Diagram Your Cloud Architecture

Cloud architecture diagrams provide critical visibility into the resources in your environment and how they’re connected. In our latest eBook, AWS Solution Architects Jason Mimick and James Wenzel walk through best practices on how to build effective and professional diagrams.

Download the Free eBook

Top comments (0)

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay