Skip to content

Instantly share code, notes, and snippets.

@joaquinabian
Created February 15, 2011 16:39
Show Gist options
  • Select an option

  • Save joaquinabian/827777 to your computer and use it in GitHub Desktop.

Select an option

Save joaquinabian/827777 to your computer and use it in GitHub Desktop.
Quick and dirty snippet for checking new releases in Gohlke repository
#Check http://www.lfd.uci.edu/~gohlke/pythonlibs/ for new releases
#works for Python 3.2
from urllib import request
from html.parser import HTMLParser
import re
import datetime
from collections import defaultdict
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
class MyParser(HTMLParser):
def __init__(self, checkversion):
HTMLParser.__init__(self)
self.hitpy = None
self.pack = None
self.checkversion = checkversion
self.col = defaultdict(list)
def handle_starttag(self, tag, attrs):
if tag == 'a':
for a, b in attrs:
if a == 'id':
self.pack = b
self.hitpy = False
def handle_data(self, data):
"handle all text not in html tags"
if self.checkversion in data:
self.hitpy = True
if self.hitpy:
hitdate = re.search('\[(\D\D\D \d\d), 2011\]', data)
if hitdate:
self.hitpy = False
self.col[self.pack].append(hitdate.group(1))
def output(self, n):
"printa los cambios de menos de n dias"
today = datetime.date.today()
today = today.toordinal()
for key, dates in self.col.items():
dates = set(dates)
for date in dates:
(month, day) = date.split()
num_month = months.index(month) + 1
time_published = datetime.date(2011, num_month, int(day))
time_published = time_published.toordinal()
if (today - time_published) < n:
txt = '%-10s %s' %(key, date)
print(txt)
if __name__ == "__main__":
url = "http://www.lfd.uci.edu/~gohlke/pythonlibs/"
checkversion = 'Python 3.2'
days_old = 7
with request.urlopen(url) as sock:
html = sock.read()
htmldec = html.decode('utf8')
myparser = MyParser(checkversion)
myparser.feed(htmldec)
myparser.output(days_old)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment