Skip to content

Instantly share code, notes, and snippets.

@Demeter
Forked from kachok/listing.py
Created January 10, 2012 08:30
Show Gist options
  • Select an option

  • Save Demeter/1587870 to your computer and use it in GitHub Desktop.

Select an option

Save Demeter/1587870 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Jul 29, 2011.
    34 changes: 34 additions & 0 deletions listing.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    import urllib
    import re

    import time


    data = urllib.urlopen('http://bitly.measuredvoice.com/bitly_archive/?C=M;O=D').read()
    #print data

    #datafiles name pattern - usagov_bitly_data2011-07-29-1311919454
    p = re.compile('usagov_bitly_data\d{4}-\d{2}-\d{2}-\d{10}')
    #print p.findall('<tr><td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td><td><a href="usagov_bitly_data2011-07-29-1311919454">usagov_bitly_data2011-07-29-1311919454</a></td><td align="right">29-Jul-2011 07:04 </td><td')

    m=p.findall(data)

    #print m

    for i in range(len(m)):
    if (i%2==0):
    print m[i]

    #time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.localtime(epoch))

    print len(m)

    for i in range(len(m)):
    if (i%2==0):
    print "downloading ", m[i]
    clicks = urllib.urlopen('http://bitly.measuredvoice.com/bitly_archive/'+m[i]).read()
    file = open(m[i], "w")
    file.write(clicks)
    file.close()
    print "done"