Source

dataliberation / issues / tigris / pull_issues.py

Full commit

import os
import sys
import urllib

def getIssue(fid):
    query = urllib.urlencode({'id':fid})
    urllib.urlretrieve("http://scons.tigris.org/issues/xml.cgi?%s" % query, "%d.xml" % fid)

def main():
    max = 0
    cur = 0
    if len(sys.argv) > 1:
        sl = sys.argv[1].split('-')
        if len(sl) > 1:
            cur = int(sl[0])-1
            max = int(sl[1])
        else:
            max = int(sys.argv[1])
            
    while 1:
        if max > 0:
            if cur == max:
                break
        cur += 1
        print "%d" % cur
        getIssue(cur)
        # Check for contents
        f = open('%d.xml' % cur)
        content = f.read()
        f.close()
        if content.find('issue status_code="404" status_message="NotFound"') >= 0:
            # Delete the last file
            os.remove('%d.xml' % cur)
            break

if __name__ == "__main__":
    main()