Esempio n. 1
0
def create(tory):
    """
    Funckja tworzy nowy obiekt tory
    :param tory:
    :return:
    """
    nazwa = tory.get("nazwa")
    dlugosc = tory.get("dlugosc")
    numer = tory.get("numer")
    u_id = current_user.id
    print(nazwa, dlugosc, numer)
    cur.execute(
        "SELECT b.b_id FROM bocznica b WHERE b.nazwa = %s AND b.u_id = %s",
        (nazwa, u_id))
    b_id = cur.fetchone()[0]
    print(b_id)
    cur.execute(
        "SELECT EXISTS(SELECT 1 from tory t, bocznica b where t.numer = %s AND t.b_id = %s);",
        (numer, b_id))
    value = cur.fetchone()[0]
    print(value)

    if not value:
        cur.execute("INSERT INTO tory (b_id,dlugosc,numer) VALUES (%s,%s,%s);",
                    (b_id, dlugosc, numer))
        connection.commit()
        return "Added successfully", 201
    else:
        abort(406, "Bocznica o tej nazwie już istnieje")
Esempio n. 2
0
def read_one(nazwa):
    wagony = []
    cur.execute("SELECT sprawdz_czy_istnieje(%s)", (nazwa, ))
    value = cur.fetchone()[0]
    if value:
        cur.execute(
            "SELECT array_to_json((row_to_json(w))) FROM wagony_na_torze w WHERE numer_wagonu = %s;",
            (nazwa, ))
        results = cur.fetchone()
        for row in results:
            wagony.append(row)
        return results
    else:
        abort(404, "Wagon o tej nazwie nie znaleziony")
Esempio n. 3
0
    async def whitelist(self, ctx, *, content):
        """
        Allows A User To Whitelist Themselves On The Connected MC Server
        """
        await ctx.message.delete()
        # Return If There Is No Argument
        if content.strip == "":
            return
        # Get Users Database Entry
        cur.execute("select whitelist from user_data where discord_user_id = %s", (str(ctx.author.id),))
        is_present = cur.fetchone()

        if is_present is None:
            await global_functions.add_user_db_row(ctx.author)
        # Check If They Have Already Used The Command Or The User Is Not A Bot Admin
        if is_present is False and ctx.author.id != 451848182327148554:
            await ctx.send(embed=await global_functions.create_embed(title="fail",
                                                                     description=
                                                                     "You Already Have An Account Whitelisted\n"
                                                                     "If You Changed Your Account Name Or Got A New "
                                                                     "Account Please Contact A Staff Member.",),
                           delete_after=30)
            return
        # Else Add Them To The Whitelist And Update Database
        else:
            user_id = str(ctx.author.id)
            sql = "UPDATE user_data SET whitelist=false WHERE discord_user_id=%s"
            cur.execute(sql, (user_id,))
            DB_conn.commit()
            # MCClient.client.send_console_command(srv_id, "whitelist add " + content)
            await ctx.send(embed=await global_functions.create_embed(title="Success",
                                                                     description=
                                                                     "Minecraft User {} Has Been Added To The"
                                                                     " Whitelist".format(content)),
                           delete_after=30)
Esempio n. 4
0
def read_one(NIP):
    """
    Funckja odpowiada na request /api/firmy/{NIP} i zwraca pojedynczy rekord
    :return:
    """
    tory = []
    cur.execute("SELECT EXISTS(SELECT 1 from firmy where NIP = %s);", (NIP, ))
    value = cur.fetchone()[0]
    if value:
        cur.execute("SELECT wyswietl_firme(%s);", (NIP, ))
        results = cur.fetchone()
        for row in results:
            tory.append(row)
        return results
    else:
        abort(404, "Score in this day not found")
Esempio n. 5
0
def firma_wagonow(NIP):
    """
    Funckja aktualizuje f_id podanej firmy dla wszystkich wagonow posiadajacych taka sama nazwe firmy
    :param NIP:
    :return:
    """
    cur.execute("SELECT nazwa FROM firmy WHERE NIP = %s;", (NIP, ))
    nazwa_firmy = cur.fetchone()[0]
    print(nazwa_firmy)
    cur.execute("SELECT dodaj_firme_wagonow(%s,%s)", (NIP, nazwa_firmy))
    value = cur.fetchone()[0]
    print(value)
    connection.commit()
    if value:
        return "Firma dodana do wagonu", 201
    else:
        abort(404, "Firma o tym numerze nie znaleziona")
