This repository was archived by the owner on Jul 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfaker.py
More file actions
55 lines (43 loc) · 1.37 KB
/
faker.py
File metadata and controls
55 lines (43 loc) · 1.37 KB
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
#coding: utf-8
'''
faker
~~~~~
Acts like a human being, a server, a bot.
'''
import requests
import json
from server.base import db, logger
from server.models import User, Bot
bot = db.session.query(Bot).filter(Bot.type == 1).one()
qqbot = bot.weibot
user = db.session.query(User).filter(User.type == 1).all()[0]
user.attach_bot()
userbot = user.get_bot()
json_header = {'Content-Type': 'application/json'}
token = {'token': user.token}
def post_order(order):
order = '@%s %s' % (bot.name, order)
userbot.post.t__add(content=order)
logger.info('new order <%s> post' % order)
def fetch_job():
url = 'http://localhost:5000/arm/job'
payload = json.dumps(token)
resp = requests.get(url, data=payload, headers=json_header)
logger.info('got response <%d>' % resp.status_code)
if resp.status_code == 200:
logger.info('new job <%d %s> fetched' % (
resp.json['id'], resp.json['action']))
return resp.json
def report_job(job_id, report):
url = 'http://localhost:5000/arm/job/%d' % job_id
payload = token
token['report'] = {
'obj': 'tv',
'action': 'turnon',
'type': 0,
'status': report
}
payload = json.dumps(payload)
resp = requests.put(url, data=payload, headers=json_header)
logger.info('got response <%d>' % resp.status_code)
return resp