def user_exist_and_paired(auth_token):

    connection = connect()

    try:

        cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

        query = "select * from user where open_id = %s"

        if cursor.execute(query, auth_token):

            connection.commit()

            user_info = cursor.fetchone()

            if user_info["couple_id"] == -1:
                connection.close()

                return True, False, user_info["id"]  # 是否存在 是否配对 id是几
            else:
                connection.close()

                return True, True, user_info["id"]
        else:
            connection.close()

            return False, False, -1

    except:
        connection.close()

        return False, False, -1
def has_complete(auth_token):
    connection = connect()
    try:

        cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

        query = "select * from user where id = %s"

        if cursor.execute(query, auth_token):

            connection.commit()

            current_user = cursor.fetchone()

            if current_user["task_proc"] == 2:

                if cursor.execute(query, current_user["couple_id"]):

                    connection.commit()

                    if cursor.fetchone()["task_proc"] == 2:

                        connection.close()

                        return True, current_user["couple_id"]

        connection.close()

        return False, -1

    except:
        connection.close()

        return False, -1
def get_status_service(auth_token):

    connection = connect()

    try:

        cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

        query = "select * from user where id = %s"

        if cursor.execute(query, (auth_token)):

            connection.commit()

            user_state = cursor.fetchone()

            connection.close()

            return True, "获取用户信息成功", user_state

        else:

            connection.close()

            return False, "用户不存在", "null"

    except:
        connection.close()

        return False, "无法连接数据库", "null"
def task1_question_service():

    connection = connect()

    try:

        cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

        query = "select * from question"

        if cursor.execute(query):

            connection.commit()

            questions = cursor.fetchall()

            connection.close()

            return True, "获取问题成功", questions

        else:

            connection.close()

            return False, "获取问题失败", "null"

    except:

        connection.close()

        return False, "无法连接数据库", "null"
def submit_task2_service(auth_token, file):

    connection = connect()

    try:

        if file and allowed_file_photo(file.filename):

            filename = file.filename

        else:

            return False, "图片上传失败,只能上传png、jpg、jpeg格式", "null"

        new_filename = auth_token + "." + str(filename).split(".")[1]

        img_path = UPLOAD_FOLDER_PHOTO + new_filename

        file.save(str(img_path))

        cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

        img_path = config['display_path'] + "photo/" + new_filename

        task_query = "update task set img_path = %s where u_id = %s"

        user_query = "update user set task_proc = 2 where id = %s"

        try:

            cursor.execute(task_query, (img_path, auth_token))

            cursor.execute(user_query, auth_token)

            connection.commit()

            connection.close()

            return True, "图片上传成功", "null"

        except:

            connection.rollback()

            connection.close()

            return False, "图片上传失败", "null"

    except:

        connection.close()

        return False, "无法连接数据库", "null"
def upload_audio_service(auth_token, file):

    connection = connect()

    try:

        if file and allowed_file_audio(file.filename):

            filename = file.filename

        else:

            return False, "彩蛋上传失败,只能上传mp3、wma、wav格式", "null"

        new_filename = auth_token + "." + str(filename).split(".")[1]

        audio_path = UPLOAD_FOLDER_AUDIO + new_filename

        file.save(str(audio_path))

        cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

        egg_path = config['display_path'] + "audio/" + new_filename

        query = "update user set egg_status = 1, egg_path = %s where id = %s"

        try:

            cursor.execute(query, (egg_path, auth_token))

            connection.commit()

            connection.close()

            return True, "彩蛋上传成功", "null"

        except:

            connection.rollback()

            connection.close()

            return False, "彩蛋上传失败", "null"

    except:

        connection.close()

        return False, "无法连接数据库", "null"
def get_egg_service(auth_token):

    connection = connect()

    try:

        cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

        query = "select * from user where id = %s"

        if cursor.execute(query, (get_couple_id(auth_token)[1])):

            connection.commit()

            egg_path = cursor.fetchone()

            query = "update user set egg_status = 2 where id = %s"

            try:

                cursor.execute(query, (auth_token))

                connection.commit()

            except:

                connection.rollback()

            connection.close()

            return True, "获取彩蛋成功", egg_path["egg_path"]

        else:

            connection.close()

            return False, "获取彩蛋失败", "null"

    except:

        connection.close()

        return False, "无法连接数据库", "null"