Esempio n. 6
0
def create(wagon):
    nazwa = wagon.get("nazwa")
    numer = wagon.get("numer")
    numer_wagonu = wagon.get("numer_wagonu")
    u_id = current_user.id

    cur.execute(
        "SELECT t.t_id FROM tory t LEFT JOIN bocznica b ON t.b_id = b.b_id WHERE t.numer = %s AND b.nazwa=%s AND b.u_id = %s;",
        (numer, nazwa, u_id))
    t_id = cur.fetchone()[0]
    cur.execute("SELECT sprawdz_czy_istnieje(%s)", (numer_wagonu, ))
    value = cur.fetchone()[0]
    if not value:
        cur.execute("SELECT nowy_wagon(%s,%s)", (t_id, numer_wagonu))
        connection.commit()
        return "Dodano pomyslnie", 201
    else:
        abort(406, "Wagon z tym numerem juz istnieje")
Esempio n. 7
0
def read_one(numer_wagonu):
    """
    This function responds to a request for /api/scores/{id}
    :return:
    """
    wagony = []
    cur.execute("SELECT sprawdz_czy_istnieje(%s)", (numer_wagonu, ))
    value = cur.fetchone()[0]
    if value:
        cur.execute(
            "SELECT array_to_json((row_to_json(w))) FROM wagony_na_torze w WHERE numer_wagonu = %s;",
            (numer_wagonu, ))
        results = cur.fetchone()
        for row in results:
            wagony.append(row)
        return results
    else:
        abort(404, "Wagon o tym numerze nie znaleziony")
Esempio n. 8
0
def update(nazwa, wagon_bazowy):
    cur.execute("SELECT EXISTS(SELECT 1 FROM wagony WHERE nazwa = %s);",
                (nazwa, ))
    value = cur.fetchone()[0]
    if value:
        nazwa_wagonu = wagon_bazowy.get("nazwa")
        cur.execute("UPDATE wagony SET nazwa = %S WHERE nazwa = %s)",
                    (nazwa, nazwa_wagonu))
    else:
        abort(406, "Wagon o tej nazwie nie istnieje")
Esempio n. 9
0
def delete(nazwa):
    cur.execute("SELECT EXISTS(SELECT 1 from wagony where nazwa = %s);",
                (nazwa, ))
    val = cur.fetchone()[0]
    if val:
        cur.execute("DELETE FROM wagony WHERE nazwa = %s CASCADE;", (nazwa, ))
        connection.commit()
        return "Deleted successfully", 201
    else:
        abort(404, "Wagon o tej nazwie nie znaleziona")
Esempio n. 10
0
def login_post():
    email = request.form.get('email')
    password = request.form.get('password')
    remember = True if request.form.get('remember') else False
    cur.execute(
        "SELECT EXISTS(SELECT 1 FROM uzytkownik where email_uzytkownika = %s AND haslo = %s);",
        (email, password))
    value = cur.fetchone()[0]
    if not value:
        flash('Bledy login lub haslo')
        return redirect(url_for('auth.login'))
    # login code goes here
    cur.execute(
        "SELECT u_id FROM uzytkownik WHERE email_uzytkownika = %s AND haslo = %s;",
        (email, password))
    user_id = cur.fetchone()[0]
    user = User(user_id)
    login_user(user, remember=remember)
    return redirect(url_for('home'))
Esempio n. 11
0
def read_one(t_id):
    """
    Funckja odpowiada na request /api/tory/{t_id}
    i zwraca jeden tor
    :return:
    """
    tory = []
    cur.execute("SELECT EXISTS(SELECT 1 from tory where t_id = %s);", (t_id, ))
    value = cur.fetchone()[0]
    if value:
        cur.execute(
            "SELECT array_to_json(array_agg(row_to_json(t))) FROM tory t WHERE t_id = %s;",
            (t_id, ))
        results = cur.fetchone()
        for row in results:
            tory.append(row)
        return results
    else:
        abort(404, "Tor o tym id nie znaleziony")
