def insertSNtoBlack_SN(db, url): # 使用cursor()方法获取操作游标 cursor = db.cursor() # 获得字段 SN = repy.isSN(url) # SQL 插入语句 sql = "INSERT INTO BLACK_SN(black_sn) VALUES ('%s')" % (SN) try: # 执行SQL语句 cursor.execute(sql) # 执行sql语句 db.commit() print("insert BLACK_SN scuess") except: # 发生错误时回滚 db.rollback() print("insert error")
sql = "select id from mtdhb where sign = '" + sign + "'" # 执行sql语句 results = MySQL.exeSelectSql(db, sql) for row in results: uid = row[0] print('cookie id:', uid) MySQL.update_cookie(db, uid, cookiestr) MySQL.updateCookieById(db, uid, cookiestr) else: print('插入') # 没有加cookie验证,因为自用肯定能输入正确cookie MySQL.insertcookie(db=db, cookiestr=cookiestr) elif (number == 9): url = input("输入饿了么红包链接:") MySQL.selectIfInBlack_SNByUrl(db, url) groupsn = repy.isSN(url) MySQL.deleteIfInBlack_SN(db, groupsn) elif (number == 10): groupsn = input("输入红包链接 groupsn:") MySQL.selectIfInBlack_SN(db, groupsn) MySQL.deleteIfInBlack_SN(db, groupsn) elif (number == 11): # 批量领取 urls = input('输入urls:') urllist = [] themelist = [] groupsnlist = repy.isSN(urls) for groupsn in groupsnlist: db = MySQL.creatDBObject() id = input('输入开始领取的cookieid(数据库第几个开始领取,默认为1)') if id == '':
def selectIfInBlack_SNByUrl(db, url): # 获得字段 SN = repy.isSN(url) selectIfInBlack_SNBySN(db=db, groupsn=SN)
def getOne(db, id, url): # # 先判断url是否在黑名单中 # # 如果在黑名单中 # if(MySQL.selectIfInBlack_SN(db,url) ==True): # print("该url在黑名单中无法领取!因为该url被本程序领取过。") # return # # 如果不在黑名单中 # else: headers = { 'User-Agent': 'Mozilla/5.0 (Linux; Android 5.1; m1 metal Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043409 Safari/537.36 V1ANDSQ7.2.5744YYBD QQ/7.2.5.3305 NetType/WIFI WebP/0.3.0 Pixel/1080' } # url = input("输入饿了么红包链接:") jurl = "https://h5.ele.me/restapi/marketing/promotion/weixin/" jsons = { 'group_sn': '', 'sign': '', 'weixin_avatar': 'http://thirdqq.qlogo.cn/qqapp/101204453/6409FAE1CEA4B1A50F8A85B8DFDA7236/40', 'weixin_username': '******', 'method': 'phone' } # cookiedict = {'_utrace': '', 'ubt_ssid': '', 'perf_ssid': '', 'snsInfo[101204453]': '', 'SID': ''} cookiedict = {'snsInfo[101204453]': '', 'SID': ''} # 获取一个cookie cookie = MySQL.selectCookieObjectById(db, id) # 如果获取到的为None 说明数据获取不到 if (cookie == None): print("获取cookie data失败") return None else: # cookie2 = copy.copy(cookie) # 补全jurl jurl = jurl + cookie.jurl # 补全json字典 # 如果传入url参数 # if vardict['url']: jsons['group_sn'] = repy.isSN(url=url) # 如果传入groupsn参数 # if vardict['groupsn']: # jsons['group_sn'] = vardict['groupsn'] jsons['sign'] = cookie.sign # 补全cookie字典 # cookiedict = connect.cookieOejectToDictionary(cookie2) # cookiedict['_utrace'] = cookie.utrance # cookiedict['ubt_ssid'] = cookie.ubt_ssid # cookiedict['perf_ssid'] = cookie.perf_ssid cookiedict['snsInfo[101204453]'] = cookie.info cookiedict['SID'] = cookie.SID # 领取红包 s = requests.session() # 设置代理 # s.proxies = {'http': '121.193.143.249:80'} # s.proxies = {'http':'127.0.0.1:8888'} re = s.post(url=jurl, headers=headers, cookies=cookiedict, json=jsons) # 打印返回的json对象 re_json = re.content.decode() # print(re_json) # json对象解析为字典 re_json_dict = json.loads(re_json) # print(len(re_json_dict)) # 返回json长度为2 表示输入手机号,正常的json数据长度是8 if (len(re_json_dict) != 2): # print(re_json_dict) # print(re_json_dict['promotion_records']) arrary = re_json_dict['promotion_records'] # 打印已经领取 的数目 array_length = len(arrary) # if array_length == 0: # print("红包已失效") # return print('当前已经领取的数目:' + str(array_length)) #打印红包类型 HBtype_array = re_json_dict['promotion_items'] # HBtype_array = HBtype_array[0] if HBtype_array != []: HBtype = HBtype_array[0]['name'] print("当前红包类型:", HBtype) else: print("类型未知 --- 当前小号未领取到红包") else: array_length = -1 message = re_json_dict['message'] print("返回json错误:" + message) print("当前cookieid:" + str(id)) return int(array_length)
def get_one(self, url, ck): headers = { 'User-Agent': 'Mozilla/5.0 (Linux; Android 5.1; m1 metal Build/LMY47I; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/53.0.2785.49 Mobile MQQBrowser/6.2 TBS/043409 Safari/537.36 V1ANDSQ7.2.5744YYBD QQ/7.2.5.3305 NetType/WIFI WebP/0.3.0 Pixel/1080' } jurl = repy.isJurl(ck) # cookie字典 cookiedict = {} snsinfo = repy.is_snsinfo(ck) cookiedict[snsinfo[0]] = snsinfo[1] cookiedict['_utrace'] = repy.is_utrace(ck) cookiedict['ubt_ssid'] = repy.isUbt_ssid(ck) cookiedict['perf_ssid'] = repy.isPerf_ssid(ck) cookiedict['SID'] = repy.isSID(ck) # for key, value in cookiedict.items(): # print(key, ' : ', type(value)) # json字典 jsondict = { 'group_sn': '', 'sign': '', 'weixin_avatar': 'http://thirdqq.qlogo.cn/qqapp/101204453/6409FAE1CEA4B1A50F8A85B8DFDA7236/40', 'weixin_username': '******', 'method': 'phone' } jsondict["group_sn"] = repy.isSN(url) jsondict["sign"] = repy.iselemekey(ck) # for key, value in jsondict.items(): # print(key,' : ',value) s = requests.session() re = s.post(url=jurl, headers=headers, cookies=cookiedict, json=jsondict) re_json = re.content.decode() # print(re_json) # json对象解析为字典 re_json_dict = json.loads(re_json) # self.writefile(re_json) if (len(re_json_dict) != 2): arrlen = len(re_json_dict['promotion_records']) print("已经领取个数:" + str(arrlen)) else: arrlen = -1 message = re_json_dict['message'] print("返回json错误:" + message) print("当前cookieid:" + str(ck)) return int(arrlen) def get_max(url, ck): lucky_number = repy.isLuckNumber(url) if lucky_number != None: print("手气最佳位置:" + str(lucky_number)) else: print("获取手气最佳失败!") return