-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestsql.py
40 lines (29 loc) · 1.28 KB
/
testsql.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Implement a simple python script using psycopg2 and argparse libraries.
# The script will display the movies from your database based on the user’s preferences.
# The user should be able to perform the following:
# Check whether the movie with specific name is among the top 250 movies.
# If so - display the release year of the movie and the imdb rating
# Display the user all the movies with imdb rating higher than the one provided by the user.
import pprint
import psycopg2
with psycopg2.connect(host="localhost",
port=5432,
database="imdb",
user="postgres",
password="danick92") as conn:
def find_movie(movie_name):
with conn.cursor() as cur:
sql = f"select movie_name , release_date , rating from imdb_top it where movie_name = {movie_name};"
cur.execute(sql)
result = cur.fetchone()
return result
def find_movies_by_rating(rate):
with conn.cursor() as cur:
sql = f"select movie_name, rating from imdb_top it where rating > {rate};"
cur.execute(sql)
result = cur.fetchall()
return result
res = find_movies_by_rating(8)
pprint.pprint(res)
res1 = find_movie("Spider")
print(res1)