-
Notifications
You must be signed in to change notification settings - Fork 0
/
hose.py
executable file
·41 lines (34 loc) · 1.14 KB
/
hose.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
#!/usr/bin/env python
from secrets import APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET
from entropy import InfoSize, numberToBase
from twython import TwythonStreamer
from time import sleep
import requests
import json
class MyStreamer(TwythonStreamer):
def on_success(self, data):
if 'text' in data:
text = data['text'].encode('utf-8')
# print(text)
s=InfoSize(text)
url="http://localhost:8080"
id=0
bits = numberToBase(s,2)
bits.reverse()
for bit in bits:
if bit==0:
cmd = [{'id':str(id),'target':0}]
else:
cmd = [{'id':str(id),'target':100}]
payload = {'data':json.dumps(cmd)}
# print(payload)
requests.post(url, data=payload)
id+=1
def on_error(self, status_code, data):
print(status_code)
print("Rate limited, sleeping for 600")
sleep(600)
stream = MyStreamer(APP_KEY, APP_SECRET,
OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
stream.statuses.filter(track='frequency')
#stream.user()