import datetime import time from MySQLdb.connections import Connection from MySQLdb.cursors import DictCursor def timeUnix(): return int(time.time()) if __name__ == '__main__' : connect = Connection(host='192.168.1.2',user='******',passwd='5OpqU7zv324a7KJxu@4d',db='xiaolajiao',port=3306,charset='utf8') cursor = connect.cursor(cursorclass=DictCursor) cursor.execute(""" select * from shouji_goods WHERE is_promote = 1 AND promote_cycle>0 """) rows = cursor.fetchall() for goods in rows: # print(datetime.datetime.fromtimestamp(goods.get('promote_end_date')).strftime('%Y-%m-%d %H:%M:%S')) if(goods.get('promote_end_date')<=timeUnix()): startDate = goods.get('promote_end_date') endDate = int(goods.get('promote_end_date')) + int(goods.get('promote_cycle'))*24*3600 cursor.execute(""" update shouji_goods SET promote_start_date=%s,promote_end_date=%s WHERE goods_id=%s""" % (startDate,endDate,goods.get('goods_id'))) cursor.close() connect.close()
dbc.execute(queries.ClearAthletesTable) dbc.execute(queries.CLEAR_TRAINERS_TABLE) with open(file, newline='') as f: dbc.executemany( queries.addRecordFromFile, InputDataSet(f).check_rec_format().get_data_per_row()) dbc.execute(queries.FillInAthletesTable) dbc.execute(queries.AddAthleteIdToStatRecord) dbc.execute(queries.FILL_IN_TRAINERS_TABLE) except Connection.Error as e: # print(dbc._last_executed) print("MySQL Error {0}: {1}".format(e.args[0], e.args[1])) else: db.commit() elif o in ("-d", ): q_object = get_duplicate_name() SelectResult(q_object).print_qresult() elif o in ("--by-name"): q_object = get_regdata_by_name(a) result = SelectResult(q_object).print_qresult().report_tofile( "duplicates.csv") elif o in ("--schools"): try: dbc.execute(queries.GET_SCHOOLS) SelectResult(dbc).print_qresult() except Connection.Error as e: print("MySQL Error {0}: {1}".format(e.args[0], e.args[1])) else: assert False, "unhandled option" db.close()
def close(self): self.__close_watchers() BaseConnection.close(self)