Exemplo n.º 1
0
def AddCategoryBlg():
    Urlbase = URLBASE
    username = CONFIG['TYPE_USER']['ROOT']
    connect = Model(username)
    req = request.get_json()
    result = {}
    name_category = req["name_category"]

    #id = None
    Insert_ofCategory = dict()
    Insert_ofCategory = {
        'TABLE': 'blg_category',
        'Col1': 'id',
        'Col2': 'name',
        'Val3': '%s',
        'Val4': '%s'
    }

    nombre_id = "id"
    nombre_tabla = "blg_category"
    id_max = connect.MAX_ID_TABLE(username, nombre_tabla, nombre_id)
    print(id_max[0]["max_id"])
    if id_max[0]["max_id"] == None:
        id_sig = "1"
    else:
        proximo_id = id_max[0]["max_id"] + 1
        id_sig = str(proximo_id)

    Data = [id_sig, name_category]
    ''' result["new_proveedor"] = name '''
    res_insert = connect.IT_TABLE(username, Insert_ofCategory, Data)
    result = {"hola": 2}

    return result
Exemplo n.º 2
0
def AddPostBlg():
    Urlbase = URLBASE
    username = CONFIG['TYPE_USER']['ROOT']
    connect = Model(username)
    req = request.get_json()
    result = {}
    id_category = req["id_category"]
    id_users = req["id_users"]
    title_post = req["title_post"]
    date_post = req["date_post"]

    #id = None
    Insert_ofPost = dict()
    Insert_ofPost = {
        'TABLE': 'post',
        'Col1': 'id',
        'Col2': 'title',
        'Col3': 'image',
        'Col4': 'created_at',
        'Col5': 'status',
        'Col6': 'user_id',
        'Col7': 'category_id',
        'Val8': '%s',
        'Val9': '%s',
        'Val10': '%s',
        'Val11': '%s',
        'Val12': '%s',
        'Val13': '%s',
        'Val14': '%s'
    }

    nombre_id = "id"
    nombre_tabla = "post"
    id_max = connect.MAX_ID_TABLE(username, nombre_tabla, nombre_id)
    print(id_max[0]["max_id"])
    if id_max[0]["max_id"] == None:
        id_sig = "1"
    else:
        proximo_id = id_max[0]["max_id"] + 1
        id_sig = str(proximo_id)

    img_name = "post" + id_sig + "user" + id_users + "catg" + id_category + ".jpg"
    status = "1"

    Data = [
        id_sig, title_post, img_name, date_post, status, id_users, id_category
    ]

    res_insert = connect.IT_TABLE(username, Insert_ofPost, Data)
    result = {"hola": 2}

    return result
Exemplo n.º 3
0
def sopa_letters():
    Urlbase = URLBASE
    username = CONFIG['TYPE_USER']['ROOT']
    connect = Model(username)
    #urlrev = URLBASE
    if request.method == "POST":
        id_topic = request.form['topic']
    else:
        id_topic = "1"

    print(id_topic)

    num_palabras = 0
    TSSTopico = {'TABLE': 'grupo', 'Col1': 'id', 'Col2': 'topico'}
    DatosTopico = connect.SSP_TABLE(username, TSSTopico)

    wid = id_topic
    TSSVocabulary = {
        'TABLE': 'vocabulary',
        'Col1': 'id',
        'Col2': 'english',
        'Col3': 'spanish',
        'Col4': 'grupo',
        'Col5': 'ejemplos',
        'Whe6': 'grupo=%s'
    }
    Data = (wid, )
    PalabrasCrucigrama = connect.SW_TABLE(username, TSSVocabulary, Data)
    list_palabras = []
    list_id = []
    Palabras_in_Crucigrama = []
    for items in PalabrasCrucigrama:
        list_id.append(items["id"])

    acierto = 0
    num_palabras = 0
    while num_palabras < 15:
        value_palabra = randint(0, len(list_id) - 1)
        palabra_select = PalabrasCrucigrama[value_palabra]["english"]
        palabra_select = re.sub(r"\s+", "", palabra_select, flags=re.UNICODE)
        num_letras = len(palabra_select)
        nueva_palabra = {}
        if acierto == 0 and num_letras > 10 and num_letras < 13:
            if palabra_select not in list_palabras:
                list_palabras.append(palabra_select)
                nueva_palabra["spanish"] = PalabrasCrucigrama[value_palabra][
                    "spanish"]
                nueva_palabra["english"] = palabra_select
                Palabras_in_Crucigrama.append(nueva_palabra)
                num_palabras += 1
                acierto = 1
        else:
            if palabra_select not in list_palabras:
                list_palabras.append(palabra_select)
                nueva_palabra["spanish"] = PalabrasCrucigrama[value_palabra][
                    "spanish"]
                nueva_palabra["english"] = palabra_select
                Palabras_in_Crucigrama.append(nueva_palabra)
                num_palabras += 1

    resultados_crucigrama = sopa_letras.llenar_palabra()
    result_crucigrama = resultados_crucigrama.generar_crucigrama(list_palabras)
    data = result_crucigrama[0]
    palabras = result_crucigrama[1]
    nombre_id = "id"
    nombre_tabla = "crucigrama"
    id_max = connect.MAX_ID_TABLE(username, nombre_tabla, nombre_id)
    proximo_id = id_max[0]["max_id"] + 1
    id = str(proximo_id)
    grupo = "1"
    Insert_ofCrucigrama = dict()
    Insert_ofCrucigrama = {
        'TABLE': 'crucigrama',
        'Col1': 'id',
        'Col2': 'grupo',
        'Col3': 'palabras',
        'Val4': '%s',
        'Val5': '%s',
        'Val6': '%s',
    }
    Data = [id, grupo, palabras]
    res_insert = connect.IT_TABLE(username, Insert_ofCrucigrama, Data)

    return render_template("/blog/sopa.html",
                           url=Urlbase,
                           data=data,
                           palabras_crucigrama=Palabras_in_Crucigrama,
                           id_crucigrama=proximo_id,
                           DatosTopico=DatosTopico)