def station_validate(form, field): ''' 表单tostation和tostation验证函数 ''' r = RedisDB() if not r.getStation(field.data): raise ValidationError(u'木有这个站')
def insert_into_db(origin_user_id=None, kwai_Id=None): """ 初始化待抓取信息 :param origin_user_id:其实就是origin_user_id,快手给用户的id :param kwai_Id:连接中的id :return: """ m = Monitor() rdb = RedisDB() if kwai_Id is None: data = m.judge_is_alive(origin_user_id) else: page_source = m.get_uid(kwai_Id) origin_user_id = m.parse_uid_response(page_source) data = m.judge_is_alive(origin_user_id) if data is None: print("当前用户未开播") else: data = create_item(data) data['KWai_id'] = kwai_Id rdb.init_one_kol(unique_name="HASH_" + origin_user_id, key_value_dict=data)
if __name__ == "__main__": # data num_samplers = 2 batch_size = 256 epoch_size = int(1e2) * batch_size buffer_size = int(1e5) # runner settings, ~training gamma = 0.99 tau = 0.01 tau_period = 1 # in batches # optimization lr = 3e-4 db_server = RedisDB() # You can change game # env_name = "LunarLander-v2" env_name = "CartPole-v1" env = gym.make(env_name) replay_buffer = OffpolicyReplayBuffer( observation_space=env.observation_space, action_space=env.action_space, epoch_len=epoch_size, capacity=buffer_size, n_step=1, gamma=gamma, history_len=1, )
import traceback import tornado.web import tornado.ioloop from tornado import ioloop, gen from lxml import etree from utils import * from db import MongoDB from db import RedisDB from logger_helper import logger from wxpy import * logger = logging.getLogger('wxpyInterface') TURING_BOT = TuringBot() MONGO_OBJ = MongoDB() REDIS_OBJ = RedisDB() global bot @gen.coroutine def cur_wxpy_mode(): wxpy_mode = REDIS_OBJ.client.get('WXPY_MODE') logger.info('Current mode: %s' % wxpy_mode) bot.self.send_msg('Current mode: %s' % wxpy_mode) @gen.coroutine def register_task_reminder(): if get_wxpy_mode() != 'GAI': logger.info('Not GAI mode, pass the reminder') return
# 部分弹幕功能代码来自项目:https://github.com/IsoaSFlus/danmaku,感谢大佬 # 快手弹幕代码来源及思路:https://github.com/py-wuhao/ks_barrage,感谢大佬 import sys import os import base64 import asyncio import danmaku from db import RedisDB, MysqlClass r = RedisDB() """ # 编码 encode_str = base64.encodebytes(test_str.encode('utf8')) # b'aGVsbG8gd29ybGQh\n' print(encode_str.decode()) # 默认以utf8解码,结果 aGVsbG8gd29ybGQh # 解码 decode_str = base64.decodebytes(encode_str) # b'hello world!' print(decode_str.decode()) # 默认以utf8解码,结果 hello world! """ async def printer(q): """ 输出弹幕信息 :param q: 输出异步队列中 put 的弹幕 :return: """ while True: mdb = MysqlClass() m = await q.get()
def __init__(self): #self.mdb = MongoDB() self.rdb = RedisDB() self.duration = 2000