def getProductInfo(sku_id): params = { 'access_token': '%s' % secret.getSecret()['access_token'], 'app_key': '%s' % secret.getSecret()['app_key'], 'method': 'jingdong.service.promotion.goodsInfo', 'timestamp': secret.getSecret()['now'], 'skuIds': '%s' % sku_id, 'v': '2.0', } #参数排序 keys = params.keys() keys.sort() #访问服务 url = 'https://api.jd.com/routerjson?sign=%s' % getSignAndMd5( keys, secret.getSecret()['app_secret'], params) r = requests.get(url, params=params) skuinfo_result = json.loads(r.content) unicode_str = skuinfo_result[ 'jingdong_service_promotion_goodsInfo_responce'][ 'getpromotioninfo_result'] unicode_result = json.loads(unicode_str) goodsName = unicode_result['result'][0]['goodsName'] #商品名称 unitPrice = unicode_result['result'][0]['unitPrice'] #商品价格 commisionRatioPc = unicode_result['result'][0]['commisionRatioPc'] #佣金比例 #返给用户的钱 fanli = round(unitPrice * commisionRatioPc / 100 * 0.3, 2) ''' for k,v in unicode_result['result'][0].iteritems(): if k == 'goodsName': print v if k == 'commisionRatioPc': print v if k == 'unitPrice': print v ''' return goodsName.encode('utf-8'), str(unitPrice), str(fanli)
def getFanliLink(skuId): url = 'https://item.m.jd.com/product/%s.html'%skuId params = { 'access_token':'%s'%secret.getSecret()['access_token'], 'app_key':'%s'%secret.getSecret()['app_key'], 'method':'jingdong.service.promotion.batch.getcode', 'timestamp':secret.getSecret()['now'], 'v':'2.0', 'id':'%s'%skuId, 'url':'%s'%url, 'unionId':'%s'%secret.getSecret()['union_id'], 'channel':'WL', 'webId':'%s'%secret.getSecret()['site_id'], } #参数排序 keys = params.keys() keys.sort() #访问服务 url = 'https://api.jd.com/routerjson?sign=%s'%getSignAndMd5(keys,secret.getSecret()['app_secret'],params) r = requests.get(url,params=params) skuinfo_result = json.loads(r.content) unicode_str = skuinfo_result['jingdong_service_promotion_batch_getcode_responce']['querybatch_result'] unicode_result = json.loads(unicode_str) click_url = unicode_result['urlList'][0]['url'] return click_url
def getSelfCode(url): params = { 'access_token':'%s'%secret.getSecret()['access_token'], 'app_key':'%s'%secret.getSecret()['app_key'], 'method':'jingdong.service.promotion.getcode', 'timestamp':secret.getSecret()['now'], 'v':'2.0', 'promotionType':'7', 'materialId':'%s'%url, 'unionId':'%s'%secret.getSecret()['union_id'], 'channel':'WL', 'webId':'%s'%secret.getSecret()['site_id'], 'adttype':'6', } #参数排序 keys = params.keys() keys.sort() #访问服务 url = 'https://api.jd.com/routerjson?sign=%s'%getSignAndMd5(keys,secret.getSecret()['app_secret'],params) r = requests.get(url,params=params) result_ = json.loads(r.content) unicode_str = result_['jingdong_service_promotion_getcode_responce']['queryjs_result'] unicode_result = json.loads(unicode_str) click_url = unicode_result['url'] return click_url
def getProductInfo(sku_id): params = { 'access_token':'%s'%secret.getSecret()['access_token'], 'app_key':'%s'%secret.getSecret()['app_key'], 'method':'jingdong.service.promotion.goodsInfo', 'timestamp':secret.getSecret()['now'], 'skuIds':'%s'%sku_id, 'v':'2.0', } #参数排序 keys = params.keys() keys.sort() #访问服务 url = 'https://api.jd.com/routerjson?sign=%s'%getSignAndMd5(keys,secret.getSecret()['app_secret'],params) r = requests.get(url,params=params) skuinfo_result = json.loads(r.content) unicode_str = skuinfo_result['jingdong_service_promotion_goodsInfo_responce']['getpromotioninfo_result'] unicode_result = json.loads(unicode_str) goodsName = unicode_result['result'][0]['goodsName']#商品名称 unitPrice = unicode_result['result'][0]['unitPrice']#商品价格 commisionRatioPc = unicode_result['result'][0]['commisionRatioPc']#佣金比例 #返给用户的钱 fanli = round(unitPrice*commisionRatioPc/100*0.3,2) ''' for k,v in unicode_result['result'][0].iteritems(): if k == 'goodsName': print v if k == 'commisionRatioPc': print v if k == 'unitPrice': print v ''' return goodsName.encode('utf-8'),str(unitPrice),str(fanli)
else: numstrikes = int(line[-1:]) if(numstrikes == 2): punish(user) numstrikes = 0 print('User reset after punishment.') else: numstrikes += 1 print('Strike added to user.') return numstrikes strikes.write(user + ' 1') print('User added to strikes DB.') strikes.close() return 1 def punish(user): print('User punished.') def get_user_id(message): res = re.search('<@(|!)[0-9]+>', message) res = res.group(0) res = re.sub('!', '', res) print('Found UID ' + res + 'in message.') return res if __name__ == "__main__": client = MyClient() client.run(getSecret())
newEvent.numPlayers = numPlayers print(form.id) #tests permissions. @bot.command() async def test(ctx): if await checkPerm(ctx): await ctx.message.channel.send("You have the permissions for this.") #turns on botSpeak (see on_message event) @bot.command() async def botSpeak(ctx, channel): if await checkPerm: storeVars.state = 1 storeVars.channel = int(channel) await ctx.message.channel.send( "*[BotSpeak enabled, to end type `$s stop`]*") class storeVars: #literally used to store variables and thats it # state 1 is on, 0 is off state = 0 channel = 0 bot.run(getSecret(), bot=True, reconnect=True)