def __init__(self): try: self.Login() except: self.Logger("Login Error") else: self.draft = "" #Save the draft when refreshing interrupt self.db = QContactDB(self) self.log = "" #Log displaying at bottom self.exit = False self.current_contact = None
def QLogin(qq=None, user=None, conf=None): if not conf: conf = QConf(qq, user) conf.Display() if conf.qq: INFO('开始自动登录...') picklePath = conf.PicklePath() session = QSession() try: with open(picklePath, 'rb') as f: session.__dict__ = pickle.load(f) session.dbname = conf.absPath(session.dbbasename) except Exception as e: WARN('自动登录失败,原因:%s', e) else: INFO('成功从文件 "%s" 中恢复登录信息' % SYSTEMSTR2STR(picklePath)) try: session.TestLogin() except RequestError: WARN('自动登录失败,原因:上次保存的登录信息已过期') except Exception as e: WARN('自动登录失败,原因:%s', e) DEBUG('', exc_info=True) else: return session, QContactDB(session), conf if os.path.exists(session.dbname): try: os.remove(session.dbname) except OSError: pass except: WARN('', exc_info=True) INFO('开始手动登录...') session = QSession() session.Login(conf) picklePath = conf.PicklePath() try: with open(picklePath, 'wb') as f: pickle.dump((session.__dict__), f) except Exception as e: WARN('保存登录信息及联系人失败:%s %s', (e, SYSTEMSTR2STR(picklePath))) else: INFO('登录信息已保存至: %s' % SYSTEMSTR2STR(picklePath)) return session, QContactDB(session), conf
def QLogin(qq=None, user=None): conf = QConf(qq, user) conf.Display() if conf.qq: INFO('开始自动登录...') picklePath = conf.PicklePath() session = QSession() try: with open(picklePath, 'rb') as f: session.__dict__ = pickle.load(f) except Exception as e: WARN('自动登录失败,原因:%s', e) else: INFO('成功从文件 "%s" 中恢复登录信息' % picklePath) try: session.TestLogin() except RequestError: WARN('自动登录失败,原因:上次保存的登录信息已过期') except Exception as e: WARN('自动登录失败,原因:%s', e) DEBUG('', exc_info=True) else: return session, QContactDB(session), conf try: os.remove(session.dbname) except: pass INFO('开始手动登录...') session = QSession() session.Login(conf) picklePath = conf.PicklePath() try: with open(picklePath, 'wb') as f: pickle.dump((session.__dict__), f) except Exception as e: WARN('保存登录信息及联系人失败:%s %s', (e, picklePath)) else: INFO('登录信息已保存至文件:file://%s' % picklePath) return session, QContactDB(session), conf
def QLogin(qq=None, user=None): conf = QConf(qq, user) conf.Display() if conf.qq: INFO('开始自动登录...') picklePath = conf.PicklePath() session = QSession() contactdb = QContactDB(session) try: contactdb.Restore(picklePath) except Exception as e: WARN('自动登录失败,原因:%s', e) else: INFO('成功从文件 "%s" 中恢复登录信息' % picklePath) try: contactdb.session.TestLogin() except RequestError: WARN('自动登录失败,原因:上次保存的登录信息已过期') except Exception as e: WARN('自动登录失败,原因:%s', e) DEBUG('', exc_info=True) else: return contactdb.session.Copy(), contactdb, conf INFO('开始手动登录...') session = QSession() session.Login(conf) contactdb = QContactDB(session, conf.PicklePath()) contactdb.Dump() return session.Copy(), contactdb, conf
class Chat(BaseSession): def __init__(self): try: self.Login() except: self.Logger("Login Error") else: self.draft = "" #Save the draft when refreshing interrupt self.db = QContactDB(self) self.log = "" #Log displaying at bottom self.exit = False self.current_contact = None def main_session(self): #Init screen bi.close_iodisplay() sys.stdout.write('\x1b[3J\x1b[0m') while not self.exit: sys.stdout.write('\x1b[30;1H\x1b[7m'+' '*30+'\x1b[0m') sys.stdout.write('\x1b[31;1H\x1b[J') sys.stdout.write('\x1b[36;1H\x1b[46m\x1b[30m'+'a'*30+'\x1b[0m\x1b[31;1H') s = '' #bi.restore() c = sys.stdin.read(1) lastchar = '' m = '' while (c): s = '' if ord(c) not in range(128): s = c s += sys.stdin.read(2) sys.stdout.write(s) sys.stdout.flush() lastchar = s[-1] m += s elif c == "\n": break elif c=="/": """ commands: cd buddy Tony cd group class1 cd discuss banana-group quit """ sys.stdout.write('\x1b[36;1H') command = sys.stdin.readline() sys.stdout.write(command) commands = command.split(' ',2) if (commands[0] == "cd") and len(commands) == 3: if commands[1] in ['buddy','group','discuss']: if len(self.db.List(commands[1],commands[2])) <> 0: self.current_contact = self.db.List(commands[1],commands[2])[0] else: #print log:Not exist else: #log:Unknown type elif commands[0]=='quit': bi.restore() sys.exit() else: lastchar = c m += c sys.stdout.write(c) sys.stdout.flush() lastchar = c c = sys.stdin.read(1) # time.sleep(0.1) row = calculate(content) if (m): if self.current_contact <> None: self.SendTo(self.current_contact,m) # content.append(['User MJ',m]) #Check update result = self.poll() #analyze result #use new thread to sync message #if get new message if row > 28: sys.stdout.write('\x1b['+str(29)+';1H\x1b[7m'+content[-1][0]+'\n\x1b[0m\x1b[K'+content[-1][1]+'\x1b[K\x1b[0m\n'+'\x1b[K\x1b[0m\n'*7) else: sys.stdout.write('\x1b['+str(row)+';1H\x1b[7m'+content[-1][0]+'\n\x1b[0m'+content[-1][1]) time.sleep(0.1)