minor update

This commit is contained in:
Miroslav Stampar 2011-01-15 13:43:08 +00:00
parent 5bdb50c224
commit 44504746cf

View File

@ -52,12 +52,12 @@ def main():
i = int(config.get('options', 'index')) i = int(config.get('options', 'index'))
try: try:
file = open(TABLES_FILE, 'r') f = open(TABLES_FILE, 'r')
for line in file.xreadlines(): for line in f.xreadlines():
if len(line) > 0 and ',' in line: if len(line) > 0 and ',' in line:
temp = line.split(',') temp = line.split(',')
tables[temp[0]] = int(temp[1]) tables[temp[0]] = int(temp[1])
file.close() f.close()
except: except:
pass pass
@ -66,7 +66,7 @@ def main():
files, oldFiles = None, None files, oldFiles = None, None
try: try:
while True: while True:
quit = False abort = False
oldFiles = files oldFiles = files
files = [] files = []
@ -76,7 +76,7 @@ def main():
for match in refiles.finditer(page): for match in refiles.finditer(page):
files.append(urllib.unquote(match.group(1))) files.append(urllib.unquote(match.group(1)))
if len(files) >= 10: break if len(files) >= 10: break
quit = (files == oldFiles) abort = (files == oldFiles)
except KeyboardInterrupt: except KeyboardInterrupt:
raise raise
@ -84,17 +84,17 @@ def main():
except Exception, msg: except Exception, msg:
print msg print msg
if quit: if abort:
break break
sys.stdout.write("\n---------------\n") sys.stdout.write("\n---------------\n")
sys.stdout.write("Result page #%d\n" % (i+1)) sys.stdout.write("Result page #%d\n" % (i+1))
sys.stdout.write("---------------\n") sys.stdout.write("---------------\n")
for file in files: for sqlfile in files:
print file print sqlfile
try: try:
req = urllib2.Request(file) req = urllib2.Request(sqlfile)
response = urllib2.urlopen(req) response = urllib2.urlopen(req)
if response.headers.has_key('Content-Length'): if response.headers.has_key('Content-Length'):
@ -133,19 +133,19 @@ def main():
pass pass
finally: finally:
file = open(TABLES_FILE, 'w+') f = open(TABLES_FILE, 'w+')
tables = sorted(tables.items(), key=itemgetter(1), reverse=True) tables = sorted(tables.items(), key=itemgetter(1), reverse=True)
for table, count in tables: for table, count in tables:
file.write("%s,%d\n" % (table, count)) f.write("%s,%d\n" % (table, count))
file.close() f.close()
config.set('options', 'index', str(i+1)) config.set('options', 'index', str(i+1))
file = open(CONFIG_FILE, 'w+') f = open(CONFIG_FILE, 'w+')
config.write(file) config.write(f)
file.close() f.close()
if __name__ == "__main__": if __name__ == "__main__":
main() main()