Ejemplo n.º 1
0
def insert_tweet(parent_tweet_id, name, text, image_path, create_at):
    conn = con.mysql_connect()
    cursor = conn.cursor()

    if (parent_tweet_id is None and image_path is None):
        mySql_insert_query = """INSERT INTO tweet (name,text, create_at) VALUES ( '""" + \
            name+"""', '"""+text+"""', '"""+create_at+"""')"""

    elif (image_path is None):
        mySql_insert_query = """INSERT INTO tweet (parent_tweet_id, name,text, create_at) VALUES ( '""" + parent_tweet_id + """', '""" + name + """', '""" + text + """', '""" + create_at + """')"""

    elif (parent_tweet_id is None):
        mySql_insert_query = """INSERT INTO tweet (name,text, image_path, create_at) VALUES ( '""" + \
            name+"""', '"""+text+"""', '"""+image_path+"""', '"""+create_at+"""')"""

    else:
        mySql_insert_query = """INSERT INTO tweet (parent_tweet_id, name,text, image_path, create_at) VALUES ( '""" + \
            parent_tweet_id+"""','"""+name+"""', '"""+text + \
            """', '"""+image_path+"""','"""+create_at+"""')"""

    try:
        cursor.execute(mySql_insert_query)
        conn.commit()
        return "success"
    except:
        conn.rollback()
        return "failed"
Ejemplo n.º 2
0
def get_users():
    conn = con.mysql_connect()
    cursor = conn.cursor()

    fetch_user = """
  SELECT * FROM nf_users;
  """
    cursor.execute(fetch_user)
    result = cursor.fetchall()
    return result
Ejemplo n.º 3
0
def get_tweet():
    # fetchall tweet from database
    conn = con.mysql_connect()
    cursor = conn.cursor()

    fetch_tweet = """
  SELECT * FROM tweet;
  """
    cursor.execute(fetch_tweet)
    result = cursor.fetchall()
    return result
Ejemplo n.º 4
0
def get_reply_count(parent_tweet_id):
    #counting replies for every tweets
    conn = con.mysql_connect()
    cursor = conn.cursor()

    reply_count = """
  SELECT COUNT(*) FROM tweet
  WHERE parent_tweet_id = '""" + str(parent_tweet_id) + """'
  """

    cursor.execute(reply_count)
    result = cursor.fetchall()
    cursor.close()
    return result
Ejemplo n.º 5
0
def check_db(email):
    conn = con.mysql_connect()
    cursor = conn.cursor()

    fetch_user = """
  SELECT * FROM nf_users;
  """
    cursor.execute(fetch_user)
    result = cursor.fetchall()
    for r in result:
        if (r[2] == email):
            return "success"
        else:
            continue
Ejemplo n.º 6
0
def sign_in(email, password):
    conn = con.mysql_connect()
    cursor = conn.cursor()

    fetch_user = """
  SELECT * FROM nf_users;
  """
    cursor.execute(fetch_user)
    result = cursor.fetchall()
    for r in result:
        if (r[2] == email):
            if (r[3] == password):
                id = r[0]
                return id
        else:
            continue
Ejemplo n.º 7
0
def insert_movies(name, link, description, category_id, image_path):
    conn = con.mysql_connect()
    cursor = conn.cursor()

    mySql_insert_query = """INSERT INTO nf_movies (name, link, description, category_id, image_path) VALUES ( '"""+name+"""', '""" + \
        link+"""', '"""+description+"""','"""+category_id+ \
        """','"""+image_path+"""')"""

    try:
        cursor.execute(mySql_insert_query)
        conn.commit()
        return "success"
    except Exception as e:
        print(e)
        conn.rollback()
        return "failed"
    conn.close()
Ejemplo n.º 8
0
def insert_user(name, email, password, con_password):
    conn = con.mysql_connect()
    cursor = conn.cursor()

    if ("@" in email):
        if (password == con_password):
            mySql_insert_query = """INSERT INTO nf_users (name, email, password) VALUES ( '"""+name+"""', '""" + \
                email+"""', '"""+password+"""')"""

            try:
                cursor.execute(mySql_insert_query)
                conn.commit()

                get_id = """
        SELECT id FROM nf_users
        WHERE email = '""" + email + """'

        """
                cursor.execute(get_id)
                id = cursor.fetchall()
                return id
            except Exception as e:
                print(
                    '<script>window.alert("Your email has an account and jump to LOGIN page");</script>'
                )
                print(
                    '<script>window.location.replace("http://localhost/netflix_project/login.py");</script>'
                )
                print(e)
                conn.rollback()
                return "failed"
            conn.close()
        else:
            print(
                '<script>window.alert("Please type in password properly");</script>'
            )
            print(
                '<script>window.location.replace("http://localhost/netflix_project/signup.py");</script>'
            )
        return
    else:
        print(
            '<script>window.alert("Please type in proper email address");</script>'
        )
        return