Beispiel #1
0
def register():
    # Gets the information of the user to register for the database
    # return:
    #   user: if data provided is valid
    #   -1: if the user selects to go back
    valid_entry = False
    clear_screen()
    print("Register for new account")

    while not valid_entry:
        email = input("Email: ")
        user_data = getUser(email)
        if user_data:
            print("Email already in use")
        else:
            valid_entry = True
    name = input("Name: ")
    pwd = input("Password: "******"City: ")

    valid_entry = False
    while not valid_entry:
        gender = input("Gender (M/F): ")
        if gender == "M" or gender == "F":
            valid_entry = True
        else:
            print("Entry is invalid, Please enter M or F for gender")

    db.cur.execute("INSERT INTO users VALUES (?, ?, ?, ?, ?)", (email, name, pwd, city, gender))
    db.conn.commit()
    db.set_user(email, name, city, gender)
    return db.cur_user
def run(messaging_event):
    sender = messaging_event['sender_data']
    sender.update(db.get_user(sender['id']))
    if not sender.get('creation_time'):
        sender['creation_time'] = datetime.datetime.now(pytz.utc).isoformat()
    messages = process(messaging_event)
    sender['spoke'] = True
    sender['last_update_time'] = datetime.datetime.now(pytz.utc).isoformat()
    db.set_user(sender)
    return messages
Beispiel #3
0
def star_toggle(key):
    key = int(key)
    to_return = {"success": False, "error": None}
    user = get_user()["user"]

    if not user:
        to_return["error"] = "You are not logged in."
        return Response(dumps(to_return), mimetype="application/json"), 403

    if key in user["starred"]:
        user["starred"] = [x for x in user["starred"] if x != key]
        to_return["starred"] = False
    else:
        user["starred"].append(key)
        to_return["starred"] = True

    print "User stars: {}".format(user["starred"])
    if set_user(user):
        to_return["success"] = True
        return Response(dumps(to_return), mimetype="application/json")
    else:
        to_return["error"] = "Could not set user object."
        return Response(dumps(to_return), mimetype="application/json"), 500

    return Response(dumps(to_return), mimetype="application/json"), 403
Beispiel #4
0
def star_toggle(key):
    key = int(key)
    to_return = {"success": False, "error": None}
    user = get_user()["user"]

    if not user:
        to_return["error"] = "You are not logged in."
        return Response(dumps(to_return), mimetype="application/json"), 403

    if key in user["starred"]:
        user["starred"] = [x for x in user["starred"] if x != key]
        to_return["starred"] = False
    else:
        user["starred"].append(key)
        to_return["starred"] = True

    print "User stars: {}".format(user["starred"])
    if set_user(user):
        to_return["success"] = True
        return Response(dumps(to_return), mimetype="application/json")
    else:
        to_return["error"] = "Could not set user object."
        return Response(dumps(to_return), mimetype="application/json"), 500

    return Response(dumps(to_return), mimetype="application/json"), 403
