-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
executable file
·49 lines (37 loc) · 1.21 KB
/
script.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
import pyyoutube
from microdotphat import write_string, set_decimal, clear, show
import config as cfg
import math
import datetime
import time
# Calls the YouTube API and returns the subscribers count.
def get_subscribers():
api = pyyoutube.Api(api_key=cfg.API_KEY)
result = api.get_channel_info(channel_id=cfg.CHANNEL_ID)
channel_info = result.items[0]
subcount = channel_info.statistics.subscriberCount
return subcount
# Parses and formats the input to a safe number.
def safe_num(num):
if isinstance(num, str):
num = float(num)
return float('{:.3g}'.format(abs(num)))
# Formats the number.
def format_number(num):
num = safe_num(num)
sign = ''
metric = {'T': 1000000000000, 'B': 1000000000, 'M': 1000000, 'K': 1000, '': 1}
for index in metric:
num_check = num / metric[index]
if num_check >= 1:
num = num_check
sign = index
break
return f"{str(num).rstrip('0').rstrip('.')}{sign}"
while True:
clear()
sub_count = get_subscribers()
print(datetime.datetime.now().strftime("%H:%M:%S") + " Sub count: " + sub_count)
write_string(format_number(sub_count), kerning=False)
show()
time.sleep(30)