Esempio n. 1
0
def main():
    conn, cur = db_ops.open_db_conn()

    # For testing out the script (have to create a test table called testmovies)
    # sql_command = """
    #     INSERT INTO testmovies
    #     (title, tags)
    #     VALUES (?, ?)"""
    # cur.execute(sql_command, ('Title', 'Tag1, Tag2'))

    sql_command = """
        SELECT *
        FROM movies"""
    cur.execute(sql_command)
    table = cur.fetchall()

    sql_command = """
        UPDATE movies
        SET tags = ?
        WHERE title = ?"""

    for row in table:
        li = row[1].split(', ')
        li = str(li).strip('[]')
        print(li)
        cur.execute(sql_command, (li, row[0]))

    db_ops.close_db_conn(conn)
Esempio n. 2
0
    def get_recs(self):
        recs = {'netflix': {}, 'hulu': {}, 'amazon': {}, 'disney': {}}

        conn, cur = db_ops.open_db_conn()
        sql_command = """
            SELECT * FROM movies"""
        cur.execute(sql_command)
        movies = cur.fetchall()
        db_ops.close_db_conn(conn)

        for movie in movies:
            if movie in self.ratings:
                continue
            movie_score = 0
            title = movie[0]
            tags = movie[1].strip('][').split(', ')
            platforms = movie[2].strip('][').split(', ')

            for tag in tags:
                tag = tag.strip('\'')
                if tag in self.vector:
                    movie_score += self.vector[tag]
                else:
                    movie_score += 2.5

            for platform in platforms:
                # These strips shouldn't cause any issues, but be sure to check
                # them if any bugs arise
                platform = platform.strip('\r').strip(']\n').strip('\'')
                recs[platform][title] = movie_score

        return recs
Esempio n. 3
0
def main():
    with open('sample_movies.txt') as f:
        movies = [line.rstrip('\n') for line in f]

    for movie in movies:
        conn, cur = db_ops.open_db_conn()
        omdb_info = get_tags(movie)
        tags = omdb_info['Genre']

        utelly_info = get_availability(omdb_info['imdbID'])

        availability = []
        for location in utelly_info['collection']['locations']:
            availability.append(location['display_name'])
        availability = str(availability).strip('[]')

        sql_command = """
            SELECT *
            FROM movies
            WHERE title = ?"""
        cur.execute(sql_command, (movie,))

        if cur.fetchone() is None:
            sql_command = """
                INSERT INTO movies
                (title, tags, availability)
                VALUES (?, ?, ?)"""
            cur.execute(sql_command, (movie, tags, availability,))

        db_ops.close_db_conn(conn)
Esempio n. 4
0
    def select_all_movies():
        conn, cur = db_ops.open_db_conn()
        sql_command = """
            SELECT *
            FROM movies"""
        cur.execute(sql_command)

        rows = cur.fetchall()
        d = {}
        for r in rows:
            title = r[0]
            genre = r[1]
            platforms = r[2]

        return rows
Esempio n. 5
0
    def add_user_to_db(self):
        conn, cur = db_ops.open_db_conn()

        sql_command = """
            SELECT *
            FROM users
            WHERE login = ?"""
        cur.execute(sql_command, (self.login,))

        if cur.fetchone() is None:
            sql_command = """
                INSERT INTO users
                (login)
                VALUES (?)"""
            cur.execute(sql_command, (self.login,))

        db_ops.close_db_conn(conn)
Esempio n. 6
0
    def add_movie_to_db(self):
        conn, cur = db_ops.open_db_conn()

        sql_command = """
            SELECT *
            FROM movies
            WHERE title = ?"""
        cur.execute(sql_command, (self.title, ))

        if cur.fetchone() is None:
            sql_command = """
                INSERT INTO movies
                (title, tags, availability)
                VALUES (?, ?, ?)"""
            cur.execute(sql_command,
                        (self.title, repr(self.tags), repr(self.availability)))

        db_ops.close_db_conn(conn)