forked from xprojectind/xprj
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Poll.py
53 lines (42 loc) · 1.42 KB
/
Poll.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
import os, sys, time
path = os.path.join(os.path.dirname(__file__), '../lib/')
sys.path.insert(0, path)
from thrift.transport import THttpClient
from thrift.protocol import TCompactProtocol
from curve import LineService
from curve.ttypes import *
class Poll:
client = None
auth_query_path = "/api/v4/TalkService.do";
http_query_path = "/S4";
polling_path = "/P4";
host = "gd2.line.naver.jp";
port = 443;
UA = "Line/7.14.0"
LA = "IOSIPAD\t7.14.0\tiPhone OS\t10.12.0"
rev = 0
def __init__(self, authToken):
self.transport = THttpClient.THttpClient('https://gd2.line.naver.jp:443'+ self.http_query_path)
self.transport.setCustomHeaders({
"User-Agent" : self.UA,
"X-Line-Application" : self.LA,
"X-Line-Access": authToken
});
self.protocol = TCompactProtocol.TCompactProtocol(self.transport);
self.client = LineService.Client(self.protocol)
self.rev = self.client.getLastOpRevision()
self.transport.path = self.polling_path
self.transport.open()
def stream(self, sleep=50000):
#usleep = lambda x: time.sleep(x/1000000.0)
while True:
try:
Ops = self.client.fetchOps(self.rev, 5)
except EOFError:
raise Exception("It might be wrong revision\n" + str(self.rev))
for Op in Ops:
# print Op.type
if (Op.type != OpType.END_OF_OPERATION):
self.rev = max(self.rev, Op.revision)
return Op
#usleep(sleep)