-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
66 lines (53 loc) · 1.81 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
import json
from pathlib import Path
import src.exceptions as exceptions
from src.constants import LayerConfig
from src.data_collection import collect_data
from src.image_creation import build_layer_config, create_image
# from src.encoding import encode_img_to_b64
class Config:
# Twitter username to scan
USERNAME = "AniketTeredesai"
# hex of the desired background color
BG_CLR = "#448dd9"
# (height, width)
BG_SIZE = (1000, 1000)
# layer config constants
# [[layer radius, number of users in the layer, gap size], ...]
LAYER_CONFIG: LayerConfig = [
[0, 1, 0],
[200, 8, 25],
[330, 15, 25],
[450, 26, 20],
]
# each page returns maximum of 200 tweets and likes
FAVORITES_PAGES_TO_FETCH = 1
TIMELINE_PAGES_TO_FETCH = 1
def main(debug: bool = False):
d = Path("res/circles_dump.json").resolve()
i = Path("res/circles.jpg").resolve()
p = Path("res/placeholder_avatar.png").resolve()
try:
if debug and d.exists():
q = Path("res/debug_avatar.jpg").resolve()
with open(d, "r") as f:
lc = json.load(f)
else:
q = None
ledger = collect_data(
Config.USERNAME,
Config.TIMELINE_PAGES_TO_FETCH,
Config.FAVORITES_PAGES_TO_FETCH,
Config.LAYER_CONFIG,
)
lc = build_layer_config(ledger, Config.LAYER_CONFIG)
with open(d, "w") as f:
json.dump(lc, f)
image = create_image(Config.BG_SIZE, Config.BG_CLR, lc, p, q)
image.save(i, "jpeg")
# data_str = encode_img_to_b64(image)
except (exceptions.InactiveUser, exceptions.InvalidUser, exceptions.ApiError) as e:
print(e)
if __name__ == "__main__":
# main(debug=True)
main()