def new(path): c = Cache(path) try: f = max(c.query(Message), key=lambda x: x.id) return f except ValueError: return None
def _dispatch_servers(self, num): _host_db = Cache(HOST_DB) hs = [i.host for i in _host_db.query(Host)] c = 0 while 1: w = random.randint(0, len(hs)) yield hs.pop(w) c += 1 if c >= num: break if len(hs) == 0: break
def onQQMessage(bot, contact, member, content): # print(f"{contact} | {member.name} : {content}") m = MsgMan() print(colored(contact.name + "|" + member.name, 'green'), end='\r') msg_d = contact.__dict__ msg_d['sendUser'] = member.name msg_d['sendQq'] = member.uin msg_d['sendNick'] = member.nick msg_d['sendType'] = contact.ctype msg_d['sendContent'] = content msg = Msg(**msg_d) m.syncs_msg(msg) c = Cache(MSG_DB) ding_tk = list(c.query(Token, tp='ding'))[-1] if_send = False for k in c.query(Key): if k.text in content: if_send = True break if if_send: send_notification(msg, ding_tk.text)
def list(cls): c = Cache(conf['session-db']) return list(c.query(Book))
def StartWeRobot(): parser = ArgumentParser() parser.add_argument("-s", "--start", action="store_true", default=False, help="start server") parser.add_argument("-a", "--add-token", default=None, help="setting token") parser.add_argument("-I", "--initialization", action="store_true", default=False, help="initialization config") args = parser.parse_args() c = Cache(MSG_DB) if args.start: t = list(c.query(Token, tp='ding'))[-1] l = Loginer(t.text) itchat.auto_login(qrCallback=l, hotReload=True) itchat.run() elif args.add_token: t = Token(text=args.add_token, tp='ding') t.save(c) elif args.initialization: text = """[program:x-wechat] command=/usr/local/bin/Qwechat -s stdout_logfile= /var/log/x-wechat.log stderr_logfile= /var/log/x-wechat.err.log """ text3 = """[program:x-replayer] command=/usr/local/bin/Qserver -p 14144 stdout_logfile= /var/log/x-relayer.log stderr_logfile= /var/log/x-relayer.err.log """ text2 = """[unix_http_server] file=/tmp/supervisor.sock ; path to your socket file [supervisord] logfile=/var/log/supervisord/supervisord.log ; supervisord log file logfile_maxbytes=50MB ; maximum size of logfile before rotation logfile_backups=10 ; number of backed up logfiles loglevel=error ; info, debug, warn, trace pidfile=/var/run/supervisord.pid ; pidfile location nodaemon=false ; run supervisord as a daemon minfds=1024 ; number of startup file descriptors minprocs=200 ; number of process descriptors user=root ; default user childlogdir=/var/log/supervisord/ ; where child log files will live [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] [inet_http_server] port = 127.0.0.1:9001 [include] files = /root/.config/services/*.conf """ if not os.path.exists(os.path.expanduser("~/.config/services")): os.mkdir(os.path.expanduser("~/.config/services")) with open(os.path.expanduser("~/.config/services/x-wechat.conf"), 'w') as fp: fp.write(text) with open(os.path.expanduser("~/.config/services/x-relayer.conf"), 'w') as fp: fp.write(text3) with open(os.path.expanduser("~/.config/supervisor.conf"), 'w') as fp: fp.write(text2) print("-- init --- install ok") os.popen( "pip3 install -U git+https://github.com/Supervisor/supervisor.git 1>/dev/null 2>/dev/null;" ).read() os.popen("mkdir /var/log/supervisord/ ").read() os.popen("supervisord -c ~/.config/supervisor.conf").read() print("-- init --- start supervisor ok") os.popen("supervisorctl reread;supervisorctl update;").read() print("-- init --- start load procecers ok")