Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.