def get_items(): url = "https://api.steampowered.com/IEconDOTA2_570/GetGameItems/V001/" querystring = {"key": WebAPIKey} try: time.sleep(1) parsed_data = requests.request("GET", url, params=querystring, timeout=3).json() except TimeoutError: print('The request timed out') else: if debug: print('Request Received') if debug: print('====== Item List ======') for item in parsed_data['result']['items']: item_id = item['id'] item_name = item['name'][5:] item_cost = item['cost'] item_secret_shop = item['secret_shop'] item_side_shop = item['side_shop'] item_recipe = item['recipe'] if not check_item_exists(item_id): add_item(item_id, item_name, item_cost, item_secret_shop, item_side_shop, item_recipe)
def create_location(message): try: if ( Backend_stuff[6] == 1 ): # checking if bubbleID is created else dont generate another bubbleID chat_id = message.chat.id location = message.text Customeritem[6] = location print(Customeritem[6]) Backend_stuff[0] = database.add_user( chat_id, message.chat.username, message.chat.first_name) # adding username to backend print(Backend_stuff[0]) Backend_stuff[6] = Backend_stuff[6] + 1 print(Backend_stuff[6]) Backend_stuff[2], Backend_stuff[3] = database.add_bubble( Backend_stuff[1], Backend_stuff[0], bubbletype) print(Backend_stuff[2]) Backend_stuff[4] = database.add_item( Backend_stuff[1], Customeritem[2], Customeritem[7], Customeritem[9], Customeritem[4], Customeritem[5], int(Customeritem[3])) # adding item into backend and itemID print(Backend_stuff[4]) Backend_stuff[5] = database.add_order( Backend_stuff[2], Backend_stuff[0], Backend_stuff[4], Customeritem[6]) # adding order and get PTN print(Backend_stuff[5]) markup9 = types.ReplyKeyboardMarkup(row_width=1) itembtn1 = types.KeyboardButton('Yes') itembtn2 = types.KeyboardButton('No') markup9.add(itembtn1, itembtn2) msg = bot.reply_to( message, """Do you want to continue shopping with the same retailer?""", reply_markup=markup9) bot.register_next_step_handler(msg, create_continue) except Exception as e: bot.reply_to(message, 'oooops')
def item(): if request.method == "POST": item = json.loads(request.data) db_item = db.add_item(name=item["ItemName"], room=item["Room"], owner=item["Owner"], value=item["Value"], quant=item["Quantity"], size=item["Size"], priority=item["Priority"], fragile=item["Fragile"], owned=item["Owned"], moved=item["Moved"], keeping=item["Keeping"], notes=item["Notes"]) return json.dumps(db_item), 201, json_content elif request.method == "GET": items = db.get_items() return json.dumps(items), 200, json_content elif request.methos == "DELETE": item = json.loads(request.data) db_item = db.delete_item(item["ItemName"]) return json.dumps(db_item), json_content
def join_confirm(message): try: chat_id = message.chat.id confirmation = message.text if (confirmation == 'Yes'): Backend_stuff[0] = database.add_user(chat_id, message.chat.username, message.chat.first_name) print(Backend_stuff[0]) Backend_stuff[2], Backend_stuff[1] = database.retrieve_bubble( Joinitem[0]) print(Backend_stuff[2]) Backend_stuff[4] = database.add_item(Backend_stuff[1], Joinitem[1], Joinitem[5], Joinitem[8], Joinitem[3], Joinitem[4], int(Joinitem[2])) print(Backend_stuff[4]) Backend_stuff[5] = database.add_order(Backend_stuff[2], Backend_stuff[0], Backend_stuff[4], (Joinitem[0])[7:]) print(Backend_stuff[5]) markup15 = types.ReplyKeyboardMarkup(row_width=1, one_time_keyboard=True) itembtn1 = types.KeyboardButton('Yes') itembtn2 = types.KeyboardButton('No') markup15.add(itembtn1, itembtn2) msg = bot.reply_to( message, """Do you want to continue shopping with the same retailer?""", reply_markup=markup15) bot.register_next_step_handler(msg, join_continue) else: Thread(target=command_start(message)).start() except Exception as e: bot.reply_to(message, 'oooops')
def create_location(message): try: chat_id = message.chat.id location = message.text print(location) Customeritem[6] = location Backend_stuff[0] = database.add_user(message.chat.first_name) print(Backend_stuff[0]) if (Backend_stuff[6] == 1): Backend_stuff[6] = Backend_stuff[6] + 1 print(Backend_stuff[6]) Backend_stuff[2], Backend_stuff[3] = database.add_bubble( Backend_stuff[1], Backend_stuff[0], Customeritem[6]) print(Backend_stuff[2]) Backend_stuff[4] = database.add_item(1, Customeritem[2], Customeritem[7], Customeritem[9], Customeritem[4], Customeritem[5], int(Customeritem[3])) #itemID = database.add_item(1, 'www.blah4.com', 'purple tee', 20.25, 'EU 34', 'purple', 2) print(Backend_stuff[4]) Backend_stuff[5] = database.add_order(Backend_stuff[2], Backend_stuff[0], Backend_stuff[4]) print(Backend_stuff[5]) markup9 = types.ReplyKeyboardMarkup(row_width=1) itembtn1 = types.KeyboardButton('Yes') itembtn2 = types.KeyboardButton('No') markup9.add(itembtn1, itembtn2) msg = bot.reply_to( message, """Do you want to continue shopping with the same retailer?""", reply_markup=markup9) bot.register_next_step_handler(msg, create_continue) #Thread(target=command_start(message)).start() except Exception as e: bot.reply_to(message, 'oooops')
def add_item(user_id, item_id): conn = sqlite3.connect(db) if (conn is not None): database.add_item(conn, user_id, item_id) conn.close()
def database_page(): """Handles the /database (or database view) of the website.""" # If there is a "GET" request (ie. just loading the page) # Load the page with the list of foods pulled from the database if request.method == "GET": return render_template("database.html", foods=pull_items(), active_page="database") else: # POST method -> "ADD" Form has been submitted # Pulls the 'keys' or items in the form values = list(request.form.keys()) # Checks to ensure all of the values required are present if ("food" in values and "description" in values and "food_type" in values and "image" in values and "recipe" in values and "recipe_link" in values): # Assigns variables to all of the form's items food, description, food_type, image_link, recipe, recipe_link = ( request.form.get("food"), request.form.get("description"), request.form.get("food_type"), request.form.get("image"), request.form.get("recipe"), request.form.get("recipe_link"), ) # Current count of the database count = count_database() # if count == None: #! Error! count_database has returned invalid input # Re-render the page again return render_template("database.html", foods=pull_items(), active_page="database") # Downloads the image, stores it, and provides the location image_location = download_image(image_link, str(count)) # Adds all of the information to the database db_add = add_item( food=food, food_type=food_type, recipe=recipe, recipe_source=recipe_link, description=description, image_location=image_location, image_link=image_link, ) # If the addition fails, reload the page if db_add == None: #! Error! db_add provided invalid input return render_template("database.html", foods=pull_items(), active_page="database") # * The form has been succesfully added to the database, reload the page return render_template("database.html", foods=pull_items(), active_page="database") elif "food_select" in values: # Post Method -> "REMOVE" form has been submitted # Removes from the database remove_item(str(request.form.get("food_select"))) # Renders the page return render_template("database.html", foods=pull_items(), active_page="database") else: # Catch-all, re-renders the page render_template("database.html", foods=pull_items(), active_page="database")
'text': 'Reminder. This event will begin soon!', } bot_message['thread'] = {"name": thread} message_headers = {'Content-Type': 'application/json; charset=UTF-8'} http_obj = Http() response = http_obj.request( uri=hook, method='POST', headers=message_headers, body=dumps(bot_message), ) if response[0]['status'] == '200': return True if __name__ == '__main__': while True: for link in rss_list: events = get_events_from_rss(link) for event in events: if is_unique(event.name): thread = send_message(event) if thread: add_item(event, thread) for item in get_upcoming_events(): if item.thread: remind_about_event(item.thread) #24 hours time.sleep(60 * 60 * 24)