def shortlink_backfill(): cur = Paste._cursor() cur.execute( """ SELECT * from pastes WHERE shortlink is null """ ) pastes = cur.fetchall() for paste in pastes: if paste['unlisted']: url = 'https://paste.buttscicl.es/u/' + paste['hash'] else: url = 'https://paste.buttscicl.es/p/' + str(paste['id']) shortlink = Paste.get_shortlink(url) if shortlink is not None: cur.execute( """ UPDATE pastes SET shortlink = %s WHERE hash = %s """, (shortlink, paste['hash']) ) Paste.conn.commit() print 'Done #' + str(paste['id']) cur.close()
def shortlink_backfill(): cur = Paste._cursor() cur.execute(""" SELECT * from pastes WHERE shortlink is null """) pastes = cur.fetchall() for paste in pastes: if paste['unlisted']: url = 'https://paste.buttscicl.es/u/' + paste['hash'] else: url = 'https://paste.buttscicl.es/p/' + str(paste['id']) shortlink = Paste.get_shortlink(url) if shortlink is not None: cur.execute( """ UPDATE pastes SET shortlink = %s WHERE hash = %s """, (shortlink, paste['hash'])) Paste.conn.commit() print 'Done #' + str(paste['id']) cur.close()
def tearDown(self): # drop the table so we can # recreate it for other tests cur = Paste._cursor() cur.execute('DROP TABLE pastes') cur.execute('DROP TABLE users') cur.connection.commit() cur.close()