Skip to content

Instantly share code, notes, and snippets.

@ChristianKniep
Last active August 29, 2015 14:06
Show Gist options
  • Save ChristianKniep/9a1ab41ef8360aa3e586 to your computer and use it in GitHub Desktop.
Save ChristianKniep/9a1ab41ef8360aa3e586 to your computer and use it in GitHub Desktop.
Iterate through image list on registry.hub.docker.io
from bs4 import BeautifulSoup
from graphitesend import graphitesend
import requests
import re
gsend = graphitesend.init(graphite_server='localhost', group='dockerhub', system_name="", prefix="")
req = requests.get("https://registry.hub.docker.com/repos/qnib/")
data = req.text
soup = BeautifulSoup(data)
res = {}
for div in soup.findAll("div", class_="repo-list-item"):
descr = div.findAll("div", class_="repo-list-item-description").pop()
desc_lst = descr.text.encode('utf8').split("\n")
for item in [item.strip() for item in desc_lst if item.strip() != '']:
if re.match("\w+/\w+", item):
name = item
res[name]={}
break
descr = div.findAll("div", class_="repo-list-item-stats-left").pop()
desc_lst = descr.text.encode('utf8').split("\n")
for item in [item.strip() for item in desc_lst if item.strip() != '']:
res[name]['stars'] = item
descr = div.findAll("div", class_="repo-list-item-stats-right").pop()
desc_lst = descr.text.encode('utf8').split("\n")
for item in [item.strip() for item in desc_lst if item.strip() != '']:
res[name]['downloads'] = item
for name, dic in res.items():
dic['name'] = name
print "%(name)-30s %(stars)-5s %(downloads)s" % dic
gsend.send("%(name)s.stars" % dic, dic['stars'])
gsend.send("%(name)s.doenloads" % dic, dic['downloads'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment