Skip to content

Instantly share code, notes, and snippets.

@dbrant
Created January 22, 2025 16:26
Show Gist options
  • Select an option

  • Save dbrant/86943183d8b31e2ce574c9a2945d7ea9 to your computer and use it in GitHub Desktop.

Select an option

Save dbrant/86943183d8b31e2ce574c9a2945d7ea9 to your computer and use it in GitHub Desktop.
Retrieve the number of on-this-day events from a given language Wikipedia.
# Retrieve the number of on-this-day events from a given language Wikipedia,
# iterated over all days of all months of the year.
# usage: onthisday.py [en|de|ru|...]
#
# Dmitry Brant, 2025
import sys
import requests
daysPerMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def getOnThisDay(language, month, day):
req = "https://" + language + ".wikipedia.org/api/rest_v1/feed/onthisday/events/" + str(month).zfill(2) + "/" + str(day).zfill(2)
events = requests.get(req).json()['events']
return len(events)
language = sys.argv[1]
file = open("onthisday_" + language + ".csv", "w", encoding="utf-8")
for month in range(1, 13):
for day in range(1, daysPerMonth[month-1] + 1):
numEvents = getOnThisDay(language, month, day)
line = str(month) + "\t" + str(day) + "\t" + str(numEvents)
print(language + ": " + str(month) + "/" + str(day) + ": " + str(numEvents))
file.write(line + "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment