3 # 2014 by Jan "Someone" Vales <someone@somenet.org>
14 print "submitting flag: "+flag
17 # RETURN (success?, srvresponse)
25 print "*** sleeping "+str(sleeptime)+" sec..."
27 dbconn = psycopg2.connect("host=127.0.0.1 dbname=postgres user=postgres password=dba")
29 cur.execute("CREATE TABLE IF NOT EXISTS flags ("
30 "fid serial NOT NULL PRIMARY KEY,"
31 "flag character varying(32) NOT NULL UNIQUE,"
32 "service character varying(32),"
33 "received timestamp without time zone NOT NULL DEFAULT date_trunc('second', NOW()),"
34 "submitted timestamp without time zone,"
35 "status integer NOT NULL DEFAULT 0,"
36 "srvresponse character varying(128)"
40 print "Connected to DB + table created"
44 print "*** sleeping another "+str(sleeptime)+" sec..."
47 cur = dbconn.cursor(cursor_factory=psycopg2.extras.DictCursor)
48 cur.execute("SELECT * from flags where status = 0")
49 print "Fetched " + str(cur.rowcount) + " rows"
50 # rows = cur.fetchall()
51 for row in cur.fetchall():
52 (success, resp) = submit(row['flag'])
54 cur.execute("UPDATE flags SET submitted = date_trunc('second', NOW()), "
55 "status = %s, srvresponse = %s WHERE fid = %s",
56 (success, resp, row['fid']))
58 except psycopg2.DatabaseError as e:
63 except psycopg2.DatabaseError as e:
68 except psycopg2.DatabaseError as e:
72 except psycopg2.DatabaseError as e:
75 print "should never be reached"
77 if __name__ == "__main__":
78 def signal_handler(signal, frame):
79 print 'SIG received. exitting!'
81 signal.signal(signal.SIGINT, signal_handler)