def open_QR(id): for get_count in range(10): output_info('Getting uuid') uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid() time.sleep(1) output_info('Getting QR Code') if itchat.get_QR(uuid, picDir='images/%s.png' % id): break elif get_count >= 9: output_info('Failed to get QR Code, please restart the program') sys.exit() output_info('Please scan the QR Code') return uuid # uuid = open_QR() # waitForConfirm = False # while 1: # status = itchat.check_login(uuid) # if status == '200': # break # elif status == '201': # if waitForConfirm: # output_info('Please press confirm') # waitForConfirm = True # elif status == '408': # output_info('Reloading QR Code') # uuid = open_QR() # waitForConfirm = False
def open_qr(self): for get_count in range(1): self.outputWritten('获取uuid中…… ') uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid() time.sleep(1) self.outputWritten('成功获取uuid ') if itchat.get_QR(uuid, picDir=r'%s' % os.path.join(current_path, 'qrcode.jpg')): break elif get_count >= 1: self.outputWritten("获取二维码出错,请重启程序 ") sys.exit() return uuid
def getUUID(): uuid = itchat.get_QRuuid() for count in xrange(10): if uuid is None: LogCat("UUID is none,try again....", tag="INFO:") uuid = itchat.get_QRuuid() else: break return uuid
def open_QR(self): self.output_info('Getting uuid') uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid() time.sleep(1) self.output_info('Getting QR Code') qrCode = QRCode('https://login.weixin.qq.com/l/' + uuid) qrCode.png("QR.png", scale=10) self.programSignal.getting_QR.emit() return uuid
def get_code(): """ 获取UUID :return: """ uuid = itchat.get_QRuuid() if not uuid: uuid = itchat.get_QRuuid() time.sleep(2) code = itchat.get_QR(uuid) return code, uuid
def open_QR(): for get_count in range(10): output_info('Getting uuid') uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid();time.sleep(1) output_info('Getting QR Code') if itchat.get_QR(uuid): break elif get_count >= 9: output_info('Failed to get QR Code, please restart the program') sys.exit() output_info('Please scan the QR Code') return uuid
def open_QR(): for get_count in range(10): output_info("正在获取 uuid") uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid() time.sleep(1) if itchat.get_QR(uuid, enableCmdQR=True): break elif get_count >= 9: output_info("获取二维码信息失败 请重新运行程序") sys.exit() output_info("请扫描二维码") return uuid
def open_QR(): for get_count in range(10): output_info("getting uuid") uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid() time.sleep(1) output_info("getting QR CODE") if itchat.get_QR(uuid): break elif get_count >= 9: output_info("Failed to get QR Code ,restart the program") sys.exit() output_info("Please scan the QR Code") return uuid
def open_QR(): global uuid for get_count in range(15): output_info('Getting uuid') uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid() time.sleep(1) output_info('Getting QR code') if itchat.get_QR(uuid): break elif get_count >= 9: output_info('没有正常获取二维码,请刷新页面') return uuid output_info('请扫描二维码')
def open_QR(self): for get_count in range(10): log.info('Getting uuid of QR code') uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid() time.sleep(1) log.info('Getting QR Code') if self.get_QR(uuid): break elif get_count >= 9: log.error('Failed to get QR Code, please restart the program') sys.exit() log.info('Please scan the QR Code to login') return uuid
def open_qr(self): print('Getting uuid') uuid = itchat.get_QRuuid() self.uuid = uuid while uuid is None: uuid = itchat.get_QRuuid() time.sleep(1) print('Getting QR Code') qrStorage = io.BytesIO() qrCode = QRCode('https://login.weixin.qq.com/l/' + uuid) qrCode.png(qrStorage, scale=6) with open(self.picDir, 'wb') as f: f.write(qrStorage.getvalue()) print('Please scan the QR Code') return uuid
def hello_world(): # return 'Hello World!' # itchat.login(enableCmdQR=2,hotReload=True,picDir='C:\\Users\laomingming\Pictures\\'+'qr.png') # img = itchat.login(hotReload=True) # shutil.copy(os.getcwd() + '/' + 'QR.png', '/home/mysite/static/QR.png') # byte_io = BytesIO() # img.save(byte_io, 'PNG') # byte_io.seek(0) path = 'C:\\Users\\laomingming\\Pictures\\' os.chdir(path) os.getcwd() a = itchat.get_QRuuid() byte_io = itchat.get_QR(a) # byte_io = BytesIO() # img.save(byte_io, 'PNG') # byte_io.seek(0) # b.seek(0) # b = obj.seek(0) print(type(byte_io)) # byte_io = BytesIO() # obj.save(byte_io, 'PNG') b = byte_io.seek(0) print(type(b)) return send_file(byte_io, mimetype='image/png')
def open_QR(): for get_count in range(10): output_info("Getting uuid") uuit = itchat.get_QRuuid() while uuid is None: uuitd = itchat.get_QRuuid(); time.sleep(1) output_info("Getting QR code") if itchat.get_QR(uuid): break elif get_coun >= 9: output_info("Failed to get QR code, plz restart the program") sys.exit() output_info("Plz scan the QE Code") return uuid
def login_weixin(request): uuid = itchat.get_QRuuid() qrStorage = itchat.get_QR(uuid) # t = time.strftime("%Y%m%d %H%M%S") # response = HttpResponse(qrStorage.getvalue()) # response['Content-Type'] = 'image/png' # response['Content-Disposition'] = 'attachment;filename="QR_%s.png"' % t return HttpResponse(itchat.log)
def main(): global uuid itchat.auto_login(hotReload=True) uuid = itchat.get_QRuuid() timer = threading.Timer(1, Timer_Fun) timer.start() time.sleep(100 * 1) timer.cancel()
def open_QR(): while True: uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid() time.sleep(1) code_img = itchat.get_QR(uuid) print(code_img) if code_img: # add_wx = Wx() # add_wx.code = 1 # add_wx.code_img = code_img # add_wx.save() break time.sleep(1200) output_info('Please scan the QR Code') return uuid
def open_qr(com_queue=None): for get_count in range(10): print ('Getting uuid') uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid(); time.sleep(1) print ('Getting QR Code') if itchat.get_QR(uuid, enableCmdQR=True, qrCallback=qrcode_handle): break elif get_count >= 9: print ('Failed to get QR Code, please restart the program') sys.exit() print ('Please scan the QR Code') # todo 更新手机显示 if com_queue: com_queue.put({"mode": 1}) return uuid
def get_qrcode(userId): # try: userInfo = User.find_user_by_id(userId=userId) if userInfo: qrcodeUrl = 'https://login.weixin.qq.com/l/' + itchat.get_QRuuid() return qrcodeUrl else: response.status = 401 return 'Unauthorized'
def open_QR(): for get_count in range(10): print('Getting uuid') uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid() time.sleep(1) print('Getting QR Code') try: if itchat.get_QR(uuid): break elif get_count >= 9: print('Failed to get QR Code, please restart the program') sys.exit() except ZeroDivisionError: print 'div 0 error' print('Please scan the QR Code. uuid = ' + str(uuid)) return uuid
def _entry(self, current_user, app): print(self.isLoggedIn, 'self is loggedin') if not self.isLoggedIn: load_status = self.itchat.load_login_status( 'data/itchat{}.pk1'.format(current_user.get_id())) print('threadalive1:', threading.active_count()) print(self.thread.is_alive()) print(self.qr_img, 'qr_img') print(load_status) if load_status.get('BaseResponse').get('Ret') == 0: self.isLoggedIn = True self.thread = Thread(target=self.readygo) self.thread.start() self.itchat.dump_login_status('data/itchat{}.pk1'.format( current_user.get_id())) print('threadalive2:', threading.active_count()) return None uuid = itchat.get_QRuuid() itchat.get_QR(uuid=uuid, qrCallback=_qrtrans) if self.thread.is_alive() and self.qr_img != 0: return self.qr_img if not self.thread.is_alive(): print('please Login') self.thread = Thread(target=self.monitor_login) self.thread.start() return self.qr_img # 已经登陆微信 if self.isLoggedIn: # wechat 掉线或者登出 if not self.thread.is_alive(): print('threadalive3:', self.thread.is_alive()) self.isLoggedIn = False uuid = itchat.get_QRuuid() itchat.get_QR(uuid=uuid, qrCallback=_qrtrans) self.thread = Thread(target=self.monitor_login) self.thread.start() return self.qr_img return None
def open_QR(): num=input("请输入今天签到的人数") try: num=int(num) except Exception as e: num=1 for get_count in range(num): output_info('Getting uuid') uuid = itchat.get_QRuuid() while uuid is None: uuid = itchat.get_QRuuid() time.sleep(10) output_info('Getting QR Code') if itchat.get_QR(uuid): break elif get_count >= num: output_info('获取二维码出错,请重启程序') sys.exit() output_info('请重新扫二维码') return uuid
def api_wechat_login(): global thread uuid = itchat.get_QRuuid() itchat.get_QR(uuid=uuid, qrCallback=QR_to_b64) print(thread.is_alive()) if thread.is_alive(): return jsonify({'success': 0, 'msg': '已有登陆线程存在' }) # thread = task(monitor_login,itchat) thread = Thread(target = monitor_login, args = (itchat, )) thread.start() return jsonify({'success': 1, 'qr': qr_b64.decode("utf-8") })
def get_qr(): if not test_connect(): logger.info( "You can't get access to internet or wechat domain, so exit.") return None global qruuid qruuid = itchat.get_QRuuid() itchat.uuid = qruuid if os.path.exists(qrCode_dir): os.remove(qrCode_dir) itchat.get_QR(uuid=qruuid, picDir=qrCode_dir, qrCallback=qr_callback) return qruuid
def login(): # pic = request.headers.get('Host') picname = 'weixin' qr_path = f'./weixinapp/static/weixin/QRcode/{picname}.png' uuid = itchat.get_QRuuid() # print(f'24{uuid}') qrStorage = itchat.get_QR(uuid=uuid, enableCmdQR=True) with open(qr_path, 'wb') as f: f.write(qrStorage.getvalue()) # print(f'28{uuid}') return render_template('weixin/login.html', uuid=uuid, qr=picname, note='请使用微信扫描二维码进行登陆!')
def getUuid(uuidPath): for i in range(10): output_info('Getting uuid %d' % i) uuid = itchat.get_QRuuid() if uuid is not None: with open(uuidPath, 'w') as fp: fp.write(uuid) return uuid nap(2) # Sleep a while return None
def get_qrimg(current_user, app): global thread global isLoggedIn import threading if not isLoggedIn: #load_status 会开启一个线程 load_status = itchat.load_login_status('itchat.pkl') print('threadalive1:', threading.active_count()) #服务器接受hotreload,开始数据的初始化 if load_status.get('BaseResponse').get('Ret') == 0: isLoggedIn = True thread = Thread(target=ready, args=(app, itchat, current_user)) thread.start() itchat.dump_login_status('itchat.pkl') print('threadalive2:', threading.active_count()) return None uuid = itchat.get_QRuuid() itchat.get_QR(uuid=uuid, qrCallback=Qr2Img) if thread.is_alive(): return qr_img if not thread.is_alive(): print('please Login') thread = Thread(target=monitor_login, args=(itchat, current_user, app)) thread.start() return qr_img #已经登陆微信 if isLoggedIn: # wechat 掉线或者登出 if not thread.is_alive(): print('threadalive3:', thread.is_alive()) isLoggedIn = False thread = Thread(target=monitor_login, args=(itchat, current_user, app)) thread.start() return qr_img return None
def login(id): while True: #检查登录状态 status = itchat.check_login(id) print(config.uuid, status) #如果登录状态符合要求,就等待10s再重新检查状态 if status in ['200', '201']: print('Already login') time.sleep(10) #如果状态检查不符合要求,则进行登录,登录成功则获取uuid,并获取朋友,聊天室,公众号列表 elif status in ['400', '408', '0']: print('Need to login') try: itchat.auto_login(hotReload=True) itchat.send_msg('login successfully!', toUserName='******') config.uuid = itchat.get_QRuuid() get_friend_list() get_chart_room_list() get_mp_list() itchat.run() except: #如果失败,重试 time.sleep(10)
def hello(name=None): global thread uuid = itchat.get_QRuuid() itchat.get_QR(uuid=uuid, qrCallback=QR_to_b64) print(thread.is_alive()) if thread.is_alive(): return render_template('login.html', name=name, info={ 'success': 1, 'msg': '已有登陆线程存在', 'qr': qr_b64.decode("utf-8") }) # thread = task(monitor_login,itchat) thread = Thread(target=monitor_login, args=(itchat, )) thread.start() return render_template('login.html', name=name, info={ 'success': 1, 'qr': qr_b64.decode("utf-8") })
def get_uuid(self): self.uuid = itchat.get_QRuuid() print(self.uuid)
if fromUser is None: fromUser = {} toChatroom = itchat.search_chatrooms(userName=msg["ToUserName"]) if toChatroom is None: toChatroom = {} log.notice("{} -> {} : {}".format( fromUser.get("NickName", u"Stranger").encode("utf-8"), toChatroom.get("NickName", u"Stranger").encode("utf-8"), msg["Content"].encode("utf-8"))) if msg.isAt: text = msg.text.replace(username, u"").split(u"\u2005", 2)[-1].encode("utf-8") handle_user_msg(text, msg) elif fromUser is not None and fromUser.get("NickName", "") == username: text = msg.text.encode("utf-8") handle_user_msg(text, msg) if __name__ == '__main__': log.init("../log/chatbot", "notice") uuid = itchat.get_QRuuid() itchat.auto_login(hotReload=True) me = itchat.search_friends() username = me["NickName"] #加载黑名单词 with open("../static/blackword") as f: for word in f: blackword_list.append(word.strip()) itchat.run()
try: # 读取头像文件 img = Image.open('./head_img/%s_head_img-%d.jpg' % (self.uuid, i)) except Exception as e: print(e) else: # 设置头像图片尺寸 img = img.resize((each_size, each_size), Image.ANTIALIAS) # 粘贴好友头像到指定的位置 image.paste(img, (x * each_size, y * each_size)) x += 1 if x == lines: x = 0 y += 1 image.save("./img/%s_all_head_img.png" % self.uuid) print('生成完成') itchat.send_image("./img/%s_all_head_img.png" % self.uuid, 'filehelper') if __name__ == "__main__": # 登录微信 itchat.auto_login(hotReload=True) friends = itchat.get_friends(update=True) analyse = Analyse(friends, itchat.get_QRuuid()) # analyse.friends_sex_ratio() # analyse.friends_map() analyse.signature_cloud() # analyse.head_img_cloud()