Skip to content

Instantly share code, notes, and snippets.

@joelthelion
Last active September 21, 2017 13:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelthelion/0a5e60a907fdbdabe3a133f0e04b6dff to your computer and use it in GitHub Desktop.
Save joelthelion/0a5e60a907fdbdabe3a133f0e04b6dff to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
from itertools import islice
import re
import requests
from bs4 import BeautifulSoup
if __name__ == '__main__':
stat_soup = BeautifulSoup(requests.get("https://stats.lineageos.org/").content, "lxml")
code_soup = BeautifulSoup(requests.get("https://wiki.lineageos.org/devices/").content, "lxml")
names = {}
for table in code_soup.find_all("table", class_="device"):
for row in table.find_all("tr"):
try:
item = row.td.a
common_name = item.text.strip()
code = item["href"].split("/")[-1]
names[code] = common_name
except AttributeError as e:
pass
for row in stat_soup.find(id="top-devices").find_all(class_="leaderboard-row"):
model = row.span.a.text
popularity = int(row.find_all("span",recursive=False)[1].text)
if popularity < 50: break
name = names.get(model, "UNKNOWN")
print(f"{name:50} : {popularity} ({model})")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment