def obtenerChat(chatId): conn = database.conect() cur = database.statement( conn, "SELECT * from chats where chatId='" + str(chatId) + "';") rows = cur.fetchall() database.close(conn) return rows
def main(): layout_main = [[sg.Text('What do you want to do?')], [ sg.Button('Login to System'), sg.Button('Create Account'), sg.Button('Exit') ]] window_main = sg.Window('Login Hash', layout_main) while True: event, values = window_main.read() if event in (None, 'Exit'): break elif event in ('Login to System'): window_main.close() login() break elif event in ('Create Account'): window_main.close() create_account() break db.close() window_main.close()
def route_do_edit(): title = form('title') id = int(form('id')) content = form('content') hpot = form('email') if title is None or id is None or content is None or hpot is not "": return 'Error' if app.config['locked']: if form('pass') != app.config['pass']: return redirect('/') if not database.init(): return error(app.config['db_err_title'], app.config['db_err_msg']), 503 if id == 0: database.query('INSERT INTO articles VALUES(NULL, ?, ?, 0)', [escape(title), escape(content)]) else: database.query("UPDATE articles SET revision = 1 WHERE title=?", [title]) database.query("INSERT INTO articles VALUES(NULL, ?, ?, 0)", [escape(title), escape(content)]) database.close() return redirect(url_for('route_article', title=title))
def run(self): print("Starting " + self.name) # Imports import notification from concurrent.futures import thread # Make global variables available in local context global running, pref # Initialize everything database.init(pref.get_preference("database")) # A refill every 24 hours refill = 24 * 60 * 60 sleepy_time = 5 cur_time = int(calendar.timegm(time.gmtime())) last_time = cur_time - (cur_time % refill) # Run the code while running: # Calculate next refill cur_time = int(calendar.timegm(time.gmtime())) new = last_time + refill # Refill? if cur_time > new: notification.send_refill() control.inventory_refill() last_time = new else: # Wait till refill time.sleep(sleepy_time) database.close()
def guardarChat(chatId): conn = database.conect() database.statement(conn, "create table if not exists chats(chatId varchar);") database.statement( conn, "insert into chats (chatId) values('" + str(chatId) + "');") database.close(conn)
def obtenerLastImg(): conn = database.conect() cur = database.statement( conn, "SELECT * from parametros where param='lastImg';") rows = cur.fetchall() database.close(conn) return rows
def createTable(mode = 0, connection = None, database_spec = None, drop_tables = None): if mode == 1: menu.clearScreen() print("\nAirline Booking Setup") # connect to database curs = database.cursor(connection) try: # drop pre-existing tables checkTable(drop_tables, curs) # create tables execSQL(database_spec, curs) connection.commit() database.close(None,curs) print("Setup Complete\n") except cx_Oracle.DatabaseError as exc: error, = exc.args print(sys.stderr, "Oracle code:", error.code) print(sys.stderr, "Oracle message:", error.message)
def insertIntoDatabase(expId, malBehaviorNumber, length, resultingData): connection = db.connect() # exclude the header and only insert the pure data in the database resultingData = resultingData[1:] db.insertLocalizationBrute(connection, expId, length, malBehaviorNumber, resultingData) db.close(connection)
def imageCreate(): """Create an initial image.""" if not checkReady(): return fail('The API is still booting up... Please wait.') log('Creating the first image...') if not checkAccessToken(): sublog('No access token.') return fail('Invalid access token.') if not 'editTime' in request.json.keys(): sublog('No editTime specified.') return fail('No editTime specified.') if not 'hopsLeft' in request.json.keys(): sublog('No hopsLeft specified.') return fail('No hopsLeft specified.') if not 'nextUser' in request.json.keys(): sublog('No nextUser specified.') return fail('No nextUser specified.') if not 'image' in request.json.keys(): sublog('No image specified.') return fail('No image specified.') sublog('Edit time: ' + str(request.json['editTime']) + '\n\tHops: ' + str( request.json['hopsLeft']) + '\n\tNext user: '******'nextUser'] + '\n\tImage: (yes)') # Make sure the next user is valid... con = database.connect() c = con.cursor() c.execute("SELECT COUNT(*) FROM users WHERE username=:nextUser", {'nextUser': request.json['nextUser']}) r = c.fetchone() if r[0] == 0: database.close(con) sublog('Next user was not valid.') return fail('Invalid nextUser.') # Add the image to the pending queue. thisUser = accessTokenToUser(request.json['accessToken']) thisImageUUID = str(uuid.uuid1()) sublog('Name: ' + thisUser) c.execute( "INSERT INTO images (imageUUID, originalOwner, hopsLeft, editTime, image, nextUser, previousUser) VALUES (:imageUUID, :originalOwner, :hopsLeft, :editTime, :image, :nextUser, :previousUser)", {'imageUUID': thisImageUUID, 'originalOwner': thisUser, 'hopsLeft': request.json['hopsLeft'], 'editTime': request.json['editTime'], 'image': request.json['image'], 'nextUser': request.json['nextUser'], 'previousUser': thisUser}) # Add the initial creator into the log of people who should be notified when this image is done. c.execute("INSERT INTO imageHistory (imageUUID, username) VALUES (:imageUUID, :username)", {'imageUUID': thisImageUUID, 'username': thisUser}) # TODO: Send push notification to the next user. database.close(con) sublog('Image created.') return success('Image created and next user will be alerted.')
def deleteFriend(): if not checkReady(): return fail('The API is still booting up... Please wait.') log('Removing friend...') if not checkAccessToken(): sublog('Bad access token.') return fail('Invalid access token.') if not 'friend' in request.json.keys(): sublog('No friend specified.') return fail('No friend specified.') thisUser = accessTokenToUser(request.json['accessToken']) sublog('Name: ' + thisUser + '\n\tFriend: ' + request.json['friend']) con = database.connect() c = con.cursor() c.execute("DELETE FROM friends WHERE username=:username and friend=:friend", {'username': thisUser, 'friend': request.json['friend']}) database.close(con) sublog('Friend removed.') return success('Friend removed!')
def run(self): # Create the DB connection conn = db.connection() cur = conn.cursor() # Create the run information cur.execute('call amazon_review.proc_create_rundata(%s)', ('ExtractProduct', )) conn.commit() # get the run id generated for the job cur.execute('SELECT * FROM amazon_review.func_return_runid(%s)', ('ExtractProduct', )) run_id = cur.fetchone() prod.extract_product() with self.output().open('w') as outfile: outfile.write('Product extraction task ExtractProduct is done!\n') # Update the run status cur.execute('call amazon_review.proc_update_rundata(%s)', (run_id, )) conn.commit() # closing db connection db.close(conn, cur)
def run(self): # Create the DB connection conn = db.connection() cur = conn.cursor() # Create the run information cur.execute('call amazon_review.proc_create_rundata(%s)', ('LoadProdBuyAfterViewingDimension', )) conn.commit() # get the run id generated for the job cur.execute('SELECT * FROM amazon_review.func_return_runid(%s)', ('LoadProdBuyAfterViewingDimension', )) run_id = cur.fetchone() p_buy_after_view_dim.load_product_buy_after_viewing(run_id) with self.output().open('w') as outfile: outfile.write('The task LoadProdBuyAfterViewingDimension is done') # Update the run status cur.execute('call amazon_review.proc_update_rundata(%s)', (run_id, )) conn.commit() # closing db connection db.close(conn, cur)
def run(self): # Create the DB connection conn = db.connection() cur = conn.cursor() # Create the run information cur.execute('call amazon_review.proc_create_rundata(%s)', ('LoadProductReviewFact', )) conn.commit() # get the run id generated for the job cur.execute('SELECT * FROM amazon_review.func_return_runid(%s)', ('LoadProductReviewFact', )) run_id = cur.fetchone()[0] print(run_id) # Call the program for data loading into DWH p_review_fact.load_product_review_fact(run_id) with self.output().open('w') as outfile: outfile.write('The task LoadProductReviewFact is done') # Update the run status cur.execute('call amazon_review.proc_update_rundata(%s)', (run_id, )) conn.commit() # closing db connection db.close(conn, cur)
def imageSeen(): """Set an image's hop count to -1 so it won't appear in the list of images the client gets when they query.""" if not checkReady(): return fail('The API is still booting up... Please wait.') log('Marking image as seen...') if not checkAccessToken(): sublog('Bad access token.') return fail('Invalid access token.') if not 'uuid' in request.json.keys(): sublog('No UUID specified.') return fail('No UUID specified.') # Make sure a client can only mark their own images as seen, and only images that have a hopCount of 0. thisUser = accessTokenToUser(request.json['accessToken']) sublog('Name: ' + thisUser) con = database.connect() c = con.cursor() c.execute("UPDATE imageHistory SET viewed=1 WHERE imageUUID=:imageUUID AND username=:username", {'imageUUID': request.json['uuid'], 'username': thisUser}) database.close(con) sublog('Acknowledgement complete.') return success('Successfully acknowledged image.')
def getFriends(): """Get the friends list of a client.""" if not checkReady(): return fail('The API is still booting up... Please wait.') log('Checking friends list...') if not checkAccessToken(): sublog('Bad access token.') return fail('Invalid access token.') thisUser = accessTokenToUser(request.json['accessToken']) sublog('Name: ' + thisUser) con = database.connect() c = con.cursor() c.execute("SELECT friend FROM friends WHERE username=:username", {'username': thisUser}) res = jsonRows(c) database.close(con) sublog('Ok.') return res
def addFriend(): """Adds a friend to someone's friend list.""" if not checkReady(): return fail('The API is still booting up... Please wait.') log('Adding friend...') if not checkAccessToken(): sublog('Bad access token.') return fail('Invalid access token.') if not 'friend' in request.json.keys(): sublog('No friend specified.') return fail('No friend specified.') thisUser = accessTokenToUser(request.json['accessToken']) sublog('Name: ' + thisUser + '\n\tFriend: ' + request.json['friend']) if request.json['friend'] == thisUser: sublog('User tried to add themself as friend...') return fail('You can\'t add yourself as a friend...') con = database.connect() c = con.cursor() c.execute("INSERT OR IGNORE INTO friends (username, friend) VALUES (:username, :friend)", {'username': thisUser, 'friend': request.json['friend']}) database.close(con) sublog('Friend added.') return success('Friend added!')
def load_product_also_bought_dimension(run_id): # Creating the spark session spark = SparkSession \ .builder \ .appName("Loading product also bought dimension") \ .config("spark.driver.extraClassPath",spark_driver_extraClassPath) \ .config("spark.executor.extraClassPath",spark_executor_extraClassPath) \ .getOrCreate() # Source data file path path = input_file # Read product also bought parquet files productAlsoBoughtDF = spark.read.parquet(path) # Loading data into temp table in DWH for further processing productAlsoBoughtDF.select('asin','also_bought').write \ .format(conn_format) \ .option("url", url) \ .option("dbtable", "amazon_review.temp_product_also_bought") \ .option("user", user) \ .option("password", password) \ .option("driver", driver) \ .mode("overwrite")\ .save() # Calling the stored proc to load d_product_also_bought conn = db.connection() cur = conn.cursor() cur.execute('call amazon_review.proc_load_product_also_bought(%s)', (run_id, )) conn.commit() db.close(conn, cur)
def cleanOldUsers(): dt = datetime.date.today().toordinal() - objects.DAYS_KEEP_OLD_USERS old = database.select('persons', where= [('start_date', '<', dt), 'and', ('end_date', '<', dt)]) for pid in [tp['pid'] for tp in old]: log(2, 'Removing user %d from database' % (pid,)) database.delete('persons', { 'pid': pid }) database.close()
def DBChoices(self, attr): import database as DB DB.initialize() DB.connect() try: return [(x.path, os.path.basename(x.path)) for x in DB.VideoBumpers.select().where(DB.VideoBumpers.type == self.vtype)] finally: DB.close()
def backupDatabase(): database.close() if not os.path.exists(globals.BACKUPFOLDER_NAME): os.makedirs(globals.BACKUPFOLDER_NAME) copyfile(globals.DATABASE_NAME, globals.BACKUPFOLDER_NAME + "/" + datetime.utcnow().strftime("%Y-%m-%d_%H-%M") + ".db") database.init()
def route_random(): database.init() row = database.fetch("SELECT title FROM articles WHERE title!='Main Page' ORDER BY RANDOM() LIMIT 1") database.close() if row != None: title = row['title'].replace(' ', '_') return redirect('/' + title) else: return redirect('/')
def logout(connection, user): cursor = database.cursor(connection) update = "Update users set last_login = sysdate where email = :user_email" update = update.replace(":user_email", "'"+user+"'") cursor.execute(update) connection.commit() database.close(cursor)
def saveUserAvatar(user_id, filename): db = connection() csr = db.cursor() query = "UPDATE users SET avatar='" + filename + "' where id='" + str( user_id) + "';" csr.execute(query) db.commit() csr.close() db.close()
def route_article(title): title = title.replace('_', ' ') if not database.init(): return error(app.config['db_err_title'], app.config['db_err_msg']), 503 article = database.fetch('SELECT * FROM articles WHERE title = ? AND revision = 0', [title]) database.close() if article != None: return render_template('article.html', title=title, content=article['content']) else: return render_template('article.html', title=title, content='There is currently no text on this page')
def guardarLastImg(img): conn = database.conect() database.statement( conn, "create table if not exists parametros(param varchar, value varchar);") database.statement( conn, "CREATE unique INDEX if not exists param ON parametros(param);") database.statement( conn, "insert into parametros (param,value) values('lastImg','') on conflict (param) do update set value='" + str(img) + "';") database.close(conn)
def route_edit(title): title = title.replace('_', ' ') if not database.init(): return error(app.config['s_db_title'], app.config['s_db_msg']), 503 article = database.fetch('SELECT * FROM articles WHERE title = ?', [escape(title)]) database.close() if article != None: return render_template('edit.html', title=article['title'], id=article['id'], content=article['content']) else: return render_template('edit.html', title=title, id=0, content='')
def DBChoices(attr): import database as DB DB.initialize() ratingSystem = util.getSettingDefault('rating.system.default') DB.connect() try: return [(x.style, x.style) for x in DB.RatingsBumpers.select( DB.fn.Distinct(DB.RatingsBumpers.style)).where( DB.RatingsBumpers.system == ratingSystem)] finally: DB.close()
def DBChoices(attr): import database as DB DB.initialize() ratingSystem = util.getSettingDefault('rating.system.default') DB.connect() try: return [ (x.style, x.style) for x in DB.RatingsBumpers.select(DB.fn.Distinct(DB.RatingsBumpers.style)).where(DB.RatingsBumpers.system == ratingSystem) ] finally: DB.close()
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: print('action called') cursor = database.find_project() results = [doc for doc in cursor] message = '' for result in results: message += result['name'] + ', ' dispatcher.utter_message(text=message) database.close() return []
def getUserID(user): db = connection() csr = db.cursor() query = "select id from users where email='" + str(user) + "';" csr.execute(query) profile_data = csr.fetchall()[0] user_id = profile_data[0] csr.close() db.close() return user_id
def accessTokenToUser(token): """Look up an access token and find out who the user is.""" print("\tLooking up user: "******"... "), con = database.connect() c = con.cursor() c.execute("SELECT username FROM activeAccessTokens WHERE accessToken=:accessToken", {'accessToken': token}) r = c.fetchone() v = r[0] print('It\'s ' + v) database.close(con) return v
def imageQuery(): """Returns a list of images that a user should see. Some might be incomplete, needing additions, and others might be finished images.""" if not checkReady(): return fail('The API is still booting up... Please wait.') log('Querying for list of actionable images...') if not checkAccessToken(): sublog('Bad access token.') return fail('Invalid access token.') thisUser = accessTokenToUser(request.json['accessToken']) sublog('Name: ' + thisUser) # Basically, look at the images table and see if any have nextUser set to us. This will be the first set of results. # Also look for images in the images table whose hopCount is 0 and with us in the history table linking us to this image. con = database.connect() c = con.cursor() # We need the rows from this and also anything that this username has in the image history which hasn't 0 hopCount. c.execute( "SELECT imageUUID, previousUser, editTime, hopsLeft FROM images WHERE nextUser=:thisUser AND hopsLeft<>0", {'thisUser': thisUser}) firstSet = jsonRows(c)['items'] # Now, we also need any image whose UUID is mentioned with this username in the imageHistory, and whose hopCount is 0 c.execute( "SELECT imageUUID, previousUser, editTime, hopsLeft FROM images AS III WHERE III.imageUUID IN (SELECT imageUUID FROM imageHistory WHERE username=:username AND viewed=0) AND hopsLeft=0", {'username': thisUser}) secondSet = jsonRows(c)['items'] database.close(con) sublog("Unfinished images: " + str(len(firstSet))) sublog("Finished images: " + str(len(secondSet))) finalSet = [] for thing in firstSet: finalSet.append(thing) for thing in secondSet: finalSet.append(thing) return {'success': True, 'items': finalSet}
def run(self): global running, pref print("Starting " + self.name) database.init(pref.get_preference("database")) # Communication loop ard = arduino.Interface(b'ZxPEh7ezUDq54pRv', pref.get_preference("arduino_port")) while running: if self._scanned_card(ard.read_rfid()): ard.send_accept() else: ard.send_reject() # threads.remove(self) print("Exiting " + self.name) database.close()
def userRegister(): """Register a user.""" if not checkReady(): return fail('The API is still booting up... Please wait.') log('Attempting to register...') if not 'username' in request.json.keys(): sublog('Registration attempt but no username provided in request.') return fail('Username not provided in registration.') if not 'passwordHash' in request.json.keys(): sublog('Registration attempt but no password hash provided in request.') return fail('Password hash not provided in registration.') if not 'phoneNumber' in request.json.keys(): sublog('Registration attempt but no phone number provided in request.') return fail('Phone number not provided in registration.') if len(request.json['username']) == 0 or len(request.json['passwordHash']) == 0 or len( request.json['phoneNumber']) == 0: sublog('Attempted to register with a 0-length field.') return fail('Come on now, no 0-length fields.') sublog("Name: " + request.json['username'] + "\n\tPhone: (" + request.json['phoneNumber'] + ")\n\tHash: " + request.json['passwordHash']) # Check that this user doesn't already exist. con = database.connect() c = con.cursor() c.execute("SELECT COUNT(*) FROM users WHERE username=:username OR phoneNumber=:phoneNumber", {'username': request.json['username'], 'phoneNumber': request.json['phoneNumber']}) r = c.fetchone() if r[0] != 0: sublog("That username or phone number already exists.") return fail('Username or phone number already exists.') # Ok. Insert them into the database. c.execute("INSERT INTO users (username, passwordHash, phoneNumber) VALUES (:username, :passwordHash, :phoneNumber)", {'username': request.json['username'], 'passwordHash': request.json['passwordHash'], 'phoneNumber': request.json['phoneNumber']}) database.close(con) sublog("User registered.") return success('User registered.')
def authenticate(username, password): # Make sure at least something was entered since username/password can't be empty if username == "" or password == "": return "False" database.init("../data/database.db") print(username + "," + password) # Get a user object belonging to the entered credentials user = database.get_user_by_login(username, password) # If the user object is not null, the credentials are valid if not user: return "False" else: return "True" database.close()
def createTable(mode = 0, connection = None, database_spec = None, drop_tables = None): if mode == 1: menu.clearScreen() print("\nAirline Booking Setup") # connect to database curs = database.cursor(connection) try: # drop pre-existing tables checkTable(drop_tables, curs) # create tables execSQL(database_spec, curs) connection.commit() # insert single queries # data = [('Quadbury', 101, 7.99, 0, 0)] # cursInsert = connection.cursor() # cursInsert.bindarraysize = 1 # cursInsert.setinputsizes(32, int, float, int, int) # cursInsert.executemany("INSERT INTO TOFFEES(T_NAME, SUP_ID, PRICE, SALES, TOTAL) " # "VALUES (:1, :2, :3, :4, :5)", data); # cursInsert.close() # read from a table # # executing a query # curs.execute("SELECT * from TOFFEES") # # get all data and print it # rows = curs.fetchall() # for row in rows: # print(row) database.close(None,curs) print("Setup Complete\n") except cx_Oracle.DatabaseError as exc: error, = exc.args print(sys.stderr, "Oracle code:", error.code) print(sys.stderr, "Oracle message:", error.message)
def login_user(): """ Logins the user in by taking their credentials and validating them against the database. Returns the username to be used for all further operations. """ validated = False while not validated: try: print("\n\t\tLOGIN") username = input("Enter username: "******"Enter password: "******"\n\nExit.") database.close() exit()
def scrape(pairs): conn, c = db.init('tradingPairs.db') for pair in pairs: print('Scrape: Updating ' + pair + '...') fromDate = '' last = db.getLastDate(c, pair) if last: fromDate = last[0][0] else: fromDate = earliest candles = client.get_historical_klines(pair, Client.KLINE_INTERVAL_1MINUTE, fromDate) cleanCandles(candles) for candle in candles: db.dataEntry(c, conn, pair, candle) db.close(c, conn)
def load_product_category(run_id): spark = SparkSession \ .builder \ .appName("Loading Product Category Dimension") \ .config("spark.driver.extraClassPath",spark_driver_extraClassPath) \ .config("spark.executor.extraClassPath",spark_executor_extraClassPath) \ .getOrCreate() # sc = spark.sparkContext # Source data file path path = input_file # Read product category parquet files for product information productCatDF = spark.read.parquet(path) # Creating temp views on source DataFrame productCatDF.createOrReplaceTempView("productCatDF") finalproductCatDF = spark.sql("SELECT category as category_name\ FROM productCatDF") finalproductCatDF.select('category_name').write \ .format(conn_format) \ .option("url", url) \ .option("dbtable", "amazon_review.temp_product_category") \ .option("user", user) \ .option("password", password) \ .option("driver", driver) \ .mode("overwrite")\ .save() print('runid ->', run_id) # Calling the stored proc to load d_product_dimension conn = db.connection() cur = conn.cursor() cur.execute('call amazon_review.proc_load_product_category_dimension(%s)', (run_id, )) conn.commit() db.close(conn, cur)
def userListWithoutMe(): """Return a list of users in the database so others can send images to them. Doesn't include yourself. User specify a search string to narrow down potential users and provide auto-complete functionality.""" if not checkReady(): return fail('The API is still booting up... Please wait.') log('Getting user list (exclusive)...') if not 'accessToken' in request.json.keys(): sublog('No access token.') return fail('No access token in request.') thisUser = accessTokenToUser(request.json['accessToken']) sublog('Name: ' + thisUser) con = database.connect() c = con.cursor() if not 'search' in request.json.keys(): sublog('Returning up to 100 non-specific users...') c.execute("SELECT username FROM users WHERE username<>:username LIMIT 100", {'username': thisUser}) else: if len(request.json['search']) < 2: sublog('Search string specified but not long enough.') database.close(con) return fail('Search string not long enough, need at least 2 characters.') sublog('Returning up to 100 users that begin with ' + str(request.json['search'])) c.execute( "SELECT username FROM users WHERE username<>:username AND username LIKE :search ORDER BY length(username) ASC LIMIT 100", {'username': thisUser, 'search': request.json['search'] + '%'}) res = jsonRows(c) database.close(con) sublog('Ok.') return res
def userLogin(): """Log a user in and generate a unique ID for this session.""" if not checkReady(): return fail('The API is still booting up... Please wait.') log('Logging in...') if not 'username' in request.json.keys(): sublog('No username provided in request.') return fail('Username not provided in login.') if not 'passwordHash' in request.json.keys(): sublog('No password hash provided in request.') return fail('Password hash not provided in login.') sublog('Name: ' + request.json['username'] + '\n\tHash: ' + request.json['passwordHash']) # Check if this is the correct password. con = database.connect() c = con.cursor() c.execute("SELECT COUNT(*) FROM users WHERE username=:username AND passwordHash=:passwordHash", {'username': request.json['username'], 'passwordHash': request.json['passwordHash']}) r = c.fetchone() if r[0] == 0: sublog('Login failed.') return fail('Invalid username or password.') # Alright, they've logged in, now generate a random access key and give it to them. # XXX: These probably won't collide. accessToken = str(uuid.uuid1()) c.execute("INSERT INTO activeAccessTokens (accessToken, username) VALUES (:accessToken, :username)", {'accessToken': accessToken, 'username': request.json['username']}) database.close(con) sublog('Login success.') return {'success': True, 'accessToken': accessToken, 'message': 'Logged in.'}
def imageFetch(): """Returns the actual image data based on an imageUUID if the user can see it.""" if not checkReady(): return fail('The API is still booting up... Please wait.') log('Fetching actual image data...') if not checkAccessToken(): sublog('Bad access token.') return fail('Invalid access token.') if not 'uuid' in request.json.keys(): sublog('No image ID specified for fetch.') return fail('No image ID specified for fetch.') thisUser = accessTokenToUser(request.json['accessToken']) sublog('Name: ' + thisUser) # Since presumably if the user has a UUID, it knows the image exists and it must somehow be authorized to see it # (probably), so just give in and return it, unless the hop count is -1. con = database.connect() c = con.cursor() c.execute("SELECT image FROM images WHERE imageUUID=:imageUUID AND hopCount>=0", {'imageUUID': request.json['uuid']}) r = c.fetchone() if len(r) == 0: sublog('No rows...') database.close(con) return fail('No image by that UUID.') arr = {'success': True, 'image': r[0]} database.close(con) return arr
def profileData(user): # get db components db = connection() csr = db.cursor() query = "select users.first_name, users.last_name, users.avatar from users where users.email='" + str( user) + "';" csr.execute(query) profile_data = csr.fetchall()[0] with open("./images/" + profile_data[2], "rb") as avatar_image: avatar = base64.b64encode(avatar_image.read()) profile = { "first_name": profile_data[0], "last_name": profile_data[1], "avatar": avatar } csr.close() db.close() return profile
e4.grid(row=1, column=3 ) list1 = Listbox(window, height = 6 , width = 35) list1.grid(row=2, column=0, rowspan = 6 , columnspan = 2) list1.bind('<<ListboxSelect>>', get_selected_row) p1 = Scrollbar(window) p1.grid(row=2, column=2, rowspan= 6) list1.configure(yscrollcommand = p1.set) p1.configure(command = list1.yview) b1 = Button(window, text="View All" , width=12, command=viewcommand) b1.grid(row=2 , column= 3) b2 = Button(window, text="Search Entries" , width=12, command=searchcommand) b2.grid(row=3 , column= 3) b3 = Button(window, text="Add Entries" , width=12, command=addcommand) b3.grid(row=4 , column= 3) b4 = Button(window, text="Update Selected" , width=12, command=updateselected) b4.grid(row=5 , column= 3) b5 = Button(window, text="Delete Selected" , width=12, command=deleteselected) b5.grid(row=6 , column= 3) database.close() window.mainloop()
c = 0 for c_id, p_id in id_pairs: print c_id, p_id url = problem_detail_url % (c_id, p_id) c += 1 if c % 50 == 0: topcoder.login() try: page = topcoder.get_page(url) except Exception, e: print c_id, p_id, e continue #import pdb #pdb.set_trace() p = compile('<td class="statText">Top Submission</td>[\d\D]*?</tr>') divs = p.findall(page) testcase_crawled = False for div in divs: p = compile('<td class="statText" align="right">[\d\D]*?</td>') tds = p.findall(div) for i in xrange(4): gen_solution(cur, tds[i], i, p_id) if __name__ == '__main__': topcoder = Topcoder() topcoder.login() conn, cur = init() gen_href(cur, topcoder) close(conn)
def teardown_class(cls): database.close() os.unlink(k_database)
import database database.init() database.clearSubscriptions() database.addSubscription('Watchful12', 'TestBotSlave1', 'SubTestBot1') database.addSubscription('Watchful12', 'TestBotSlave2', 'SubTestBot1') database.addSubscription('Watchful12', 'TestBotSlave3', 'SubTestBot1') database.addSubscription('Watchful12', 'TestBotSlave4', 'SubTestBot1') database.addSubscription('Watchful12', 'TestBotSlave1', 'SubTestBot2') database.addSubscription('Watchful12', 'TestBotSlave2', 'SubTestBot2') database.addSubscription('Watchful12', 'TestBotSlave5', 'SubTestBot2') database.resetAllSubscriptionTimes() database.close()
def test_close_an_open_restaurant(self): database.create_menu_table('subway') database.open('subway') self.assertTrue(database.close('subway'))
def tearDown(self): with app.test_request_context(): # Destroys and closes the database db.destroy() db.close()
def teardown(self): database.close() if os.path.exists(k_database): os.unlink(k_database)
else: if doctorData['number'].isdigit() == True : data['curnumber'] = int(doctorData['number']) data['comment'] = '{"over":false}' else: continue data['start'] = int(doctorData['start_time']) data['end'] = int(timeStamp) data['duration'] = data['end'] - data['start'] #DB.insert(data) checkPointCount += 1 if checkPointCount == 100: DB.checkPoint() checkPoint = 0 doctorData['start_time'] = timeStamp doctorData['number'] = curNumber else: doctorData_list[key]={'number':curNumber, 'start_time':timeStamp} startpath = str(input_file) finalpath = save_done_path+'/'+str(input_file).split('/')[-1] os.system('mv '+startpath+' '+finalpath) print('mv '+startpath+' '+finalpath) print "%s is completed!" % (input_file) doctorData_list.clear() input_file_ptr.close() DB.checkPoint() DB.close()
def close(): restaurant = input("Which restaurant you want to close: ") if database.is_there_such_restaurant(restaurant): database.close(restaurant) else: print("There is no such restaurant")
for tr in trs: if tr.find('/stat?c=problem_statement&pm=') == -1: continue p = compile('/stat\?c=problem_statement&pm=[0-9]*&rd=[0-9]*') url = topcoder_site_url + p.findall(tr)[0] p = compile('pm=[0-9]*') p_id = p.findall(url)[0][3:] p = compile('>.*?<') name = p.findall(tr)[2][1:-1] print p_id, url, name page = topcoder.get_page(url) p = compile('<\!-- BEGIN BODY -->[\d\D]*?<\!-- END BODY -->') description = p.findall(page)[0] try: cur.execute(insert_template % (p_id, name, escape_string(description), url)) except IntegrityError: print p_id, 'Duplicate!' print if __name__ == '__main__': topcoder = Topcoder() topcoder.login() conn, cur = init() gen_problem(cur, topcoder) #test("http://community.topcoder.com/stat?c=round_overview&er=5&rd=14734"); close(conn)
def test_close_a_closed_restaurant(self): database.create_menu_table('speedy') self.assertFalse(database.close('speedy'))