Exemple #8
0
def details_of_branches_api():

    para_data = {}

    logger.info(request.headers)
    logger.info(request.args)

    if "Authorization" in request.headers.keys():
        headers = request.headers['Authorization']
        conf = ValidateApiToken(headers)
        verify = conf.verify_token()

        if verify['Access'] == "Access Granted":
            logger.info(verify)
            try:
                para_data["bank_name"] = request.args['bank_name']
                para_data["city"] = request.args['city']
                para_data["limit"] = request.args['limit']
                para_data["offset"] = request.args['offset']
            except Exception:
                para_data["limit"] = 10
                para_data["offset"] = 0

            db_connect = service.connect(para_data)
            return json.dumps(
                {
                    'success': True,
                    "Details_of_Branches": db_connect
                },
                default=str)

        elif verify['success'] == False and verify['Access'] == 'Access Denied':
            logger.error(verify['Access'])
            return jsonify({'Error': "Invalid credentials"}), 400

        else:
            logger.error(verify['Access'])
            return jsonify({'Error': "Oops Token Expired"}), 400
    else:
        logger.error("Invalid Access_token")
        return jsonify({'Error': "Invalid request"}), 400
def get_user_id(auth_token):

    connection = connect()
    try:

        cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

        query = "select * from user where open_id = %s"

        if cursor.execute(query, auth_token):
            user_id = cursor.fetchone()
            connection.close()

            return True, user_id["id"]
        else:
            connection.close()

            return False, "null"
    except:
        connection.close()

        return False, "无法连接数据库"
def submit_task1_service(auth_token, get_answer, get_standard):

    connection = connect()

    try:

        cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

        insert_query = "insert into task(u_id,answer,standard) values(%s,%s,%s)"

        update_query = "update user set task_proc = 1 where id = %s"

        try:

            cursor.execute(insert_query,
                           (auth_token, get_answer, get_standard))

            cursor.execute(update_query, auth_token)

            connection.commit()

            connection.close()

            return True, "Success", "null"

        except:

            connection.rollback()

            connection.close()

            return False, "用户已经提交过任务", "null"

    except:

        connection.close()

        return False, "无法连接数据库", "null"
Exemple #11
0
import threading
import tkinter
from tkinter import messagebox
import service

# Ho importato service.py che gestisce configurazione dei socket e creazione della connesione, cosi
# nel caso ci sarà un errore catturato da try-except il programma si chiuderà prima evitando di sprecare più memoria
# per dedicarla alle variabili interessate a creare la finestra del gioco

# Richiamando la funzione che risiede nel service.py restituisco a gui.py gli oggetti dei rispettivi
# socket tcp e udp multicast
tcps, udps = service.connect()

num_b = 10  # Numero massimo di palline nel gioco
# Numero massimo dei giocatori in una partita (Tale caratteristica l'ho gestita e aggiunta anche nel lato server)
num_players = 23
player_names = [
]  # Lista dedicata alle stringhe dei rispettivi nomi e punti ottenuti dei giocatori
balls = [
]  # Lista delle palline che permetterà in futuro ad accedere a ogni oggeto oval e spostarla alle sue nuove coordinate

window = tkinter.Tk()  # Creazione della finestra principale del gioco
window.title("ClickerPy")  # Imposto il titolo della finestra
window.geometry('740x740')  # Configurazione delle dimensioni della finestra
window.configure(
    background="#111217")  # Configurazione del colore dello sfondo
window.resizable(
    0, 0
)  # Aggiungo la restrizione che vieta il cambiamento delle dimensioni della finestra

