-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathall.py
53 lines (39 loc) · 1.28 KB
/
all.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Unified Twitter data (merged from the archive and periodic updates)
"""
from collections.abc import Iterator
from ..core import Res
from ..core.source import import_source
from .common import Tweet, merge_tweets
# NOTE: you can comment out the sources you don't need
src_twint = import_source(module_name='my.twitter.twint')
src_archive = import_source(module_name='my.twitter.archive')
@src_twint
def _tweets_twint() -> Iterator[Res[Tweet]]:
from . import twint as src
return src.tweets()
@src_archive
def _tweets_archive() -> Iterator[Res[Tweet]]:
from . import archive as src
return src.tweets()
@src_twint
def _likes_twint() -> Iterator[Res[Tweet]]:
from . import twint as src
return src.likes()
@src_archive
def _likes_archive() -> Iterator[Res[Tweet]]:
from . import archive as src
return src.likes()
def tweets() -> Iterator[Res[Tweet]]:
# for tweets, archive data is higher quality
yield from merge_tweets(
_tweets_archive(),
_tweets_twint(),
)
def likes() -> Iterator[Res[Tweet]]:
# for likes, archive data barely has anything so twint is preferred
yield from merge_tweets(
_likes_twint(),
_likes_archive(),
)
# TODO maybe to avoid all the boilerplate above could use some sort of module Protocol?