Beispiel #5
0
def data_processing(id, pay, msg):
    if data.search_field(table_name="USERS",connection=connection,value=id, field="ID")==False:
        data.set_user(table_name="USERS", connection=connection,ID_VK=id)
    
    if pay=={"command":"start"} or pay == "admin":
        vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("START"))[0]})
        vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("HELP_MSG"))[0], "keyboard": get_main_keyboard(id =id, connection = connection)})
    
    elif msg=="admin":
        vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("ADMIN"))[0], "keyboard":key['start']})
    
    elif pay == "main_menu":
        vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("MAIN_MENU"))[0], "keyboard":get_main_keyboard(id =id, connection = connection)})

    elif pay=="subscribe":
        if data.get_field(connection=connection, table_name="USERS",select_field = "SUBSCRIBE", field="ID", value=id)[0][0]==False:
            print("tut")
            data.set_field(connection = connection, table_name = "USERS", ID_VK = id, field = "SUBSCRIBE", value = 1)
            vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("SUBSCRIBE"))[0], 'keyboard': get_main_keyboard(id =id, connection = connection)})
        else:
            data.set_field(connection = connection, table_name = "USERS", ID_VK = id, field = "SUBSCRIBE", value = 0)
            vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("UNSUBSCRIBE"))[0], 'keyboard': get_main_keyboard(id =id, connection = connection)})
    
    elif pay=="direction_selection":
        vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("DIRECTION_SELECTION"))[0], "keyboard":key['direction_selection']})
    
    elif pay=="sphere":
        sql = "DELETE FROM USERS_SPHERES WHERE ID_USER = "******"messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("SPHERE"))[0], "keyboard":key['sphere']})
    
    elif pay=="Машиностроение" or pay=="Безопасность" or pay=="Энергетика" or pay=="IT-технологии" or pay=="Электроника" or pay=="Авиация" or pay=="Общество" or pay=="Экономика" or pay=="Химия" or pay=="Языки" or pay=="Физика":
        sql = "SELECT ID_SPHERE FROM USERS_SPHERES WHERE ID_USER = "******"messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("ADD_MSG"))[0], "keyboard":key['sphere']})
                if len(size)+1>=3:
                    search_direction(id = id, type = "SPHERE")
        else:
            add_sphere(id=id,connection=connection, pay = pay)
            vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("ADD_MSG"))[0], "keyboard":key['sphere']})
        
   
    elif pay=="name_dir":
        sql = "DELETE FROM USERS_SUBJECTS WHERE ID_USER = "******"messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("NAME_DIR"))[0], "keyboard":key['subjects']})

    elif pay == "math" or pay == "biology" or pay == "geography" or pay == "foreign_language" or pay == "informatics" or pay == "history" or pay == "literature" or pay == "social_science" or pay == "physics" or pay == "chemistry":
        sql = "SELECT ID_SUB FROM USERS_SUBJECTS WHERE ID_USER = "******"messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("ADD_MSG"))[0], "keyboard":key['subjects']})
                if(len(idSub)+1>=2):
                    search_direction(id = id, type = "SUBJECTS")
        else:
            add_sub(id = id, connection = connection, sub = pay)
            vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("ADD_MSG"))[0], "keyboard":key['subjects']})
    
    elif pay == "search_by_sphere":
        search_direction(id = id, type = "SPHERE")
    elif pay == "search_by_subjects":
        search_direction(id = id, type = "SUBJECTS")
    elif pay == "lists":
        vk.method("messages.send", {"user_id": id, "message": "Выберите функцию:", "keyboard": key['list']})
    
    elif pay == "lk_code":
        vk.method("messages.send", {"user_id": id, "message": "Меня пока что этому не научили😞\nНо совсем скоро научат, обещаю!", "keyboard": get_main_keyboard(id =id, connection = connection)})
    
    elif pay == "frequency":
        vk.method("messages.send", {"user_id": id, "message": "Меня пока что этому не научили😞\nНо совсем скоро научат, обещаю!", "keyboard": get_main_keyboard(id =id, connection = connection)})
    
    elif msg == "Бу!":
        vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("FEAR_MSG"))[0], "keyboard": get_main_keyboard(id =id, connection = connection)})
    else:
        vk.method("messages.send", {"user_id": id, "message": random.choice(from_pay_to_msg("ERROR"))[0], "keyboard": get_main_keyboard(id =id, connection = connection)})
Beispiel #6
0
 if "payload" in messages["items"][0]["last_message"]:
     pay = messages["items"][0]["last_message"]["payload"][1:-1]
 else:
     pay = "0"
 try:
     pay = bytes(pay, 'cp1251').decode('utf-8')
 except ValueError:
     pass
 finally:
     print(pay)
 if data.search_field(table_name="Status",
                      connection=connection,
                      value=id,
                      field="id_vk") == False:
     data.set_user(table_name="Status",
                   connection=connection,
                   ID_VK=id)
 if pay == {"command": "start"} or pay == "admin":
     vk.method(
         "messages.send", {
             "user_id": id,
             "message": "Привет! Чем я могу тебе помочь?",
             "keyboard": keyboard_start
         })
 elif msg == "admin":
     vk.method(
         "messages.send", {
             "user_id": id,
             "message": "Начинаю с начала:",
             "keyboard": keyboard_null
         })