def update_ws(self, websocket, notify=True): if self.websocket: print(f"Closing old WS from {self.session_id}") if notify: add_task(websocket.send_json({"action": "MULTI_WS"})) add_task(self.websocket.close()) self.websocket = websocket
def __init__(self, game): self.game = game self.rounds = [] self.current_player = None self.current_team = None # Setting teams self.team_a_sessions = [] self.team_b_sessions = [] self.team_a_interception = 0 self.team_a_missed = 0 self.team_b_interception = 0 self.team_b_missed = 0 sessions = self.game.players_sessions for session in random.sample(sessions, len(sessions)): if len(self.team_a_sessions) > len(self.team_b_sessions): self.team_b_sessions.append(session) else: self.team_a_sessions.append(session) # Setting words with open("../utils/wordslist.txt", encoding="utf-8") as f: choosen_words = f.read().splitlines() choosen_words = random.sample(choosen_words, 8) self.team_a_words = choosen_words[0:4] self.team_b_words = choosen_words[4:8] # Notify everyone for session in self.game.players_sessions: session.notify({ "status": self.get_status(session), "action": "GAME_START", }) # Go ! add_task(self.work())
def main(): cfg = ConfigParser.ConfigParser() cfg.read('/data/config/morgan/morgan_spider_common_settings.cfg') entrence_list = get_entrence() logger.info('获取到 %s 个' % (len(entrence_list))) for item in entrence_list: data = { 'traceID': str(uuid.uuid1()), 'callSystemID': 'morgan-chinahr-jd-1', 'taskType': 'JD_FETCH', 'source': 'CH_HR', 'executeParam': json.dumps( { "funName": item[2], "cityCode": item[1], "cityName": item[0], "keyword": item[2] }, ensure_ascii=False) } utils.add_task(data=data)
def main(): cfg = ConfigParser.ConfigParser() cfg.read('/data/config/morgan/morgan_spider_common_settings.cfg') entrence_list = get_entrence() logger.info('获取到 %s 个' % (len(entrence_list))) for item in entrence_list: data = { 'traceID': str(uuid.uuid1()), 'callSystemID': 'morgan-ganji-jd-1', 'taskType': 'JD_FETCH', 'source': 'GJ_HR', 'executeParam': json.dumps( { 'cityUrl': item[1], 'cityName': item[0], 'funcUrl': item[3], 'funcName': item[2], 'pageNum': 1, }, ensure_ascii=False) } utils.add_task(data=data)
def create_task(): function_data = load_function() # account_data = load_account() # acc_index = 0 if function_data: for x in range(len(function_data)): func = function_data[x] func_code = func[0] func_name = func[1] city_code = '530' city_name = '北京' data = { 'source': "ZHI_LIAN", 'pageNum': 0, 'funcName': func_name.decode('utf8'), 'funcCode': func_code, 'cityCode': city_code, 'cityName': city_name } utils.add_task({ 'callSystemID': settings.project_settings['CALLSYSTEMID'], 'taskType': 'RESUME_FETCH', 'source': "ZHI_LIAN", 'executeParam': json.dumps(data, ensure_ascii=False) }) logger.info('add task success') else: logger.error('there are no functions or accounts found')
def create_task(): for user_name in settings.account_list: deadline = int(time.time() - (time.time() % 86400) + time.timezone + 24 * 60 * 60) * 1000 data = { 'traceID': str(uuid.uuid1()), 'callSystemID': 'morgan-51job-inbox-1', 'taskType': 'RESUME_INBOX', 'source': 'FIVE_ONE', 'executeParam': user_name, 'deadline': deadline } utils.add_task(data)
def create_task(): # 从指定文件读取任务列表 发送至调度 params = open('task_list').readlines() for param in params: deadline = datetime.datetime.now() + datetime.timedelta(hours=6) deadline = int(time.mktime(deadline.timetuple())) * 1000 data = { 'traceID': str(uuid.uuid1()), 'callSystemID': 'morgan-51job-arouse-1', 'taskType': 'RESUME_FETCH', 'source': 'FIVE_ONE', 'executeParam': param, 'deadline': deadline } utils.add_task(data)
def main(): cfg = ConfigParser.ConfigParser() cfg.read('/data/config/morgan/morgan_spider_common_settings.cfg') entrence_list = get_entrence() logger.info('获取到 %s 个' % (len(entrence_list))) for item in entrence_list: condition = SearchCondition(item[0], item[1], item[2], item[3], item[4]) execute_param = json.dumps(condition.to_dics(), ensure_ascii=False) data = { 'traceID': str(uuid.uuid1()), 'callSystemID': 'morgan-58-jd-1', 'taskType': 'JD_FETCH', 'source': 'FIVE_EIGHT', 'executeParam': execute_param } utils.add_task(data=data)
def index(request): if request.method=='POST': if verify_source(request.GET): #检查请求来源是否合法 x_dict=convert_xml_to_dict(request) from_username=x_dict['FromUserName'] content=x_dict['Content'].strip() if content != '1': #发送来的内容不是'1'(‘1’请求下一页),即为查询关键字 kv.delete(from_username) #remove kv user_dict rt,total_nums,current_page,total_page=query_library(content,'title','1') sub_rt=rt[0:9] #display 9 items on weixin len_sub_rt=len(sub_rt) if len_sub_rt == 9: #图书子结果是否等于9 if len(rt) > 9: #如果查询图书结果大于9条,则保存 user_dict={'rt':rt, 'next':9, 'current_page':current_page, 'total_page':total_page, 'total_nums':total_nums, 'key_word':content } kv.set(from_username,user_dict) #save article_count='10' title=u'查询关键字:%s 结果数:%s' %(content,total_nums) elif 0<len_sub_rt<9: #图书结果大于0,小于9 article_count=len_sub_rt+2 title=u'查询关键字:%s 结果数:%s' %(content,total_nums) else: #无图书查询结果 article_count='1' title=u'查询关键字:%s 结果数:%s' %(content,total_nums) description=u'没有您要检索的馆藏书目!' else: #查询下一页 user_dict=kv.get(from_username) if user_dict: _next=user_dict['next'] sub_rt=user_dict['rt'][_next:_next+9] user_dict['next']+=9 kv.replace(from_username,user_dict) len_sub_rt=len(sub_rt) if len_sub_rt == 9: #the number of response items about books is 45 article_count='10' title=u'查询关键字:%s 结果数:%s' %(user_dict['key_word'],user_dict['total_nums']) if sub_rt[-1] == user_dict['rt'][-1]: #when go to the end index if user_dict['current_page'] != user_dict['total_page']: add_task(user_dict,'/task/',from_username) # add task to sae queue to fetch next page else: kv.delete(from_username) #if go to the end page delete user_dict, else: article_count=len_sub_rt+2 title=u'查询关键字:%s 结果数:%s' %(user_dict['key_word'],user_dict['total_nums']) sub_rt=user_dict['rt'][_next:] kv.delete(from_username) #remove kv user_dict else: article_count='1' title=u'没有更多的数据或查询下一页已过期' #return 'no more data'or'query outdate' create_time=str(int(time())) t=template.loader.get_template('news_response.xml') c=template.Context(locals()) xml=t.render(c) return HttpResponse(xml,content_type='application/xml') else: return HttpResponse('False') else: return HttpResponse('False')
def notify_status(self): add_task( self.websocket.send_json({ "action": "STATUS", "status": self.get_status() }))
def notify(self, message): if self.websocket: print(f"Notifying {self.session_id}") add_task(self.websocket.send_json(message)) else: print(f"Can't notify {self.session_id}")