def add_youtube_video_to_database(url): yt = YouTube(url) video = (give_random_id(), yt.title, yt.thumbnail_url, video.streams.filter(type='audio').first().url, yt.description) database.add([ video, ])
def write(): try: database.add(request.form['u1'],request.form['u2'],request.form['toSend']+'\n') flash('Sent') return redirect(redirect_url(request)) except KeyError: flash('Please log in') return redirect(redirect_url(request))
def test_add_pizza_price(self): database.create_menu_table('speedy') database.add('speedy', 'pizza', 3.50) database.cursor.execute("SELECT price \ FROM speedy WHERE products = 'pizza'") price = database.cursor.fetchone() self.assertEqual(3.50, price[0])
def add(): restaurant = input("Name of the restaurant: ") if database.is_there_such_restaurant(restaurant): product = input("What do you want to add to the menu: ") price = input("What is the price of this product :") database.add(restaurant, product, price) else: print("There is no such restaurant")
def printBoard(xUuid): order = 0 print("-----------------------------") for x in range(NUM): print(Board[x]) for y in range(NUM): if Board[y][x] == 1: order += 1 add(xUuid, order, 1, x, y)
def register(): if request.method == 'GET': return render_template('Register.html') else: provided_username = request.form['username'] provided_password = request.form['password'] database.add(provided_username, provided_password) return render_template("index.html")
def store(): if validated[0] or (validated[0] is None and verify()): if cache: database.append(transaction_dict, 'transaction', 'cache') else: database.write(transaction_dict, 'transaction', transaction_hash[0]) database.sub('wallet', wallet_in, amount) database.add('wallet', wallet_out, amount) return transaction_dict
def test_db(): try: database.clear() print('Table Cleared') database.add(t1) print(f'{t1} has been added to the UserInfo Table') click_sound.play() except: print('Error Found')
def add(): try: thing = request.args.get("thing") except AttributeError: return "ERROR: That doesn't look right. URL param `thing` can't be empty." if (thing != "") and (thing != None) and (thing != " "): database.add(utils.sanitize(thing)) return "[✓] Thanks for reporting that Jeffrey dropped " + thing else: return "[⚠] ERROR: That doesn't look right. URL param `thing` can't be empty."
def register(): if request.method == 'GET': if session.get('logged_in'): return render_template('Register.html', signout='Signout') else: return render_template('Register.html') else: provided_username = request.form['username'] provided_password = request.form['password'] database.add(provided_username, provided_password) return redirect(url_for('index'))
def post(self): name = self.get_argument('name') surname = self.get_argument('surname') date_of_birth = self.get_argument('date_of_birth') sex = self.get_argument('sex') email = self.get_argument('email') salary = self.get_argument('salary') new_record = [name, surname, date_of_birth, sex, email, salary] # print('new record data', new_record) database.add(new_record) # all_records = database.get_all() # self.redirect('templates/list.html', title='Added new record with name: {}'.format(name)) self.redirect('/staff/list')
def accept(self): if self.nameLE.text() == '': QMessageBox.warning(self, "Błąd", "Nie podałeś nazwy", QMessageBox.Ok) elif self.measure.text() == '': QMessageBox.warning(self, "Błąd", "Nie podałeś jednostki miary", QMessageBox.Ok) else: database.add(str(self.codeLE.text()), self.nameLE.text(), self.measure.text()) QMessageBox.information( self, 'Dodano', 'Dodano produkt: ' + self.nameLE.text() + "\nO kodzie: " + self.codeLE.text() + "\n Jednostka miary: " + self.measure.text(), QMessageBox.Ok) self.close()
def store(): if verify(): database.write(header, 'block', crypto.pickle_hash(header).decode(errors='ignore')) for tx in transactions: transaction(**tx)[2]() block_size = sys.getsizeof(pickle.dumps(header, protocol=4)) old_mean = interface.add_mean_block_size(block_size) reward = config.reward_function(block_index, block_size, old_mean) database.add('wallet', wallet, reward) height = database.read('block_height', 'main') if block_index == height: # < implies insertion | > does not exist database.add('block_height', 'main', 1) return return False
def addreport(): try: data = json.loads(request.data) data = { 'email': decode_jwt(data.get('authtoken'))['email'], 'longitude': float(data.get('longitude')), 'latitude': float(data.get('latitude')), 'image': data.get('image'), 'description': data.get('description'), 'tags': data.get('tags') } if data['longitude'] == None or data['latitude'] == None or data['email'] == None: success = False else: report_id = add(data) userdata = users.find({"phone": {"$exists": True}}) for user in userdata: send(user['phone']) if report_id != None: success = True else: success = False if success == False: return json.dumps({"status": "error"}) else: return json.dumps({"status": "success"}) except: traceback.print_exc() return json.dumps({"status": "error"})
def request_distance(): r = requests.get(robot_url + "/sensor/d", timeout=requests2robot_timeout) if r.status_code == requests.codes.ok: # getting целую часть от расстояния в формате int distance_str_in = r.json()['distance'] point_pos = distance_str_in.find('.') distance_str_out = distance_str_in[:point_pos] distance_int = distance_str_out json_response = jsonify({"distance": distance_int}) # adding record to database db.add(distance_value=distance_int) else: json_response = jsonify({'web_server_response': r.status_code}) return json_response
def addto(self): self.curr = self.combo.currentText() self.meas = database.add(str(self.codeLE.text()), self.curr, self.measure.text()) QMessageBox.information( self, 'Dodano', 'Dodano produkt: ' + self.curr + "\nO kodzie: " + self.codeLE.text() + "\n Jednostka miary: " + self.meas, QMessageBox.Ok) self.close()
def transact(wallet_out, amount): amount = float(amount) * config.UNIT wallet, private_key = keypair() index = database.read('sent', 'transactions') sign, _, store = datatypes.transaction(wallet, wallet_out, amount, index, private_key, cache=True) sign() transaction = store() if transaction is None: print('Insufficient funds.') return database.add('sent', 'transactions', 1) del transaction['data_type'] networking.BASE_NODE.node().send_transaction(**transaction)
def handle_text(message): try: arguments = parsing.find_arguments(message.text, last_is_string=True) cost = parsing.get_cost(arguments[0]) date = parsing.get_date(arguments[1]) description = parsing.get_description(arguments[2]) database.add(message.chat.id, cost, date, description) bot.send_message(message.chat.id, quotes.ADD_OK) except exceptions.WrongNumberOfArgumentsException as exception: bot.send_message(message.chat.id, exception.value) except exceptions.InvalidArgumentFormatException as exception: bot.send_message(message.chat.id, exception.value) except OSError as exception: logging.critical(exception) bot.send_message(message.chat.id, quotes.BACKEND_ERROR) raise except Exception as exception: logging.error(exception) bot.send_message(message.chat.id, quotes.UNEXPECTED_ERROR) raise
def proccess_bid(bid): item = database.get(bid['item']) if (item is None or item['timestamp'] > bid['timestamp'] or item['close_time'] < bid['timestamp'] or bid['user_id'] in item['bids'] and item['bids'][bid['user_id']]['amount'] > bid['bid_amount']): return None bid_details = { 'user_id': bid['user_id'], 'amount': bid['bid_amount'], 'timestamp': bid['timestamp'] } item['bids'][bid['user_id']] = bid_details item['bid_count'] += 1 if bid['bid_amount'] > item['highest_bid']: item['highest_bid'] = bid['bid_amount'] if bid['bid_amount'] < item['lowest_bid']: item['lowest_bid'] = bid['bid_amount'] database.add(item['item'], item) return bid_details
def match(self, line): if 'Steam shutdown' in line: self.on_shutdown() if 'END PrepareTeamBattleScreen' in line: if (match := re.search(r'winnerChars P1 \[(.*?)\] P2 \[(.*?)\]', line)): if len(match.group(1).split(',')) == 3: # player 1 wins if match.group(2): self.loser_score = len(match.group(2).split(',')) else: self.loser_score = 0 self.win = self.player_number == 1 elif len(match.group(2).split(',')) == 3: # player 2 wins if match.group(1): self.loser_score = len(match.group(1).split(',')) else: self.loser_score = 0 self.win = self.player_number == 2 else: return print('Match complete!') print(f'My score: {3 if self.win else self.loser_score}') print( f'{self.opp_name} score: {3 if not self.win else self.loser_score}' ) database.add(self.gameplay_random_seed, self.win, self.opp_name, self.opp_rank[0], self.opp_rank[1], self.my_rank[0], self.my_rank[1], self.loser_score) self.gameplay_random_seed = self.opp_name = self.opp_rank = self.my_rank = self.player_number = self.win = self.loser_score = None self.state = State.NO_MATCH database.publish()
def put(self): #print(self.request) name = self.get_argument('name') quantity = self.get_argument('quantity') item = database.Items(name=name, quantity=quantity) database.add(item)
def main_menu(): def menumap(display): # Tile Map Rendering tile_rects = [] heart_lst = [] enemy_lst = [] y = 0 for row in t.menu_map: x = 0 for tile in row: if tile == 1: display.blit(t.dirt1_img.convert_alpha(), (x * 30 - s.scroll[0], y * 30 - s.scroll[1])) tile_rects.append(pg.Rect(x * 30, y * 30, 30, 30)) if tile == 2: display.blit(t.grass_img.convert_alpha(), (x * 30 - s.scroll[0], y * 30 - s.scroll[1])) tile_rects.append(pg.Rect(x * 30, y * 30, 30, 30)) if tile == 3: display.blit(t.dirt2_img.convert_alpha(), (x * 30 - s.scroll[0], y * 30 - s.scroll[1])) sushi_rect = pg.Rect(x * 30, y * 30, 30, 30) heart_lst.append(sushi_rect) # pg.draw.rect(display, (255,0,0), sushi_rect, 2) if (tile == 4): # display.blit(display, ((x * 30 - s.scroll[0], y * 30 - s.scroll[1]))) sushi_img = display.blit( t.sushi.convert_alpha(), (x * 30 - s.scroll[0], y * 30 - s.scroll[1])) heart_rect = pg.Rect(x * 30 + 21, y * 30 + 30, 40, 40) heart_lst.append(heart_rect) if tile == 5: display.blit(t.enemy.convert_alpha(), (x * 30 - s.scroll[0], y * 30 - s.scroll[1])) enemy_rect = pg.Rect(x * 30, y * 30 + 10, 35, 45) enemy_lst.append(enemy_rect) # pg.draw.rect(display, (255,255,0), enemy_rect, 2) # Uncomment the below line to see tile rects # pg.draw.rect(display, (255, 0, 0), pg.Rect(x * 30, y * 30, 30, 30), 2) if tile == 6: display.blit(t.sand_img.convert_alpha(), (x * 30 - s.scroll[0], y * 30 - s.scroll[1])) tile_rects.append(pg.Rect(x * 30, y * 30, 30, 30)) x += 1 y += 1 def button(screen, position, text, size): font = pg.font.SysFont("Cambria", size) text_render = font.render(text, True, (255, 0, 0)) x, y, w, h = text_render.get_rect() x, y = position pg.draw.rect(screen, (120, 120, 200), (x - 5, y - 5, w + 10, h + 10)) pg.draw.rect(screen, (140, 140, 200), (x, y, w, h)) return screen.blit(text_render, (x, y)) def Entry(text, x, y, base_font=pg.font.Font(None, 30)): rect = pg.Rect((x, y, 400, 32)) color = (255, 0, 0) pg.draw.rect(screen, color, rect, 2) text_surface = base_font.render(text, True, (255, 255, 255)) screen.blit(text_surface, (rect.x + 5, rect.y + 5)) return rect def Label(text, x, y, base_font=pg.font.Font(None, 30)): text_surface = base_font.render(text, True, (255, 0, 0)) screen.blit(text_surface, (x, y)) screen = pg.display.set_mode((1000, 600)) pg.display.set_caption(s.title) bg = pg.image.load('png files/Menu bg.png') bg = pg.transform.scale(bg, (1000, 600)) type_sound = pg.mixer.Sound('Sounds/type2.wav') click_sound = pg.mixer.Sound('Sounds/Type.wav') icon = pg.image.load( 'png files/Still Animation/Still Character Animation1.png') pg.display.set_icon(icon) if len(database.show()) == 0: t1 = '' else: t1 = (database.show()[0])[0] run = True while run: screen.blit(bg, (0, 0)) menumap(screen) text_entry = Entry(t1, 300, 50) Label('Enter Name', 420, 100) b1 = button(screen, (350, 125), 'Start Game', 50) clear_btn = button(screen, (710, 55), 'Clear Text', 20) for event in pg.event.get(): if event.type == pg.QUIT: pg.quit() sys.exit() if event.type == pg.MOUSEBUTTONDOWN: if b1.collidepoint(pg.mouse.get_pos()): database.clear() database.add(t1) click_sound.play() main_Game() if clear_btn.collidepoint(pg.mouse.get_pos()): t1 = '' type_sound.play() if event.type == pg.KEYDOWN: if event.key == pg.K_BACKSPACE: type_sound.play() t1 = t1[0:-1] else: type_sound.play() t1 += event.unicode pg.display.update() pg.quit()
def add(request): text = request.POST['text'] database.add(text) return redirect('home')
def api_records_create(): location = request.json['location'] storedRecord = database.add(location) return jsonify(storedRecord), 201
if(database.checklogin(name)==0): print(name+' has checked in today in '+time); if(database.checklogin(name)==1): print(name+' has checked out today in '+time); database.checkin(name); break; c = cv2.waitKey(20) % 0x100; if(c == 27): break if(press == '2'): print('PLEASE ADD SOME INFO ABOUT THIS USER'); print('Name: ');name = input(); print('Position: ');position = input(); print('Phone: ');phone = input(); print('Sex: ');sex = input(); exist = database.add(name,position,phone,sex); if(exist is True): path = r'images/'+name; os.makedirs(path); while(True): ret,frame = cap.read(); adduser.add(path,frame); c = cv2.waitKey(20) % 0x100 if(c == 27): break train.update(); print(name+'has been added') if(exist is False): print(name+' has been existed'); if(press == '3'): print('1. Today');
def test_add_pizza_twice(self): database.create_menu_table('speedy') database.add('speedy', 'pizza', 3.50) self.assertFalse(database.add('speedy', 'pizza', 4.00))
@app.route('/api/records/<record_id>', methods=['DELETE']) def api_records_delete(record_id): database.delete(record_id) return "" @app.route('/api/records', methods=['POST']) def api_records_create(): location = request.json['location'] storedRecord = database.add(location) return jsonify(storedRecord), 201 if __name__ == '__main__': database.clear() # Initial last seen records database.add('Fenway Park') database.add('Faneuil Hall') database.add('Google Cambridge Office') app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 app.run(host='0.0.0.0', port=8080, debug=True, extra_files=[ 'templates/index.html', 'static/css/styles.css', 'static/js/main.js', 'static/img/delete.png' ])
def test_not_valid_product(self): database.create_menu_table('speedy') database.add('speedy', 'pizza', 3.5) self.assertFalse(database.valid_product('speedy', 'spaghetti'))
#! This program can keep your passwords encrypted """ With this program, you can keep all your passwords in safety. Commands: help, add, remove, find, change, showall, clear """ import database as data while True: task = str(input("Enter a command here: ")) if task == 'help': print(__doc__) elif task == 'add': # Добавления данных в словарь a = input(str("Enter resource: ")) b = input(str("Enter password: "******"Enter a key: ")) data.remove(a) elif task == 'find': # Поиск данных в словаре a = input(str("Enter a key:")) data.find(a) elif task == 'change': # Изменение данных в словаре a = input(str("Enter a key you want to rename: ")) data.change(a) elif task == 'showall': # Показать все данные в словаре data.showall() elif task == 'clear': data.clear() else: print("No such command %30s" % task)
def add_to_database(): """Add the current word to database.""" response = database.add(current_word)
def test_valid_product(self): database.create_menu_table('speedy') database.add('speedy', 'pizza', 3.5) self.assertTrue(database.valid_product('speedy', 'pizza'))
graph: Graph quit: Quit """) choice = input(">> ") # choice 1 adding if choice.lower() == "add": counter = eval(input("Enter number of students to be entered: ")) for i in range(counter): stud = eval(input("Enter Student Number: ")) name = input("Enter student name: ") surname = input("Enter student surname: ") database.add(stud, name, surname) input("Enter to continue....") # choice 2 deleting elif choice.lower() == "delete": print( "////////////////////////////////////////////////////////////////") print( " You about to delete a record be sure before proceeding " ) print( "////////////////////////////////////////////////////////////////") stud = input("Enter Student Number: ") database.delete(stud) input("Enter to continue....")
def test_get_closed(): txt = {'close_time': 5} database.add('key3', txt) assert database.get_closed(2) == []
def test_clear_db(): txt = '5G burns cookies!' database.add('key5', txt) database.clear() assert database.get('key5') is None
def test_local_modify_doest_affect_db(): txt = {'txt': 'For GONDOOOOOR'} database.add('key3', txt) data = database.get('key3') data['txt'] = 'For ROHAAAAAN' assert data['txt'] != database.get('key3')['txt']
def test_update_item_in_db(): txt = 'NOOOOOOOOO? *sobs*' database.add('key2', 'Luke I am your Father') database.add('key2', txt) assert database.get('key2') == txt
command = command.lower() #print (command) return command while True: command = commandUser() c = str(command) if (c == 'a'): key = input("Enter a name: ") key = key.lower() value = input("Enter the phone number(only enter digits): ") value = int(value) database.add("data.txt", key, value) elif (c == 'f'): key = input("Enter the name you would like to search for: ") key = key.lower() database.find("data.txt", key) elif (c == 'd'): key = input("Enter the name you would like to delete: ") key = key.lower() database.delete("data.txt", key) elif (c == 'u'): key = input("Enter the name you would like to search for: ") key = key.lower() database.update("data.txt", key)
def test_add_item_to_db(): txt = 'join the darkside' database.add('key', txt) assert database.get('key') == txt