Esempio n. 12
0
 def __init__(self, id):
     cur.execute("SELECT EXISTS(SELECT 1 FROM uzytkownik where u_id = %s);",
                 (id,))
     user = cur.fetchone()[0]
     if user:
         self.id = id;
         cur.execute("SELECT email_uzytkownika FROM uzytkownik where u_id = %s;", (id,))
         email = cur.fetchone()[0]
         cur.execute("SELECT nazwa_uzytkownika FROM uzytkownik where u_id = %s;", (id,))
         name = cur.fetchone()[0]
         cur.execute("SELECT haslo FROM uzytkownik where u_id = %s;", (id,))
         password = cur.fetchone()[0]
         self.email = email
         self.name = name
         self.password = password
     else:
         self.id = 0
         self.email = ""
         self.name = ""
         self.password = ""
Esempio n. 13
0
def read_all():
    u_id = current_user.id
    wagony = []
    cur.execute(
        """SELECT (json_build_object('nazwa',b.nazwa,'numer',t.numer,'numer_wagonu',wt.numer_wagonu,'dlugosc',w.dlugosc,'czas_wjazdu',wt.czas_wjazdu,
        'czas_wyjazdu',wt.czas_wyjazdu,'czas_na_torze',wt.czas_na_torze,'opuscil_tor',wt.opuscil_tor)) FROM wagony_na_torze wt, tory t,bocznica b,wagony w WHERE
        wt.t_id=t.t_id AND wt.w_id = w.w_id AND t.b_id = b.b_id AND wt.opuscil_tor=FALSE AND u_id = %s;""",
        (u_id, ))
    results = cur.fetchone()
    for row in results:
        wagony.append(row)
    return results
Esempio n. 14
0
def read_all():
    """
    Funkcja odpowiada na request api/firmy i zwraca liste firm
    :return:        list firm w json
    """
    # Create the list of scores from our data
    tory = []
    cur.execute("SELECT * FROM wyswietl_firmy;")
    results = cur.fetchone()
    for row in results:
        tory.append(row)
    return results
Esempio n. 15
0
def zajetosc_toru(nazwa_bocznicy, numer_toru):
    """
    Funckja zwraca zajetosc podanego toru
    :param nazwa_bocznicy:
    :param numer_toru:
    :return:
    """
    u_id = current_user.id
    cur.execute("SELECT zajetosc_toru(%s,%s,%s);",
                (nazwa_bocznicy, numer_toru, u_id))
    zajetosc = cur.fetchone()[0]
    return zajetosc
Esempio n. 16
0
def read_all():
    """
    Funkcja odpowiada na request api/podsumowanie i zwraca liste
    firm ktore korzystaly z bocznicy uzytkownika czas ich wszystkich wagonow na torach
    oraz kwote jaka musza zaplacic
    :return:        podsumowanie json list
    """
    # Create the list of scores from our data
    u_id = current_user.id
    cur.execute("SELECT podsumowanie_torow(%s,%s);", (u_id, 4))
    results = cur.fetchone()
    return results
Esempio n. 17
0
def read_one(nazwa):
    """
    Ta funkcja odpoiwada na request /api/bocznica/{id}
    :return:
    """

    bocznica = []
    u_id = current_user.id
    cur.execute(
        "SELECT EXISTS(SELECT 1 from bocznica where nazwa = %s AND u_id = %s);",
        (nazwa, u_id))
    value = cur.fetchone()[0]
    if value:
        cur.execute(
            "SELECT (json_build_object('nazwa',b.nazwa)) FROM bocznica b WHERE nazwa = %s AND u_id=%s;",
            (nazwa, u_id))
        results = cur.fetchone()
        for row in results:
            bocznica.append(row)
        return results
    else:
        abort(404, "Bocznica o tej nazwie nie znaleziona")
Esempio n. 18
0
def opusc_tor(numer_wagonu):
    """
    Funkcja ustawia czas wyjazdu, czas pobytu i wartosc true dla
    pola opuscil_tor
    :param numer_wagonu:
    :return:
    """
    cur.execute("SELECT opusc_bocznice(%s)", (numer_wagonu, ))
    value = cur.fetchone()[0]
    connection.commit()
    if value:
        return "Wagon opuscil bocznice", 201
    else:
        abort(404, "Wagon o tym numerze nie znaleziony")
