Skip to content

Instantly share code, notes, and snippets.

@pavelanni
Created August 8, 2020 02:20
Show Gist options
  • Save pavelanni/0cd34ee8812bc1ce0cbfb9f4924ca719 to your computer and use it in GitHub Desktop.
Save pavelanni/0cd34ee8812bc1ce0cbfb9f4924ca719 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import sqlite3
if len(sys.argv) < 3:
print(f"Usage: {sys.argv[0]} <year_start> <year_end>")
sys.exit(1)
year_start = int(sys.argv[1])
year_end = int(sys.argv[2])
conn = sqlite3.connect('imdb.db')
c = conn.cursor()
years = [str(x) for x in range(year_start, year_end)]
for y in years:
c.execute(f"select avg(rating) as avg_rating from ratings inner join titles on titles.title_id=ratings.title_id where titles.premiered={y};")
print(f"Year: {y} Avg. rating: {c.fetchone()[0]:.2f}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment