-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacc_db.py
111 lines (96 loc) · 3.06 KB
/
acc_db.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from lib.load_settings import load_settings, print_settings
from datetime import datetime
import requests
import time
from datetime import datetime, timezone, timedelta
from typing import Optional
# vars
SETTINGS = {}
PAGE_SIZE = 5
def get_page(cursor: Optional[str], desc_key: str, is_small: int):
global PAGE_SIZE, SETTINGS
response = requests.get(
f"{SETTINGS['DATA_SERVER_URL']}/urls",
params={
"cursor": cursor,
"page_size": PAGE_SIZE,
"desc_key": desc_key,
"is_small": is_small,
},
)
return response.json().get("urls", []), response.json().get("next_cursor", None)
def translate_local_time(gmt_time: str):
dt_gmt = datetime.strptime(gmt_time, "%a, %d %b %Y %H:%M:%S %Z")
dt_utc = dt_gmt.replace(tzinfo=timezone.utc)
local_offset = timedelta(seconds=-time.timezone)
if time.daylight:
local_offset = timedelta(seconds=-time.altzone)
local_timezone = timezone(local_offset)
dt_local = dt_utc.astimezone(local_timezone)
return dt_local.strftime("%Y-%m-%d %H:%M:%S")
def print_url(da):
print("*" * 20)
print(f"url: {da['url']}")
print(f"-- title: {da.get('title', '-')}")
print(f"-- artist_name: {da['artist_name']}")
print(f"-- follower_cnt: {da['follower_count']}")
print(f"-- sender_name: {da['sender_name']}")
print(f"-- timestamp: {translate_local_time(da['timestamp'])}")
def get_db_list(desc_key, is_small):
cur_cursor = None
while True:
new_page, cursor = get_page(cur_cursor, desc_key, is_small)
if len(new_page) == 0:
print("no page found")
break
for d in new_page:
print_url(d)
print()
input("enter to next page")
print("-" * 80)
cur_cursor = cursor
def get_random_private_url(is_small: int):
response = requests.get(
f"{SETTINGS['DATA_SERVER_URL']}/random_private_url",
params={
"is_small": is_small,
},
)
return response.json()
if __name__ == "__main__":
SETTINGS = load_settings()
print_settings(SETTINGS)
ans = input("(l)get_db_list, (r)get_random_private_url: ")
if ans == "l":
ans2 = input("sort by... (t)imestamp, (f)ollower_count: ")
desc_key = ""
if ans2 == "t":
desc_key = "timestamp"
elif ans2 == "f":
desc_key = "follower_count"
else:
print("huh?")
exit()
ans3 = input("artist size? (b)ig, (s)mall: ")
is_small = 0
if ans3 == "b":
is_small = 0
elif ans3 == "s":
is_small = 1
else:
print("huh?")
exit()
get_db_list(desc_key, is_small)
elif ans == "r":
ans2 = input("artist size? (b)ig, (s)mall: ")
is_small = 0
if ans2 == "b":
is_small = 0
elif ans2 == "s":
is_small = 1
else:
print("huh?")
exit()
print_url(get_random_private_url(is_small))
else:
print("huh?")