Esempio n. 19
0
def create(firmy):
    """
    Funkcja tworzy nowa firme na podstawie przekazanych danych
    :param firmy:
    :return:
    """
    nazwa = firmy.get("nazwa")
    telefon = firmy.get("telefon")
    NIP = firmy.get("NIP")
    email = firmy.get("email")
    adres = firmy.get("adres")
    miasto = firmy.get("miasto")
    kraj = firmy.get("kraj")
    kod_pocztowy = firmy.get("kod_pocztowy")
    print(nazwa, telefon, NIP, adres, miasto)
    cur.execute(
        "SELECT EXISTS(SELECT 1 from adres where adres = %s AND miasto = %s AND kraj= %s);",
        (adres, miasto, kraj))
    value = cur.fetchone()[0]
    cur.execute("SELECT EXISTS(SELECT 1 from firmy where NIP = %s);", (NIP, ))
    value1 = cur.fetchone()[0]
    if not value1:
        if not value:
            cur.execute(
                "INSERT INTO adres(adres,miasto,kraj,kod_pocztowy) VALUES (%s,%s,%s,%s);",
                (adres, miasto, kraj, kod_pocztowy))
        cur.execute(
            "SELECT adres_id from adres  where adres = %s AND miasto = %s AND kraj= %s",
            (adres, miasto, kraj))
        adres_id = cur.fetchone()[0]
        cur.execute(
            "INSERT INTO firmy(adres_id, nazwa, telefon, NIP, email) VALUES (%s,%s,%s,%s,%s);",
            (adres_id, nazwa, telefon, NIP, email))
        connection.commit()
        return "Dodano pomyslnie", 201
    else:
        abort(406, "Firma o tej nazwie już istnieje")
Esempio n. 20
0
def read_all():
    """
    Funckja odpowiada na request /api/tory
    i zwraca kompletna liste torow uzytkownika
    :return:        lista torow
    """
    # Create the list of scores from our data
    u_id = current_user.id
    tory = []
    cur.execute("SELECT wyswietl_tory(%s);", (u_id, ))
    results = cur.fetchone()
    for row in results:
        print(str(row)[1:-1])
        tory.append(row)
    return results
Esempio n. 21
0
def delete(NIP):
    """
    Funckja usuwa firme o podanym NIPie
    :param NIP:
    :return:
    """
    cur.execute("SELECT EXISTS(SELECT 1 from firmy where NIP = %s);", (NIP, ))
    print(NIP)
    value = cur.fetchone()[0]
    if value:
        cur.execute("DELETE FROM firmy WHERE NIP=%s;", (NIP, ))
        connection.commit()
        return "Usunieto pomyslnie", 201
    else:
        abort(404, "Firma o tym NIPie nie znaleziona")
Esempio n. 22
0
def firma_uzytkownika(NIP):
    """
    Funckja aktualizuje f_id podanej firmy do uzytkownika
    :param NIP:
    :return:
    """
    u_id = current_user.id
    cur.execute("SELECT dodaj_firme_uzytkownika(%s,%s)", (NIP, u_id))
    value = cur.fetchone()[0]
    print(value)
    connection.commit()
    if value:
        return "Firma dodana do uzytkownika", 201
    else:
        abort(404, "Firma o tym numerze nie znaleziona")
Esempio n. 23
0
def delete(numer_wagonu):
    """
    :param date:
    :return:
    """
    cur.execute(
        "SELECT EXISTS(SELECT 1 from wagony_na_torze where numer_wagonu = %s;",
        (numer_wagonu, ))
    val = cur.fetchone()[0]
    if val:
        cur.execute("DELETE FROM wagony_na_torze WHERE numer_wagonu = %s;",
                    (numer_wagonu))
        connection.commit()
        return "Deleted successfully", 201
    else:
        abort(404, "Bocznica o tej nazwie nie znaleziona")
Esempio n. 24
0
def signup_post():
    email = request.form.get('email')
    name = request.form.get('name')
    password = request.form.get('password')
    print(email)
    cur.execute(
        "SELECT EXISTS(SELECT 1 FROM uzytkownik where email_uzytkownika = %s);",
        (email, ))
    value = cur.fetchone()[0]
    if value:
        flash('Email address already exists')
        return redirect(url_for('auth.signup'))

    cur.execute(
        "INSERT INTO uzytkownik (email_uzytkownika,nazwa_uzytkownika,haslo) values (%s,%s,%s);",
        (email, name, password))
    connection.commit()
    return redirect(url_for('profile'))
Esempio n. 25
0
def delete(nazwa):
    """
    Funkcja usuwa bocznice o zadanej nazwie
    :param date:
    :return:
    """
    u_id = current_user.id
    cur.execute(
        "SELECT EXISTS(SELECT 1 from bocznica where nazwa = %s AND u_id = %s);",
        (nazwa, u_id))
    val = cur.fetchone()[0]
    if val:
        cur.execute("DELETE FROM bocznica WHERE nazwa = %s AND u_id= %s;",
                    (nazwa, u_id))
        connection.commit()
        return "Usunieto pomyslnie", 201
    else:
        abort(404, "Bocznica o tej nazwie nie znaleziona")
