def __init__(self, threadID, lock, region): threading.Thread.__init__(self) self.player_region = region self.threadID = threadID self.lock = lock self.database = Database(DATABASE_DETAILS) self.m = Misc()
def create_region_tables(self): from classes import DATABASE_DETAILS, Database, REGIONS database = Database(DATABASE_DETAILS) tables = ["averages", "champ_stats", "final_stats", "game_stats", "games", "games_checked", "players_checked", "summoners"] for region in REGIONS: all_champs = list(database.get_all_items("Base_champ_list", "id")) for table in tables: database.clone_table(region + "_" + table, "Base_" + table) for champ in all_champs: database.clone_table(region + "_" + str(champ), "Base_champ") for i in range(3): database.insert_items(region + "_final_stats", "game_id", i) for champ in all_champs: database.insert_items(region + "_averages", "champ_id", champ) database.insert_items(region + "_champ_stats", "id, name", str(champ) + " , " + database.get_database_item("Base_champ_list", "id", champ, "name") ) database.close_db()
def visit(ShortAddr): database = Database(filename) LongAddr = database.find(ShortAddr) if (LongAddr == ''): return render_template('home.html', ShortAddr="", LongAddr="", status=2) else: return redirect(LongAddr)
def home(): LongAddr = "" ShortAddr = "" status = 0 # status=0: Nothing input. # status=1: Input is not a valid url. # status=2: You are trying to visit a short address not existing in the database. if (request.method == 'POST'): LongAddr = request.form['LongAddr'] if (not IfValidUrl(LongAddr)): status = 1 return render_template('home.html', ShortAddr=ShortAddr, LongAddr=LongAddr, status=status) database = Database(filename) digit = 4; ShortAddr = GenerateShort(LongAddr,digit) search = database.find(ShortAddr) while(search != ''): if (search == LongAddr): break; else: digit = digit + 1 ShortAddr = GenerateShort(LongAddr, digit) search = database.find(ShortAddr) if (search == ''): database.insert(ShortAddr, LongAddr) ShortAddr = 'http://hoogle.xyz/'+ShortAddr return render_template('home.html', ShortAddr=ShortAddr, LongAddr=LongAddr, status=status)
def register(): status = 0 if request.method == 'POST': user_name = request.form['user_name'] if not user_name.isalnum(): return render_template('register.html', status=-4, language=session['language'], user_name=user_name) user_email = request.form['user_email'] # 检查是否合法邮件地址 if not ifValidEmail(user_email): return render_template('register.html', status=-5, language=session['language'], user_name=user_name) password = request.form['password'] password1 = request.form['password1'] database = Database(filename) status = database.insertUser(user_name, user_email, password, password1) if status != 0 and status != -1 and status != -2 and status != -3 and status != -4 and status != -5 and status != -6: session['user_id'] = status return redirect(url_for('result')) return render_template('register.html', status=status, language=session['language'], user_name='Guest')
def fridges_delete(): database = Database(filename) user_id = session['user_id'] #user_id = 1 material = request.args['name'] #print 'calling deleteFromFridge({},{})'.format(user_id, [material]) database.deleteFromFridge(user_id, [material]) return redirect(url_for('fridges'))
def verify(verification_code): database = Database(filename) status = database.verifyEmail(verification_code) if status == -1: return '错误的激活链接' else: session['user_id'] = status return redirect(url_for('result'))
def admin_my_recipes_delete(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = request.args['current_user_id'] database = Database(filename) database.deleteMyRecipeEntry(user_id, request.args['id']) return redirect(url_for('admin_my_recipes', user_id=user_id))
def __init__(self, threadID, lock, database_details, api_key): threading.Thread.__init__(self) self.threadID = threadID self.lock = lock self.api_key = api_key self.database_details = database_details self.database = Database(database_details) self.static = Static(api_key) self.misc = Misc()
def profile(): user_id = session['user_id'] database = Database(filename) user_profile = database.findUserProfile(user_id) user_name = database.findUserName(user_id) return render_template('profile.html', user_id=user_id, user_profile=user_profile, user_name=user_name, language=session['language'])
def debug(): user_id = session['user_id'] database = Database(filename) user_group = database.findUserGroup(user_id) user_name = database.findUserName(user_id) return render_template('debug.html', user_id=user_id, user_group=user_group, user_name=user_name, language=session['language'])
def DBFunc(): x = Database() function = request.args['function'] print(function) if function == "init": get_db() elif function == "fill": x.objToDB() elif function == "drop": delete_db() return jsonify(True)
def fridges_insert(): database = Database(filename) user_id = session['user_id'] #user_id = 1 # user_fridge is a list of what is already in fridge if request.method == 'POST': add_stock_text = request.form['content'] if add_stock_text == '': return redirect(url_for('fridges')) add_stock_text = add_stock_text.split(' ') database.insertToFridge(user_id, add_stock_text) return redirect(url_for('fridges'))
def admin_fridges_delete(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = request.args['current_user_id'] database = Database(filename) #user_id = 1 material = request.args['name'] #print 'calling deleteFromFridge({},{})'.format(user_id, [material]) database.deleteFromFridge(user_id, [material]) return redirect(url_for('admin_fridges', user_id=user_id))
def recipes(): if 'user_id' in session: user_id = session['user_id'] database = Database(filename) user_name = database.findUserName(user_id) recipes = database.deliverRecipe() return render_template('recipes.html', user_id=session['user_id'], recipes=recipes, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def admin_user_list(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" database = Database(filename) conn = sqlite3.connect(filename) c = conn.cursor() users = c.execute('SELECT * FROM users') # users is a cursor object users = list( users ) # users is a list of tuple, like [(0,'admin','*****@*****.**'),(1,'111','*****@*****.**'),(2,'222','*****@*****.**')] return render_template('admin_user_list.html', users=users)
def recipes_insert(): database = Database(filename) if request.method == 'POST': content = request.form['content'] if content == '': return redirect(url_for('recipes')) content = Unicode_to_UTF8(content) content = content.split(' ') dish_name = content[0] content.remove(dish_name) components = content database.insertRecipeEntry(dish_name, components) return redirect(url_for('recipes'))
def result(): if 'user_id' in session: database = Database(filename) user_id = session['user_id'] user_name = database.findUserName(user_id) #user_id = 1 recipes = database.deliverMyRecipe(user_id) fridge = database.deliverFridge(user_id) if len(fridge) != 0: fridge = fridge[0][1] fridge = fridge.split(' ') # fridge is a list of what you have-unicode # recipes is a list of tuple recipe_list = list(recipes) result_list = [] for one_recipe in recipes: dish_num = one_recipe[0] dish_name = one_recipe[1] still_need = one_recipe[2].split( ' ') #components is a list of materials. what_i_have = [] for item in fridge: if item in still_need: still_need.remove(item) what_i_have.append(item) this_entry = [] this_entry.append(dish_num) this_entry.append(dish_name) this_entry.append(what_i_have) this_entry.append(still_need) this_entry.append(len(still_need)) result_list.append(this_entry) sorted_result = [] while len(result_list) != 0: min = 10000 to_delete = 0 for line in result_list: if line[4] < min: min = line[4] to_delete = line sorted_result.append(to_delete) result_list.remove(to_delete) # soted_result is a list: # [dish_num, dish_name, list(what_i_have), list(material still needed), item number still needed] return render_template('result.html', user_id=session['user_id'], data=sorted_result, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def reset_database(): tables = ["summoners", "averages", "champ_stats", "final_stats", "game_stats", "games"] database = Database(DATABASE_DETAILS) all_champs = list(database.get_all_items("Base_champ_list", "id")) misc = Misc() for region in REGIONS: for table in tables: database.delete_table(region + "_" + table) database.replicate_table("Base_" + table, region + "_" + table) for champ in all_champs: database.delete_table(region + "_" + str(champ)) database.replicate_table("Base_champ", region + "_" + str(champ))
def admin_my_recipes(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = request.args['user_id'] recipes = [] if request.method == 'POST': user_id = request.form['next_user_id'] database = Database(filename) recipes = database.deliverMyRecipe(user_id) return render_template('admin_my_recipes.html', user_id=user_id, recipes=recipes)
def my_recipes(): if 'user_id' in session: user_id = session['user_id'] database = Database(filename) user_name = database.findUserName(user_id) user_group = database.findUserGroup(user_id) if user_group == 2: return "您必须先验证邮箱才能使用功能" recipes = database.deliverMyRecipe(user_id) return render_template('my_recipes.html', user_id=session['user_id'], recipes=recipes, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def admin_statistics(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" database = Database(filename) conn = sqlite3.connect(filename) c = conn.cursor() num_recipes = c.execute('select count(*) from recipes') num_recipes = num_recipes.fetchone()[0] num_users = c.execute('select count(*) from users') num_users = num_users.fetchone()[0] return render_template('admin_statistics.html', num_users=num_users, num_recipes=num_recipes)
def admin_fridges(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = request.args['user_id'] if request.method == 'POST': user_id = request.form['next_user_id'] database = Database(filename) fridges = database.deliverFridge(user_id) if len(fridges) != 0: fridges = fridges[0][1].split(' ') # now fridges is a list of stock return render_template('admin_fridges.html', user_id=user_id, fridges=fridges)
def admin_fridges_insert(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = 0 if request.method == 'POST': user_id = request.form['current_user_id'] database = Database(filename) # user_fridge is a list of what is already in fridge add_stock_text = request.form['content'] if add_stock_text == '': return redirect(url_for('admin_fridges', user_id=user_id)) add_stock_text = add_stock_text.split(' ') database.insertToFridge(user_id, add_stock_text) return redirect(url_for('admin_fridges', user_id=user_id))
def fridges(): if 'user_id' in session: database = Database(filename) user_id = session['user_id'] user_name = database.findUserName(user_id) user_group = database.findUserGroup(user_id) if user_group == 2: return "您必须先验证邮箱才能使用功能" #user_id = 1 fridges = database.deliverFridge(user_id) if len(fridges) != 0: fridges = fridges[0][1].split(' ') # now fridges is a list of stock return render_template('fridges.html', user_id=session['user_id'], fridges=fridges, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def admin_my_recipes_insert(): if not 'user_id' in session: return redirect(url_for('login_name')) if session['user_id'] != 0: return "You don't have the access!" user_id = 0 if request.method == 'POST': user_id = request.form['current_user_id'] database = Database(filename) content = request.form['content'] if content == '': return redirect(url_for('admin_my_recipes', user_id=user_id)) content = Unicode_to_UTF8(content) content = content.split(' ') dish_name = content[0] content.remove(dish_name) components = content database.insertMyRecipeEntry(user_id, dish_name, components) return redirect(url_for('admin_my_recipes', user_id=user_id))
def login_email(): status = 0 if request.method == 'POST': user_email = request.form['user_email'] password = request.form['password'] database = Database(filename) user_id = database.verifyPassword_user_email(user_email, password) if user_id == -1: # user does not exist status = -1 elif user_id == -2: # mismatch password status = -2 elif user_id == 0: session['user_id'] = user_id return redirect(url_for('admin')) else: # 判断用户名密码是否匹配 session['user_id'] = user_id return redirect(url_for('result')) return render_template('login_email.html', status=status, language=session['language'])
def __init__(self, region, database_details): threading.Thread.__init__(self) self.player_region = region self.database = Database(database_details)
def __init__(self, region): self.region = region self.database = Database(DATABASE_DETAILS) self.games_folder = GAMES_FOLDERS_PATH + region self.s = Stat_rating() self.misc = Misc()
import mysql.connector from classes import OpenFoodFact from classes import Database access_to_db = False while not access_to_db: database = Database('alimentation') access_denied = database.create_db() if access_denied: print(access_denied) print("Use another user") continue else: database.create_tables() database.insert_data() break def main(): main_menu = True choice_cat = False while main_menu: print(45 * '-') print("1- What food do you want to replace ?\n" "2- Find my substituted foods\n" "3- Quit the program") response1 = input(': ') print(45 * '-')