def handleCommand(update, context): msg = update.effective_message if not msg: return handleAdmin(msg) if not msg.text.startswith('/wb'): return command, text = splitCommand(msg.text) if 'unsub' in command: result = subscription.remove(msg.chat_id, text) try: scheduled_key.remove(result) except: ... elif 'sub' in command: result = subscription.add(msg.chat_id, text) scheduled_key.append(result) reply = msg.reply_text(subscription.get(msg.chat_id), parse_mode='markdown', disable_web_page_preview=True) if msg.chat_id < 0: tryDelete(msg) if 'sub' in command: commitRepo(delay_minute=0) if msg.chat_id < 0: autoDestroy(reply, 0.1)
def save(self): with open('db/subscription', 'w') as f: f.write( yaml.dump(self._db, sort_keys=True, indent=2, allow_unicode=True)) commitRepo(delay_minute=0)
def record(self, mlist, target): tid = str(target.id) for l in self.lists: if l == mlist: getattr(self, l).add(tid) else: getattr(self, l).discard(tid) self.saveFile(l) commitRepo()
def handleAdmin(msg, command, text): if not text: return success = False if command == '/abl': blocklist.add(text) success = True if success: autoDestroy(msg.reply_text('success'), 0.1) tryDelete(msg) commitRepo(delay_minute=0)
def process(root_url): mkdirs('other') note = Note(root_url) series = None for item in note.soup.find_all('div'): link = item.find('a') if link: if 'active' in item.text: processNote(link['href'], link.text, getDirName(series)) else: series = item.text.strip() or series commitRepo(delay_minute=0)
def loopImp(): removeOldFiles('tmp', day=0.1) sg.reset() db.reload() for keyword in db.keywords.items: print(keyword) content_id = urllib.request.pathname2url('100103type=1&q=' + keyword) url = 'https://m.weibo.cn/api/container/getIndex?containerid=%s&page_type=searchall' % content_id process(url) for user in db.users.items: print(user) url = 'https://m.weibo.cn/api/container/getIndex?type=uid&value=%s&containerid=107603%s' \ % (user, user) process(url) commitRepo(delay_minute=0) print('loop finished. commit in thread.')
def handleAdmin(msg): if msg.chat.username not in ['b4cxb', 'weibo_read', 'weibo_one']: return command, text = splitCommand(msg.text) if not text: return success = False if command == '/abl': blocklist.add(text) success = True if command == '/apl': popularlist.add(text) success = True if success: autoDestroy(msg.reply_text('success'), 0.1) tryDelete(msg) commitRepo(delay_minute=0)