Esempio n. 26
0
def create(wagon_bazowy):
    nazwa = wagon_bazowy.get("nazwa")
    nr_startowy = wagon_bazowy.get("nr_startowy")
    nr_koncowy = wagon_bazowy.get("nr_koncowy")
    dlugosc = wagon_bazowy.get("dlugosc")
    wlasciciel = wagon_bazowy.get("wlasciciel")
    typ_wagonu = wagon_bazowy.get("typ_wagonu")

    cur.execute("SELECT EXISTS(SELECT 1 FROM wagony WHERE nazwa = %s);",
                (nazwa, ))
    value = cur.fetchone()[0]
    if not value:
        cur.execute(
            "insert into wagony (nazwa, nr_startowy, nr_koncowy, dlugosc, wlasciciel, typ_wagonu) values (%s,%s,%s,%s,%s,%s);",
            (nazwa, nr_startowy, nr_koncowy, dlugosc, wlasciciel, typ_wagonu))
        connection.commit()
        return "Dodano pomyslnie", 201
    else:
        abort(406, "Wagon z tym numerem juz istnieje")
Esempio n. 27
0
def read_all():
    """
    Funkcja odpowiada na request /api/bocznica
    i zwraca liste bocznic dla danego uzytkownika
    :return:        json list bocznica
    """
    # Create the list of scores from our data
    u_id = current_user.id
    print(u_id)
    bocznica = []
    cur.execute(
        "SELECT (json_build_object('nazwa',b.nazwa)) FROM bocznica b WHERE u_id=%s;",
        (u_id, ))
    results = cur.fetchone()
    print(results)
    if (results[0] == None):
        abort(404, "Nie masz aktualnie zadnych bocznic, dodaj je")
    for row in results:
        bocznica.append(row)
    return results
Esempio n. 28
0
 async def reaction_add_listener(self, payload):
     if payload.emoji.is_custom_emoji():
         emoji = payload.emoji.id
     else:
         emoji = payload.emoji
     sql = f"SELECT role_id " \
         f"FROM reaction_roles " \
         f"WHERE message_id='{payload.message_id}' and emoji_id='{emoji}'"
     cur.execute(sql, ())
     role = cur.fetchone()
     if role is not None:
         try:
             await payload.member.add_roles(discord.Object(int(role[0])),
                                            reason="Reaction Roles")
         except discord.Forbidden:
             try:
                 await payload.channel.send(
                     f"I Dont Have permission To Add Roles To {payload.member.name}"
                 )
             except discord.Forbidden:
                 pass
Esempio n. 29
0
def create(bocznica):
    """
    Funkcja tworzy nowa bocznice na podstawie przekazanych danych
    :param bocznica:
    :return:
    """
    nazwa = bocznica.get("nazwa")
    u_id = current_user.id
    print(nazwa)
    cur.execute(
        "SELECT EXISTS(SELECT 1 from bocznica where nazwa = %s AND u_id=%s);",
        (nazwa, u_id))
    value = cur.fetchone()[0]
    print(value)
    if not value:
        cur.execute("INSERT INTO bocznica (u_id,nazwa) VALUES (%s,%s);", (
            u_id,
            nazwa,
        ))
        connection.commit()
        return "Pomyslnie dodano", 201
    else:
        abort(406, "Bocznica o tej nazwie już istnieje")
Esempio n. 30
0
    async def reaction_remove_listener(self, payload):
        if payload.emoji.is_custom_emoji():
            emoji = payload.emoji.id
        else:
            emoji = payload.emoji

        sql = f"SELECT role_id " \
            f"FROM reaction_roles " \
            f"WHERE message_id='{payload.message_id}' and emoji_id='{emoji}'"
        cur.execute(sql, ())
        role = cur.fetchone()
        if role is not None:
            guild = discordClient.get_guild(payload.guild_id)
            member = guild.get_member(payload.user_id)
            try:
                await member.remove_roles(discord.Object(int(role[0])),
                                          reason="Reaction Roles")
            except discord.Forbidden:
                try:
                    await payload.send(
                        f"I Dont Have permission To Remove Roles From {payload.member.name}"
                    )
                except discord.Forbidden:
                    pass