|
| 1 | +import iso8601 |
| 2 | + |
| 3 | +import sqlalchemy as sa |
| 4 | +from models import Base, Series, Seasons, Episodes |
| 5 | + |
| 6 | + |
| 7 | +def to_days(date): |
| 8 | + timedelta = iso8601.parse_date(date) - iso8601.parse_date("1970-1-1") |
| 9 | + return timedelta.days |
| 10 | + |
| 11 | + |
| 12 | +def fill_series(conn): |
| 13 | + data = [ |
| 14 | + ( |
| 15 | + 1, |
| 16 | + "IT Crowd", |
| 17 | + "The IT Crowd is a British sitcom produced by Channel 4, written by Graham Linehan, produced by " |
| 18 | + "Ash Atalla and starring Chris O'Dowd, Richard Ayoade, Katherine Parkinson, and Matt Berry.", |
| 19 | + to_days("2006-02-03"), |
| 20 | + ), |
| 21 | + ( |
| 22 | + 2, |
| 23 | + "Silicon Valley", |
| 24 | + "Silicon Valley is an American comedy television series created by Mike Judge, John Altschuler and " |
| 25 | + "Dave Krinsky. The series focuses on five young men who founded a startup company in Silicon Valley.", |
| 26 | + to_days("2014-04-06"), |
| 27 | + ), |
| 28 | + ] |
| 29 | + conn.execute(sa.insert(Series).values(data)) |
| 30 | + |
| 31 | + |
| 32 | +def fill_seasons(conn): |
| 33 | + data = [ |
| 34 | + (1, 1, "Season 1", to_days("2006-02-03"), to_days("2006-03-03")), |
| 35 | + (1, 2, "Season 2", to_days("2007-08-24"), to_days("2007-09-28")), |
| 36 | + (1, 3, "Season 3", to_days("2008-11-21"), to_days("2008-12-26")), |
| 37 | + (1, 4, "Season 4", to_days("2010-06-25"), to_days("2010-07-30")), |
| 38 | + (2, 1, "Season 1", to_days("2014-04-06"), to_days("2014-06-01")), |
| 39 | + (2, 2, "Season 2", to_days("2015-04-12"), to_days("2015-06-14")), |
| 40 | + (2, 3, "Season 3", to_days("2016-04-24"), to_days("2016-06-26")), |
| 41 | + (2, 4, "Season 4", to_days("2017-04-23"), to_days("2017-06-25")), |
| 42 | + (2, 5, "Season 5", to_days("2018-03-25"), to_days("2018-05-13")), |
| 43 | + ] |
| 44 | + conn.execute(sa.insert(Seasons).values(data)) |
| 45 | + |
| 46 | + |
| 47 | +def fill_episodes(conn): |
| 48 | + data = [ |
| 49 | + (1, 1, 1, "Yesterday's Jam", to_days("2006-02-03")), |
| 50 | + (1, 1, 2, "Calamity Jen", to_days("2006-02-03")), |
| 51 | + (1, 1, 3, "Fifty-Fifty", to_days("2006-02-10")), |
| 52 | + (1, 1, 4, "The Red Door", to_days("2006-02-17")), |
| 53 | + (1, 1, 5, "The Haunting of Bill Crouse", to_days("2006-02-24")), |
| 54 | + (1, 1, 6, "Aunt Irma Visits", to_days("2006-03-03")), |
| 55 | + (1, 2, 1, "The Work Outing", to_days("2006-08-24")), |
| 56 | + (1, 2, 2, "Return of the Golden Child", to_days("2007-08-31")), |
| 57 | + (1, 2, 3, "Moss and the German", to_days("2007-09-07")), |
| 58 | + (1, 2, 4, "The Dinner Party", to_days("2007-09-14")), |
| 59 | + (1, 2, 5, "Smoke and Mirrors", to_days("2007-09-21")), |
| 60 | + (1, 2, 6, "Men Without Women", to_days("2007-09-28")), |
| 61 | + (1, 3, 1, "From Hell", to_days("2008-11-21")), |
| 62 | + (1, 3, 2, "Are We Not Men?", to_days("2008-11-28")), |
| 63 | + (1, 3, 3, "Tramps Like Us", to_days("2008-12-05")), |
| 64 | + (1, 3, 4, "The Speech", to_days("2008-12-12")), |
| 65 | + (1, 3, 5, "Friendface", to_days("2008-12-19")), |
| 66 | + (1, 3, 6, "Calendar Geeks", to_days("2008-12-26")), |
| 67 | + (1, 4, 1, "Jen The Fredo", to_days("2010-06-25")), |
| 68 | + (1, 4, 2, "The Final Countdown", to_days("2010-07-02")), |
| 69 | + (1, 4, 3, "Something Happened", to_days("2010-07-09")), |
| 70 | + (1, 4, 4, "Italian For Beginners", to_days("2010-07-16")), |
| 71 | + (1, 4, 5, "Bad Boys", to_days("2010-07-23")), |
| 72 | + (1, 4, 6, "Reynholm vs Reynholm", to_days("2010-07-30")), |
| 73 | + ] |
| 74 | + conn.execute(sa.insert(Episodes).values(data)) |
| 75 | + |
| 76 | + |
| 77 | +def fill_all_tables(conn): |
| 78 | + Base.metadata.drop_all(conn.engine) |
| 79 | + Base.metadata.create_all(conn.engine) |
| 80 | + |
| 81 | + fill_series(conn) |
| 82 | + fill_seasons(conn) |
| 83 | + fill_episodes(conn) |
0 commit comments