Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions trakt/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import json
import logging
import os
from typing import NamedTuple
from urllib.parse import urljoin

import requests
import sys
import time
from collections import namedtuple
from functools import wraps
from requests_oauthlib import OAuth2Session
from datetime import datetime, timedelta, timezone
Expand Down Expand Up @@ -359,12 +359,34 @@ def init(*args, **kwargs):
return auth_method.get(AUTH_METHOD, PIN_AUTH)(*args, **kwargs)


Airs = namedtuple('Airs', ['day', 'time', 'timezone'])
Alias = namedtuple('Alias', ['title', 'country'])
Genre = namedtuple('Genre', ['name', 'slug'])
Comment = namedtuple('Comment', ['id', 'parent_id', 'created_at', 'comment',
'spoiler', 'review', 'replies', 'user',
'updated_at', 'likes', 'user_rating'])
class Airs(NamedTuple):
day: str
time: str
timezone: str


class Alias(NamedTuple):
title: str
country: str


class Genre(NamedTuple):
name: str
slug: str


class Comment(NamedTuple):
id: str
parent_id: str
created_at: str
comment: str
spoiler: str
review: str
replies: str
user: str
updated_at: str
likes: str
user_rating: str


def _validate_token(s):
Expand Down
20 changes: 15 additions & 5 deletions trakt/movies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Interfaces to all of the Movie objects offered by the Trakt.tv API"""
from collections import namedtuple
from typing import NamedTuple

from trakt.core import Alias, Comment, Genre, get, delete
from trakt.sync import (Scrobbler, comment, rate, add_to_history,
remove_from_history, add_to_watchlist,
Expand All @@ -15,8 +16,13 @@
'trending_movies', 'updated_movies', 'Release', 'Movie',
'Translation']

Translation = namedtuple('Translation', ['title', 'overview', 'tagline',
'language'])

# FIXME: same symbol in tv module
class Translation(NamedTuple):
title: str
overview: str
tagline: str
language: str


@delete
Expand Down Expand Up @@ -77,8 +83,12 @@ def updated_movies(timestamp=None):
yield to_ret


Release = namedtuple('Release', ['country', 'certification', 'release_date',
'note', 'release_type'])
class Release(NamedTuple):
country: str
certification: str
release_date: str
note: str
release_type: str


class Movie(object):
Expand Down
9 changes: 7 additions & 2 deletions trakt/tv.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# -*- coding: utf-8 -*-
"""Interfaces to all of the TV objects offered by the Trakt.tv API"""
from collections import namedtuple
from datetime import datetime, timedelta
from typing import NamedTuple

from trakt.core import Airs, Alias, Comment, Genre, delete, get
from trakt.errors import NotFoundException
from trakt.sync import (Scrobbler, rate, comment, add_to_collection,
Expand All @@ -19,7 +20,11 @@
'TVSeason', 'Translation']


Translation = namedtuple('Translation', ['title', 'overview', 'language'])
# FIXME: same symbol in movie module
class Translation(NamedTuple):
title: str
overview: str
language: str


@delete
Expand Down
33 changes: 24 additions & 9 deletions trakt/users.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
"""Interfaces to all of the User objects offered by the Trakt.tv API"""
from collections import namedtuple
from typing import NamedTuple

from trakt.core import get, post, delete
from trakt.movies import Movie
from trakt.people import Person
Expand All @@ -12,8 +13,10 @@
'get_user_settings', 'unfollow']


class Request(namedtuple('Request', ['id', 'requested_at', 'user'])):
__slots__ = ()
class Request(NamedTuple):
id: int
user: str
requested_at: str

@post
def approve(self):
Expand Down Expand Up @@ -60,12 +63,24 @@ def unfollow(user_name):
yield 'users/{username}/follow'.format(username=slugify(user_name))


class UserList(namedtuple('UserList', ['name', 'description', 'privacy',
'display_numbers', 'allow_comments',
'sort_by', 'sort_how', 'created_at',
'updated_at', 'item_count',
'comment_count', 'likes', 'trakt',
'slug', 'user', 'creator'])):
class UserList(NamedTuple):
name: str
description: str
privacy: str
display_numbers: str
allow_comments: str
sort_by: str
sort_how: str
created_at: str
updated_at: str
item_count: str
comment_count: str
likes: str
trakt: str
slug: str
user: str
creator: str

"""A list created by a Trakt.tv :class:`User`"""

def __init__(self, *args, **kwargs):
Expand Down