l_frame = tkinter.Frame(
def request_token_service(auth_code, inviter_id):

    url = "https://api.weixin.qq.com/sns/jscode2session?appid="+app_config['appid']+"&secret="\
          +app_config['secret']+"&js_code="+auth_code+"&grant_type=authorization_code"

    req = urllib2.Request(url)
    res_data = urllib2.urlopen(req)
    res = res_data.read()
    res_json = res.decode('utf-8')

    wechat_res = json.loads(s=res_json)

    result = dict()

    try:
        open_id = wechat_res["openid"]
    except:
        return False, "invalid code", "null"

    connection = connect()
    cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

    try:

        judgement = user_exist_and_paired(open_id)

        result["id"] = judgement[2]

        if not judgement[0]:

            query = "insert into user(open_id) values(%s)"

            try:
                cursor.execute(query, (open_id))

                connection.commit()

                result["id"] = get_user_id(open_id)[1]

            except:

                connection.rollback()

                connection.close()

                return False, "数据库连接失败", "null"

        user_id = result["id"]

        if inviter_id != -1:

            couple_id = get_couple_id(user_id)[1]

            if couple_id == inviter_id:

                return True, "情侣登录成功", result

            if judgement[1]:

                connection.close()

                return True, "有邀请人登录成功,但该用户已经配对无法接受邀请", result

            if user_exist_and_paired(inviter_id)[1]:

                connection.close()

                return True, "有邀请人登录成功,但邀请人已经配对无法接受邀请", result

            try:

                if inviter_id == user_id:

                    return True, "有邀请人登陆成功,但不能和自己配对", result

                else:
                    query = "update user set couple_id = %s where id = %s"

                    cursor.execute(query, (inviter_id, user_id))

                    cursor.execute(query, (user_id, inviter_id))

                    connection.commit()

                    connection.close()

                    return True, "有邀请人登录配对成功", result

            except:

                connection.rollback()

                connection.close()

                return True, "有邀请人登录成功,配对失败", result

        connection.close()

        return True, "无邀请人登录成功", result

    except:
        connection.close()

        return False, "数据库连接失败", "null"
def get_report_service(auth_token):

    connection = connect()

    try:

        complete_condition = has_complete(auth_token)

        if complete_condition[0]:

            cursor = connection.cursor(cursor=pymysql.cursors.DictCursor)

            query = "select * from task where u_id = %s"

            if cursor.execute(query, (auth_token)):

                connection.commit()

                user_task = cursor.fetchone()

                if cursor.execute(query, (complete_condition[1])):

                    connection.commit()

                    couple_task = cursor.fetchone()

                    report = dict()
                    report["photo1"] = user_task["img_path"]
                    report["photo2"] = couple_task["img_path"]

                    if user_task["answer"] == couple_task[
                            "standard"] and user_task[
                                "standard"] == couple_task["answer"]:

                        conclusion_type = 1

                        report['score'] = 100

                    else:

                        conclusion_type = 0

                        report['score'] = random.randint(70, 99)

                    query = "select * from conclusion where conclusion_type = %s"

                    cursor.execute(query, (conclusion_type))

                    get_conclusion = random.sample(cursor.fetchall(), 1)

                    report["document"] = get_conclusion[0]['conclusion_text']

                    connection.close()

                    return True, "获取报告成功", report

                else:

                    connection.close()

                    return False, "获取伴侣信息失败", "null"
            else:

                connection.close()

                return False, "获取用户信息失败", "null"
        else:

            connection.close()

            return False, "需要等待双方完成", "null"

    except:

        connection.close()

        return False, "无法连接数据库", "null"
Exemple #14
0
тнР <b>DAILY OFFER {date}</b> тнР
<u>{name}</u>

ЁЯЯа Extra discount:  {discount}%

<b>DISCOUNT CODE:</b> {code}

"""

# Carica configurazione locale
load_dotenv("./conf/.env")

# Collega prestashop
prestashop_token = get_env_panic("PRESTASHOP_TOKEN")
ps = service.connect(prestashop_token)

# Collega a telegram
telegram_token = get_env_panic("TELEGRAM_TOKEN")
updater = Updater(telegram_token, use_context=True)

# Aggiorna prestashop
product_data = service.get_random_product(ps)
service.update_category_product(ps, product_data)

# Invia ad entrambi i canali
image_token = get_env_panic("PRESTASHOP_IMAGE_TOKEN")
today = datetime.date.today()

channel_id = get_env_panic("TELEGRAM_CHANNEL_ITA")
print("[I] Sending message to " + channel_id)