Skip to content

Repository

Models

models.api

Episode

Bases: BaseModel

Source code in src/models/api.py
31
32
class Episode(BaseModel):
    episode_id: int

episode_id: int class-attribute

Season

Bases: BaseModel

Source code in src/models/api.py
35
36
37
class Season(BaseModel):
    season: int
    show: Show

season: int class-attribute

show: Show class-attribute

Show

Bases: BaseModel

Source code in src/models/api.py
27
28
class Show(BaseModel):
    show_id: int

show_id: int class-attribute

TVTimeUser

Bases: BaseModel

Source code in src/models/api.py
22
23
24
class TVTimeUser(BaseModel):
    username: str
    password: str

password: str class-attribute

username: str class-attribute

UserDB

Bases: UserOut

Source code in src/models/api.py
18
19
class UserDB(UserOut):
    hashed_password: str

hashed_password: str class-attribute

UserIn

Bases: BaseModel

Source code in src/models/api.py
6
7
8
class UserIn(BaseModel):
    username: str
    password: str

password: str class-attribute

username: str class-attribute

UserOut

Bases: BaseModel

Source code in src/models/api.py
11
12
13
14
15
class UserOut(BaseModel):
    user_id: UUID
    username: str
    tv_time_username: str
    disabled: bool | None = None

disabled: bool | None = None class-attribute

tv_time_username: str class-attribute

user_id: UUID class-attribute

username: str class-attribute

models.data

TVTimeDataModel

Bases: JsonModel

Source code in src/models/data.py
 6
 7
 8
 9
10
11
12
13
14
15
class TVTimeDataModel(JsonModel):
    username: str = Field(index=True, primary_key=True)
    user_id: Optional[str]
    to_watch: Optional[dict]
    upcoming: Optional[dict]
    profile: Optional[dict]

    class Meta:  # pylint: disable=missing-class-docstring
        global_key_prefix = "tvtime"
        model_key_prefix = "data"

profile: Optional[dict] class-attribute

to_watch: Optional[dict] class-attribute

upcoming: Optional[dict] class-attribute

user_id: Optional[str] class-attribute

username: str = Field(index=True, primary_key=True) class-attribute

Meta

Source code in src/models/data.py
13
14
15
class Meta:  # pylint: disable=missing-class-docstring
    global_key_prefix = "tvtime"
    model_key_prefix = "data"
global_key_prefix = 'tvtime' class-attribute
model_key_prefix = 'data' class-attribute

Redis

repository.redis_repository

RedisOMClient

Source code in src/repository/redis_repository.py
 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
39
40
41
42
43
44
45
46
47
class RedisOMClient:
    def __init__(self) -> None:
        self.redis = get_redis_connection(url=REDIS_URL)
        TVTimeDataModel.Meta.database = self.redis
        # try:
        #     Migrator().run()
        # except MigrationError as e:
        #     logger.error(e)

    def exists(self, key):
        key = f"tvtime:data:{key}"
        return self.redis.exists(key)

    def get_ttl(self, key):
        key = f"tvtime:data:{key}"
        return self.redis.ttl(key)

    def get_tvtime_data(self, key):
        user = TVTimeDataModel.get(key)
        return user

    def get_tvtime_watch_next(self, key):
        data = TVTimeDataModel.get(key)
        if "Watch next" in data.to_watch:
            return data.to_watch["Watch next"]
        else:
            return {}

    def get_tvtime_not_watched_for_while(self, key):
        data = TVTimeDataModel.get(key)
        if "Not watched for a while" in data.to_watch:
            return data.to_watch["Not watched for a while"]
        else:
            return {}

    def get_tvtime_not_started_yet(self, key):
        data = TVTimeDataModel.get(key)
        if "Not started yet" in data.to_watch:
            return data.to_watch["Not started yet"]
        else:
            return {}

redis = get_redis_connection(url=REDIS_URL) instance-attribute

__init__()

Source code in src/repository/redis_repository.py
 8
 9
10
def __init__(self) -> None:
    self.redis = get_redis_connection(url=REDIS_URL)
    TVTimeDataModel.Meta.database = self.redis

exists(key)

Source code in src/repository/redis_repository.py
16
17
18
def exists(self, key):
    key = f"tvtime:data:{key}"
    return self.redis.exists(key)

get_ttl(key)

Source code in src/repository/redis_repository.py
20
21
22
def get_ttl(self, key):
    key = f"tvtime:data:{key}"
    return self.redis.ttl(key)

get_tvtime_data(key)

Source code in src/repository/redis_repository.py
24
25
26
def get_tvtime_data(self, key):
    user = TVTimeDataModel.get(key)
    return user

get_tvtime_not_started_yet(key)

Source code in src/repository/redis_repository.py
42
43
44
45
46
47
def get_tvtime_not_started_yet(self, key):
    data = TVTimeDataModel.get(key)
    if "Not started yet" in data.to_watch:
        return data.to_watch["Not started yet"]
    else:
        return {}

get_tvtime_not_watched_for_while(key)

Source code in src/repository/redis_repository.py
35
36
37
38
39
40
def get_tvtime_not_watched_for_while(self, key):
    data = TVTimeDataModel.get(key)
    if "Not watched for a while" in data.to_watch:
        return data.to_watch["Not watched for a while"]
    else:
        return {}

get_tvtime_watch_next(key)

Source code in src/repository/redis_repository.py
28
29
30
31
32
33
def get_tvtime_watch_next(self, key):
    data = TVTimeDataModel.get(key)
    if "Watch next" in data.to_watch:
        return data.to_watch["Watch next"]
    else:
        return {}

Celery

repository.celery_repository

celery = Celery(__name__) module-attribute

scrape_task(user)

Source code in src/repository/celery_repository.py
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
@celery.task(name="scrape_task")
def scrape_task(user: TVTimeUser):
    logger.info("Scraping Task Started")
    logger.debug(f"User: {user}")
    logger.debug(f"User: {user.username}")
    spider_process = CrawlerProcess(
        settings={
            "ITEM_PIPELINES": {
                "src.repository.spider.RedisWriterPipeline": 1,
            }
        }
    )
    input_args = {"user": user}
    spider_process.crawl(TVTimeSpider, **input_args)
    spider_process.start()
    try:
        TVTimeDataModel.get(user.username)
    except NotFoundError as exc:
        raise Exception("User not found") from exc