def post_ratings(): if session['username'] == "": flash("Please enter a valid username on the home page.") return redirect(url_for("home")) user = session['username'] name = database.getName(str(user)) #unicode again, for some reason questions = open("questions.txt", "r").readlines() ratees = database.getRatees(user) project = database.getCurrentProject(user) if request.method == "GET": return render_template("post_ratings.html", username = user, first = name[0], last = name[1], ratees = ratees, project = project, questions = questions) else: button = request.form["button"] if button == "Cancel": session['username'] == "" return redirect(url_for("home")) elif button == "Save": #THIS IS THE PROBLEM WITH OUR PROJECT #In conjunction with the problem line in database.py, the block below is causing our major post_rating error. ratings = {} for groupmember in ratees: ratings[groupmember] = [] for qnum in range(len(questions)): ratings[groupmember[qnum]] = [] ratings[groupmember[qnum]].append(int(request.form["%i:%s:%i"%(project, groupmember, qnum)])) print ratings database.setRatings(str(user),ratings, len(questions)) session['username'] = "" return redirect(url_for("home"))
def view_ratings(): if session['username'] == "": flash("Please enter a valid username on the home page.") return redirect(url_for("home")) if request.method == "GET": user = session['username'] name = database.getName(str(user)) #note: we have no idea why str(user) is necessary. user should not be unicode. questions = open("questions.txt", "r").readlines() return render_template("view_ratings.html", username = user, first = name[0], last = name[1], ratings = database.getRatings(user), questions = questions) else: button = request.form["button"] if button == "Cancel": session['username'] = "" return redirect(url_for("home")) elif button == "Post Ratings": return redirect(url_for("post_ratings"))
def main(): vk_session = vk_api.VkApi( token='3de9c0ce56bb265632da8c7348a37fe081ebd68d9744120f9da0108b82654974ccd938d58ceee8cc26b9c') longpoll = VkBotLongPoll(vk_session, '203395569') city = None asked = False lens = False asked1 = False greet = False asked_type = False started = False renew = False score = 0 city_last = False in_menu = True city_rand2 = False asked2 = False first_place = False guessing_city = False showing_place = False played_cities = False playing_cities = False geocoding = False for event in longpoll.listen(): vk = vk_session.get_api() if event.type == VkBotEventType.MESSAGE_NEW: if not greet: response = vk.users.get(user_id=event.obj.message['from_id']) vk.messages.send(user_id=event.obj.message['from_id'], random_id=random.randint(0, 2 ** 64), message=f'Приветствую тебя, {response[0]["first_name"]}') greet = True if event.message.text.lower() == 'выйти': showing_place = False playing_cities = False geocoding = False guessing_city = False first_place = False score = 0 in_menu = True lens = False city = None asked = False asked2 = False asked_type = False # навыки: if event.message.text == 'Покажи место' or showing_place: showing_place, asked, asked_type, city, in_menu = func_showing_place(event, asked, asked_type, city, vk, showing_place, in_menu) if (event.message.text == 'zen' or event.message.text == 'пасхалка') and in_menu: vk.messages.send(user_id=event.obj.message['from_id'], message=random.choice(['У самурая нет цели, только путь...', 'почему так...', 'не теряем время, нужно решать задачи...']), keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), random_id=random.randint(0, 2 ** 64)) if event.message.text == 'Рейтинг': data = database.getName() rating1 = [] rating2 = [] try: for i in data: data2 = database.getData(i[0]) for j in range(len(data2)): try: rating1.append(f'{i[1]} - {data2[j][3]}') rating2.append(f'{i[1]} - {len(data2[j][2].split())}') except Exception: pass vk.messages.send(user_id=event.obj.message['from_id'], message='Рейтинг игры в города:', keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), random_id=random.randint(0, 2 ** 64)) if rating1: for i in rating1: vk.messages.send(user_id=event.obj.message['from_id'], message=i, keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), random_id=random.randint(0, 2 ** 64)) else: vk.messages.send(user_id=event.obj.message['from_id'], message='Нет данных', keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), random_id=random.randint(0, 2 ** 64)) vk.messages.send(user_id=event.obj.message['from_id'], message='Рейтинг "угадай город":', keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), random_id=random.randint(0, 2 ** 64)) if rating2: for i in rating2: vk.messages.send(user_id=event.obj.message['from_id'], message=i, keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), random_id=random.randint(0, 2 ** 64)) else: vk.messages.send(user_id=event.obj.message['from_id'], message='Нет данных', keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), random_id=random.randint(0, 2 ** 64)) except Exception as a: vk.messages.send(user_id=event.obj.message['from_id'], message=a, keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), random_id=random.randint(0, 2 ** 64)) if event.message.text == 'Геокодер' or geocoding: event, asked1, vk, geocoding, in_menu = func_geocoder(event, asked1, vk, geocoding, in_menu) if event.message.text == 'Игра в города' or playing_cities: try: event, playing_cities, started, city_last, vk, in_menu, played_cities, score = func_play_cities( event, playing_cities, started, city_last, vk, in_menu, played_cities, score) except Exception as err: vk.messages.send(user_id=event.obj.message['from_id'], random_id=random.randint(0, 2 ** 64), keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), message=f'Произошла ошибка. Вы находитесь в меню.') showing_place = False playing_cities = False geocoding = False guessing_city = False first_place = False score = 0 in_menu = True lens = False city = None asked = False asked2 = False asked_type = False if event.message.text == 'Угадай город' or guessing_city: event, guessing_city, in_menu, asked2, vk, city_rand2 = func_guess_city(event, guessing_city, in_menu, asked2, vk, city_rand2) if event.message.text == 'Расстояния' or lens: try: event, vk, lens, in_menu, first_place, renew = func_distance(event, vk, lens, in_menu, first_place, renew) except Exception as err: vk.messages.send(user_id=event.obj.message['from_id'], random_id=random.randint(0, 2 ** 64), keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), message=f'Произошла ошибка. Вы находитесь в меню.') showing_place = False playing_cities = False geocoding = False guessing_city = False first_place = False in_menu = True lens = False city = None asked = False asked2 = False asked_type = False if in_menu and not (event.message.text == 'zen' or event.message.text == 'пасхалка'): vk.messages.send(user_id=event.obj.message['from_id'], random_id=random.randint(0, 2 ** 64), keyboard=open('kb1.json', 'r', encoding='UTF-8').read(), message=f'Я SpaceBot и у меня есть множество функций. Их всех ты сейчас видишь на клавиатуре.')