def setGoogleValue(self, id, google_value, links=''): sql = 'update GoogleResult_mark set google = %s, url = %s where id = %s limit 1' if links is None: linkstr = '' else: linkstr = '\n'.join(links) try: conn = DB.pool().getConnection() cursor = conn.cursor() cursor.execute(sql, (google_value, linkstr, id,)) except Exception, e: ExceptionHelper.print_exec(e)
def popTitlesFromDB(self): sql = 'select id,titleA,titleB from GoogleResult_mark where google is null and updatetime is null order by id limit 1' try: conn = DB.pool().getConnection() cursor = conn.cursor() cursor.execute(sql) data = cursor.fetchall() if(data and len(data) == 1): (id, title1, title2) = data[0] updateSQL = 'update GoogleResult_mark set updatetime = CURRENT_TIMESTAMP where id = %s' cursor.execute(updateSQL, (id,)) return id, title1, title2 except Exception, e: ExceptionHelper.print_exec(e)
def run(self): while True: reset_sql = "update GoogleResult_mark set updatetime = null where google is null and CURRENT_TIMESTAMP - updatetime > 300 limit 20" DB.shortcuts().execute(reset_sql) print "-- interval reset timestamp --" time.sleep(60)
def setGoogleValue(self, id, google_value, links=''): sql = 'update GoogleResult_mark set google = %s, url = %s where id = %s limit 1' if links is None: linkstr = '' else: linkstr = '\n'.join(links) try: conn = DB.pool().getConnection() cursor = conn.cursor() cursor.execute(sql, (google_value, linkstr, id,)) except Exception, e: ExceptionHelper.print_exec(e) finally: cursor.close() conn.close() print '[UPDATE]id:%s, Value:%s' % (id, google_value) if __name__ == '__main__': # pool = DB.initpool("localhost", "arnet_local", "root", "root") DB.initpool("10.1.1.209", "arnet_int2", "root", "root") # GoogleResultDBUpdater().popTitlesFromDB() # GoogleResultUpdateThread().run() GoogleResultDBUpdater().update() # ResetTimestampThread().run()