Passed
Push — develop ( b585db...289973 )
by Dean
03:02
created

Base.should_pull()   B

Complexity

Conditions 6

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 31.2848

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
ccs 1
cts 9
cp 0.1111
rs 8
cc 6
crap 31.2848
1 1
from plugin.sync.core.enums import SyncData, SyncMode
2 1
from plugin.sync.modes.core.base import Mode
3
4 1
from trakt_sync.cache.main import Cache
5
6
7 1
class Base(Mode):
0 ignored issues
show
Bug introduced by
The method run which was declared abstract in the super-class Mode
was not overridden.

Methods which raise NotImplementedError should be overridden in concrete child classes.

Loading history...
8 1
    mode = SyncMode.FastPull
9
10 1
    def iter_changes(self, media, pk):
11
        for key, result in self.trakt.changes:
12
            c_media, c_data = key[0:2]
13
14
            if c_media != media:
15
                # Ignore changes that aren't for `media`
16
                continue
17
18
            if c_data == SyncData.Watchlist:
19
                # Ignore watchlist data
20
                continue
21
22
            if not self.is_data_enabled(c_data):
23
                # Data type has been disabled
24
                continue
25
26
            data_name = Cache.Data.get(c_data)
27
28
            if data_name not in result.changes:
29
                # No changes for collection
30
                continue
31
32
            for c_action, items in result.changes[data_name].items():
33
                t_item = items.get(pk)
34
35
                if t_item is None:
36
                    # No item found in changes
37
                    continue
38
39
                yield c_data, c_action, t_item
40
41 1
    def should_pull(self, p_id, p_added_at):
42
        if not self.current.kwargs.get('pull'):
43
            return False
44
45
        pull = self.current.kwargs['pull']
46
47
        # Check `p_id` is inside the `ids` parameter
48
        if p_id in pull.get('ids', set()):
49
            return True
50
51
        # Check `p_added_at` timestamp is after the `created_since` parameter
52
        if p_added_at and pull.get('created_since') and p_added_at > pull['created_since']:
53
            return True
54
55
        return False
56