Skip to content

Instantly share code, notes, and snippets.

@JakeSteam
Last active December 7, 2024 20:42
Show Gist options
  • Save JakeSteam/86201fee9c0c06f319d7742436e0e364 to your computer and use it in GitHub Desktop.
Save JakeSteam/86201fee9c0c06f319d7742436e0e364 to your computer and use it in GitHub Desktop.
Script to parse all years & artists from "by artist1, artist2, artist3" in GitHub's Octodex feed
import xml.etree.ElementTree as ET
from collections import Counter
import re
# Source: https://octodex.github.com/atom.xml
tree = ET.parse('atom.xml')
root = tree.getroot()
artists = re.findall(r' by ([\w\s,]+)\n', ET.tostring(root, encoding='unicode', method='text'), re.IGNORECASE)
all_artists = []
for artist_list in artists:
all_artists.extend([artist.strip().lower() for artist in artist_list.split(',')])
sorted_artist_counts = Counter(all_artists).most_common()
print("| Artist | Count |")
print("|--------|-------|")
for artist, count in sorted_artist_counts:
print(f"| {artist} | {count} |")
| Artist | Count |
|--------|-------|
| cameronmcefee | 58 |
| jeejkang | 27 |
| johncreek | 15 |
| tonyjaramillo | 14 |
| heyhayhay | 11 |
| jasoncostello | 11 |
| cameronfoxly | 8 |
| jonrohan | 4 |
| rubyjazzy | 3 |
| nickh | 3 |
| leereilly | 2 |
| suziejurado | 2 |
| billyroh | 2 |
| chubbmo | 1 |
| ceciliorz | 1 |
| kimestoesta | 1 |
| jglovier | 1 |
| mattgraham | 1 |
| broccolini | 1 |
| jina | 1 |
| jordanmccullough | 1 |
| simon | 1 |
import xml.etree.ElementTree as ET
from collections import Counter
# Source: https://octodex.github.com/atom.xml
root = ET.parse('atom.xml').getroot()
# Skip first <updated> tag, which is the feed's last updated time
updated_tags = root.findall('.//{http://www.w3.org/2005/Atom}updated')[1:]
years = [tag.text[:4] for tag in updated_tags]
year_counts = Counter(years)
print("| Year | Count |")
print("|------|-------|")
for year, count in sorted(year_counts.items()):
print(f"| {year} | {count} |")
| Year | Count |
|------|-------|
| 2011 | 63 |
| 2012 | 27 |
| 2013 | 19 |
| 2014 | 9 |
| 2015 | 3 |
| 2016 | 3 |
| 2017 | 6 |
| 2018 | 12 |
| 2019 | 2 |
| 2020 | 5 |
| 2021 | 4 |
| 2023 | 2 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment