-
Notifications
You must be signed in to change notification settings - Fork 2
/
ticker.py
96 lines (76 loc) · 2.62 KB
/
ticker.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
#################################################################
# Title: ticker.py
# Author: Sahaj Sarup
# Copyright (c) 2018 Linaro Limited
#################################################################
import tweepy
import requests
import time
import serial
ser = serial.Serial("/dev/tty96B0",9600)
ser.flushInput()
ytapikey = ' '
ytid = ' '
twuname = ' '
twconsumer_key = ' '
twconsumer_secret = ' '
twaccess_token = ' '
twaccess_token_secret = ' '
instaid = ' '
instaurl = 'https://instagram.com/web/search/topsearch/?query={' + instaid + '}'
yturl = 'https://www.googleapis.com/youtube/v3/channels?id=' + ytid + '&key=' + ytapikey + '&part=statistics&fields=items(statistics(subscriberCount))'
auth = tweepy.OAuthHandler(twconsumer_key,twconsumer_secret)
auth.set_access_token(twaccess_token,twaccess_token_secret)
api = tweepy.API(auth)
def update():
global instadat, ytjson, user
instadat = requests.get(instaurl).json()
ytjson = requests.get(yturl).json()
user = api.get_user(twuname)
def tw():
i = 0
count = float(user.followers_count)
if count < 1000:
out = '1s' + "{:4.0f}".format(count) + ' ' + 't'
elif count > 999 and count < 1000000:
out = '1s' + "{:4.0f}".format(count/1000) + 'K' + 't'
elif count > 999999 and count < 1000000000:
out = '1s' + "{:4.0f}".format(count/1000000) + 'M' + 't'
elif count > 999999999:
out = '1s' + "{:4.0f}".format(count/1000000000) + 'B' + 't'
print out
ser.write(out)
def insta():
count = float(instadat['users'][0]['user']['follower_count'])
if count < 1000:
out = '3s' + "{:4.0f}".format(count) + 't'
elif count > 999 and count < 1000000:
out = '3s' + "{:4.0f}".format(count/1000) + 'K' + 't'
elif count > 999999 and count < 1000000000:
out = '3s' + "{:4.0f}".format(count/1000000) + 'M' + 't'
elif count > 999999999:
out = '3s' + "{:4.0f}".format(count/1000000000) + 'B' + 't'
print out
ser.write(out)
def yt():
count = float(ytjson['items'][0]['statistics']['subscriberCount'])
if count < 1000:
out = '2s' + "{:4.0f}".format(count) + 't'
elif count > 999 and count < 1000000:
out = '2s' + "{:4.0f}".format(count/1000) + 'K' + 't'
elif count > 999999 and count < 1000000000:
out = '2s' + "{:4.0f}".format(count/1000000) + 'M' + 't'
elif count > 999999999:
out = '2s' + "{:4.0f}".format(count/1000000000) + 'B' + 't'
print out
ser.write(out)
if __name__ == '__main__':
time.sleep(15)
while True:
update()
tw()
time.sleep(10)
insta()
time.sleep(10)
yt()
time.sleep(10)