def updatePinsetInformation(): #Get existing information: am = AsteriskMySQLManager() am.connect('nextor_tarificador'); sql = "SELECT * from tarifica_pinset" am.cursor.execute(sql) existing_pinsets = am.cursor.fetchall() #Get current providers on asterisk's db todays_pinsets = am.getPinsetInformation() print todays_pinsets new_pinsets = [] for today_u in todays_pinsets: existing = False for ex_u in existing_pinsets: if today_u == ex_u['pinset_number']: existing = True if not existing: #Didn't exist before, so we create one: new_pinset = ( today_u, ) new_pinsets.append(new_pinset) print "New pinset", today_u, "found." #Now, we update all previously existing pinsets and save the new ones am.connect('nextor_tarificador'); sql = "INSERT INTO tarifica_pinset \ (pinset_number) VALUES(%s)" totalRowsSaved = am.cursor.executemany(sql, new_pinsets) am.db.commit() print "----------------------------------------" print totalRowsSaved, "new pinsets saved."
def updatePinsetInformation(): #Get existing information: am = AsteriskMySQLManager() am.connect('nextor_tarificador') sql = "SELECT * from tarifica_pinset" am.cursor.execute(sql) existing_pinsets = am.cursor.fetchall() #Get current providers on asterisk's db todays_pinsets = am.getPinsetInformation() print todays_pinsets new_pinsets = [] for today_u in todays_pinsets: existing = False for ex_u in existing_pinsets: if today_u == ex_u['pinset_number']: existing = True if not existing: #Didn't exist before, so we create one: new_pinset = (today_u, ) new_pinsets.append(new_pinset) print "New pinset", today_u, "found." #Now, we update all previously existing pinsets and save the new ones am.connect('nextor_tarificador') sql = "INSERT INTO tarifica_pinset \ (pinset_number) VALUES(%s)" totalRowsSaved = am.cursor.executemany(sql, new_pinsets) am.db.commit() print "----------------------------------------" print totalRowsSaved, "new pinsets saved."