| Index: update-client.py |
| =================================================================== |
| --- update-client.py (revision 10) |
| +++ update-client.py (working copy) |
| @@ -7,18 +7,17 @@ |
| hashes = [] |
| count = 0 |
| -def AddHashes(hashes): |
| - body = urllib.urlencode({"data": ",".join(hashes)}) |
| - |
| +def UpdateHashes(hashes): |
| + body = urllib.urlencode({'data': ''.join(hashes)}) |
| headers = { |
| 'Content-Type': 'application/x-www-form-urlencoded', |
| 'Content-Length': len(body), |
| } |
| try: |
| - # conn = httplib.HTTPConnection("localhost:8080") |
| - conn = httplib.HTTPConnection("malfind.appspot.com") |
| - conn.request("POST", "/update", body, headers) |
| + #conn = httplib.HTTPConnection("localhost:8080") |
| + conn = httplib.HTTPConnection('malfind.appspot.com') |
| + conn.request('POST', '/update', body, headers) |
| response = conn.getresponse() |
| conn.close() |
| print response.status, response.reason |
| @@ -29,24 +28,23 @@ |
| return False |
| -def TryAddHashes(hashes): |
| +def TryUpdateHashes(hashes): |
| retries = 0 |
| while retries < 2: |
| - if AddHashes(hashes): |
| + if UpdateHashes(hashes): |
| hashes = [] |
| break |
| - print "Error, Retrying in 60 secs" |
| + print 'Error, Retrying in 60 secs' |
| time.sleep(60) |
| retries += 1 |
| if retries == 2: |
| - print "Too many errors, aborting" |
| + print 'Too many errors, aborting' |
| sys.exit(-1) |
| - |
| for line in open('/tmp/sbcache.txt'): |
| - if not line[0] == '+': |
| + if not line.startswith('+') and not line.startswith('-'): |
| print 'Ignoring ' + line.strip('\n') |
| continue |
| @@ -54,14 +52,13 @@ |
| if count < 19000: |
| continue |
| - hashes.append(line.strip('+').strip('\t\n')) |
| - |
| + hashes.append(line.strip('\t\n')) |
| if count % 50 == 0: |
| print count |
| - TryAddHashes(hashes) |
| + TryUpdateHashes(hashes) |
| hashes = [] |
| time.sleep(0.2) |
| -TryAddHashes(hashes) |
| +TryUpdateHashes(hashes) |
| -print "Success" |
| +print 'Success' |