-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfanfou.py
55 lines (47 loc) · 1.54 KB
/
fanfou.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
#!/usr/bin/env python
#-*- coding=utf-8 -*-
from os.path import join, dirname, abspath, exists
import time
from lxml import etree
import logbook
import api
def directmsg():
xml = api.get('direct_messages/inbox')
if xml:
xml = etree.fromstring(xml)
num = len(xml)
if num > 0:
for i in range(num):
id = xml[i][0].text
msg = xml[i][1].text
if not msg:
continue
logbook.info(msg.encode("utf8"))
sendtext(msg.encode("utf8"))
code = api.post('direct_messages/destroy', id=id)
logbook.info("destory")
while code != 1:
code, xml = api.fanfou('direct_messages/destroy',{'id':id})
def sendtext(content):
xml = api.get('account/rate_limit_status')
xml = etree.fromstring(xml)
limit_num = xml[1].text
logbook.info(limit_num)
if int(limit_num) == 0:
return
code = api.post('statuses/update',status=content)
logbook.info(content)
logbook.info("sent!")
if __name__ == '__main__':
server_log_file = join(dirname(abspath(__file__)), "log/wechat.log")
if not exists(server_log_file):
open(server_log_file, "w").close()
local_log = logbook.FileHandler(server_log_file)
local_log.format_string = (
u'[{record.time:%H:%M:%S}] '
u'lineno:{record.lineno} '
u'{record.level_name}:{record.message}')
local_log.push_application()
while True:
directmsg()
time.sleep(10)