From d98cbb821b009e3cae7b3f55cae8e77038105cf0 Mon Sep 17 00:00:00 2001 From: Jan Vales Date: Sat, 12 Nov 2016 18:18:00 +0100 Subject: [PATCH] modified: submitbot_tcp.py --- submitbot_tcp.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/submitbot_tcp.py b/submitbot_tcp.py index 1360557..791f4da 100644 --- a/submitbot_tcp.py +++ b/submitbot_tcp.py @@ -64,39 +64,37 @@ def main(): try: print "*** sleeping "+str(sleeptime)+" sec..." time.sleep(sleeptime) - dbconn = psycopg2.connect("host=127.0.0.1 port=5432 dbname=flagbot user=flagbot password=flagbotpw") + dbconn = psycopg2.connect("host=s.i port=5432 dbname=flagbot user=flagbot password=flagbotpw") print "Connected to DB" cur = None + sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + sock.connect(("flags.ructfe.org", 31337)) + eating = True + fs=sock.makefile() + while eating: + resp = fs.readline()+"" + if resp.startswith('Enter your flags, finished with newline'): + eating = False + while True: try: cur = dbconn.cursor(cursor_factory=psycopg2.extras.DictCursor) - cur.execute("SELECT * from flags where status = 0 or status = 4 limit 2") + cur.execute("SELECT * from flags where status = 0 or status = 4 order by random() limit 1") print "Fetched " + str(cur.rowcount) + " rows" if cur.rowcount == 0: print "*** sleeping another "+str(sleeptime)+" sec..." time.sleep(sleeptime) continue - sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - sock.connect(("flags.ructfe.org", 31337)) - eating = True - fs=sock.makefile() - while eating: - resp = fs.readline()+"" - if resp.startswith('Enter your flags, finished with newline'): - eating = False - for row in cur.fetchall(): + # print "here" + str(row['fid']) if row['flag'] is None or row['flag'].strip() == '': continue (success, resp) = submit(sock,row['flag']) if success != 0: - cur.execute("UPDATE flags SET submitted = date_trunc('second', NOW()), " - "status = %s, srvresponse = %s WHERE fid = %s", + cur.execute("UPDATE flags SET submitted = date_trunc('second', NOW()), status = %s, srvresponse = %s WHERE fid = %s and status = 0 or status = 4", (success, resp, row['fid'])) dbconn.commit() - sock.shutdown(socket.SHUT_WR) - sock.close() except psycopg2.DatabaseError as e: print 'Error %s' % e try: @@ -106,6 +104,8 @@ def main(): print 'Error %s' % e cur = None dbconn.rollback() + sock.shutdown(socket.SHUT_WR) + sock.close() except psycopg2.DatabaseError as e: print 'Error %s' % e -- 2.43.0