-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparseData.py
38 lines (27 loc) · 1.3 KB
/
parseData.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
37
38
from sqlmodel import Session, create_engine, select
from Models.movies_model import Movie
from datetime import datetime, timezone
def first_play():
engine = create_engine("sqlite:///database.db")
movie_name = ''
earliest = datetime.now(tz=timezone.utc)
with Session(engine) as session:
movies = session.exec(select(Movie.title, Movie.watched_at)).all()
for movie in movies:
title, watched_ats = movie
for watched_at in watched_ats:
# watched_at = datetime.fromisoformat(watched_at)
watched_at = datetime.strptime(watched_at, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc)
if watched_at < earliest:
earliest = watched_at
movie_name = title
return movie_name, earliest
def oldest_play():
'''
I checked many users trakt all-time-stats, and first play were always a movie, now it could be that anyone is more likely to watch older movies rather than older show or trakt only shows a movie in first_play.
Therefore i have excluded episodes here.
'''
engine = create_engine("sqlite:///database.db")
with Session(engine) as session:
title = session.exec(select(Movie.title).order_by(Movie.released_year)).first()
return title