def parse(self, response): try: json_obj = json.loads(response.body) if str(json_obj['resultCode'] == 0): json_str = crypt.decrypt_mobile_sk( json_obj['data'], str(response.request.meta['msk'])) print json_str data = json.loads(json_str) # if str(data['n']) != '': item = MobileItem() item['jsonstr'] = json_str item['name'] = str(data['n']) item['mobile'] = str(data['p']) item['timestamp'] = int(time.time() * 300) item['_id'] = crypt.get_md5(str(data['p'])) yield item elif str(json_obj['resultCode']) == '-1': print 'result code : -1' print 'response body: ' + str(response.body) print 'uid: ' + str(crypt.uid) + ' tk: ' + str( crypt.tk) + ' sk: ' + str(crypt.sk) else: if response.request.meta['sk'] == crypt.sk: # sendEmail("change auth") if mutex.acquire(10): if not crypt.is_changing: print 'changing auth' if crypt.change_auth(): print 'change auth success' else: print 'change auth failure' else: while crypt.is_changing: time.sleep(1) mutex.release() request = scrapy.Request( url=crypt.get_posturl(), method='POST', body=crypt.get_poststr(response.request.meta['mobile']), headers={ 'X-CLIENT-PFM': '20', 'X-CLIENT-VCODE': '81', 'X-CLIENT-PID': '8888888', 'Content-Type': 'application/json; charset=utf-8', 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.0.2; Redmi Note 2 MIUI/V7.5.5.0.LHMCNDE', 'Accept-Encoding': 'gzip', }) request.meta['mobile'] = response.request.meta['mobile'] request.meta['msk'] = crypt.sk request.meta['mtk'] = crypt.tk request.meta['muid'] = crypt.uid yield request # '{"resultCode":1400,"errorMsg":"req invalid"}' print json_obj['resultCode'] print json_obj['errorMsg'] except Exception, e: print e.message print traceback.format_exc()
def parse(self, response): try: json_obj = json.loads(response.body) if str(json_obj['resultCode'] == 0): json_str = crypt.decrypt_mobile_sk(json_obj['data'], str(response.request.meta['msk'])) print json_str data = json.loads(json_str) # if str(data['n']) != '': item = MobileItem() item['jsonstr'] = json_str item['name'] = str(data['n']) item['mobile'] = str(data['p']) item['timestamp'] = int(time.time() * 300) item['_id'] = crypt.get_md5(str(data['p'])) yield item elif str(json_obj['resultCode']) == '-1': print 'result code : -1' print 'response body: ' + str(response.body) print 'uid: ' + str(crypt.uid) + ' tk: ' + str(crypt.tk) + ' sk: ' + str(crypt.sk) else: if response.request.meta['sk'] == crypt.sk: # sendEmail("change auth") if mutex.acquire(10): if not crypt.is_changing: print 'changing auth' if crypt.change_auth(): print 'change auth success' else: print 'change auth failure' else: while crypt.is_changing: time.sleep(1) mutex.release() request = scrapy.Request( url=crypt.get_posturl(), method='POST', body=crypt.get_poststr(response.request.meta['mobile']), headers={ 'X-CLIENT-PFM': '20', 'X-CLIENT-VCODE': '81', 'X-CLIENT-PID': '8888888', 'Content-Type': 'application/json; charset=utf-8', 'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.0.2; Redmi Note 2 MIUI/V7.5.5.0.LHMCNDE', 'Accept-Encoding': 'gzip', } ) request.meta['mobile'] = response.request.meta['mobile'] request.meta['msk'] = crypt.sk request.meta['mtk'] = crypt.tk request.meta['muid'] = crypt.uid yield request # '{"resultCode":1400,"errorMsg":"req invalid"}' print json_obj['resultCode'] print json_obj['errorMsg'] except Exception, e: print e.message print traceback.format_exc()
def parse_response(self, response, request): try: json_obj = json.loads(response.body) if str(json_obj['resultCode'] == 0): json_str = crypt.decrypt_mobile_sk(json_obj['data'], str(request.meta['msk'])) MongoDBUtils().insertDB(json.loads(json_str)) elif str(json_obj['resultCode']) == '-1': print 'result code : -1' print 'response body: ' + str(response.body) print 'uid: ' + str(crypt.uid) + ' tk: ' + str(crypt.tk) + ' sk: ' + str(crypt.sk) except Exception, e: print e.message print traceback.format_exc()