i just come out and take a bubble, haha \O^O/

This commit is contained in:
urinx
2017-04-16 21:55:51 +08:00
parent 504cc4f0f6
commit c1e702aafd
38 changed files with 3809 additions and 50 deletions
+47
View File
@@ -0,0 +1,47 @@
#!/usr/bin/env python
# coding: utf-8
#===================================================
from wechat.utils import *
from config import Constant
#---------------------------------------------------
import random, time, json
#===================================================
class Bot(object):
def __init__(self):
self.emoticons = Constant.EMOTICON
self.gifs = []
self.last_time = time.time()
def time_schedule(self):
r = ''
now = time.time()
if int(now - self.last_time) > 3600:
self.last_time = now
url_latest = Constant.BOT_ZHIHU_URL_LATEST
url_daily = Constant.BOT_ZHIHU_URL_DAILY
data = get(url_latest)
j = json.loads(data)
story = j['stories'][random.randint(0, len(j['stories'])-1)]
r = story['title'] + '\n' + url_daily + str(story['id'])
return r.encode('utf-8')
def reply(self, text):
APIKEY = Constant.BOT_TULING_API_KEY
api_url = Constant.BOT_TULING_API_URL % (APIKEY, text, '12345678')
r = json.loads(get(api_url))
if r.get('code') == 100000 and r.get('text') != Constant.BOT_TULING_BOT_REPLY:
p = random.randint(1, 10)
if p > 3:
return r['text']
elif p > 1:
# send emoji
if random.randint(1, 10) > 5:
n = random.randint(0, len(self.emoticons)-1)
m = random.randint(1, 3)
reply = self.emoticons[n].encode('utf-8') * m
return reply
return ''