Skip to content

Instantly share code, notes, and snippets.

@JoGall
Last active December 11, 2022 12:08
Show Gist options
  • Save JoGall/47b061407d77c2638828631134060bcb to your computer and use it in GitHub Desktop.
Save JoGall/47b061407d77c2638828631134060bcb to your computer and use it in GitHub Desktop.
Generates a search URL for twitter.com to retrieve tweets on this day by a given user and opens results in system default browser
"""
Generates a search URL for twitter.com to retrieve tweets on this day (#OTD)
by a given user and opens results in system default browser
Usage:
python ./twitter_otd.py
Author:
Joe Gallagher (@joedgallagher)
"""
# SET PARAMS ====================================
twitter_handle = 'joedgallagher'
year_you_joined_twitter = 2013
# /END ==========================================
import webbrowser
from datetime import date
from dateutil.relativedelta import relativedelta
# generate search url
year_today = int(f'{date.today():%Y}')
url = f'https://twitter.com/search?q=from%3A{twitter_handle}%20-filter%3Areplies%20'
for yrs in range(1, year_today - year_you_joined_twitter + 1):
if yrs != 1:
url += "%20OR%20"
since_date = f'{date.today() - relativedelta(years=yrs):%Y-%m-%d}'
until_date = f'{date.today() - relativedelta(years=yrs, days=-1):%Y-%m-%d}'
url += f'(since%3A{since_date}%20until%3A{until_date})'
# open in system default browser
webbrowser.get().open(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment