Created
May 31, 2019 02:37
-
-
Save candlewill/a4edac259816adbf9bf64269de3fc85e to your computer and use it in GitHub Desktop.
京东优惠券定时抢
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""JD_get_coupon.ipynb | |
Automatically generated by Colaboratory. | |
Original file is located at | |
https://colab.research.google.com/drive/1m0QbL4UDq8mLtqSAY1A9nSTVSDxwVs17 | |
""" | |
import requests | |
import datetime | |
from pytz import timezone | |
from pytz import utc | |
import time, random | |
cookie = """webp=1; sc_width=360; shshshfpa=ad9975f4-2f66-c1d7-f658-6124de5cc7a6-1558934954; visitkey=57742551619917094; wq_area=1_0_0%7C2; pt_key=app_openAAJc63WVADARNPz6ScahefpFpe1w1nLsnR0UL3n2ASBTVzZaLVTo13WH-mZQjuI_LQ7oharGD1c; pt_pin=candlewill; pwdt_id=candlewill; sid=0e55d8a74b8b8aff03792f388a266a2w; wxa_level=1; retina=1; cid=8; wqmnx1=MDEyNjM3NHNwZG9zdHllNGVjcjEydHIubHZDY3p3eGwuJi4mYTAwZTRmM2E3Njk7ZDs4MzJmO2ttSXIxN3UyLzAyOTlzaTU2ZDcvdS44Y2RyLzB1Y2V8ODU4cDAyLk8uYTswL3A5b2lwLmFBeWVscF9pbCA7aSB1UjIgcGkzTWUpb0M1OE1zIDRiZjcyZm40S09TVSYp; __jda=122270672.15589349347171749912175.1558934934.1558937144.1558946033.3; __jdb=122270672.2.15589349347171749912175|3.1558946033; __jdc=122270672; pre_session=866654035426722-ecd09fcc6799|578; pre_seq=38; __jdv=122270672%7Cwww.zuanke8.com%7C-%7Creferral%7C-%7C1558887142153; __wga=1558946150008.1558946034329.1558937145158.1558934954451.2.3; PPRD_P=UUID.15589349347171749912175; shshshfp=5510dc0a0ad5c0cb7f82f96ec02dad33; shshshsID=e90c81ec6b10d12cc26aee1744349522_2_1558946150424; shshshfpb=j5ofEYRCn6eS1dyD%20WBTRyA%3D%3D; unpl=V2_ZzNtbUJVE0F0DEBTcx1VV2IDEF8SUEUUcg1CVS8aCFVvBBJbclRCFX0UR1BnGlsUZwYZWEtcQxNFCEdkeBBcNWQCEltDXkMcdAlGZEsaXDVuMxJZQ1BEEnINT1x6GlgFYgsVWEJSRxN8OHZTSxxeBG4HEl1DX0AQRThPVXIRWg1XAiJcchUXSXUIQld%2FHREFYwIVWkVQRhx9CUVQexxUAmIDF1lEXnMURQs%3D; __jd_ref_cls=; mba_sid=436.10; mba_muid=15589349347171749912175.436.1558946189807""" | |
Referer = """https://coupon.m.jd.com/coupons/show.action?key=7b5c4eff855945c6adfe623be7caf759&roleId=19169072&to=https://pro.m.jd.com/mall/active/8up1CvzRnoncgbTBV8zcCtoRmwk/index.html&lng=116.332639&lat=40.040007&un_area=1_2800_2851_0&sid=0e55d8a74b8b8aff03792f388a266a2w""" | |
user_agent = "jdapp;android;8.0.2;8.0.0;866654035426722-ecd09fcc6799;network/wifi;model/MI 6;addressid/138717073;appBuild/67205;psn/866654035426722-ecd09fcc6799|523;psq/69;uid/866654035426722-ecd09fcc6799;adk/;ads/;usc/kong;ucp/t_1000089893_;umd/tuiguang;utr/07e20eb316784d4185c03ce1ca9a51ef;jdv/0|kong|t_1000089893_|tuiguang|07e20eb316784d4185c03ce1ca9a51ef|1558689479;pap/JA2015_311210|8.0.2|ANDROID 8.0.0;osp/android;apv/8.0.2;osv/8.0.0;pv/396.71;ref/com.jd.lib.jshop.jshop.JshopMainShopActivity;partner/google;apprpd/Shop_ShopMain;Mozilla/5.0 (Linux; Android 8.0; MI 6 Build/OPR1.170623.027; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.132 MQQBrowser/6.2 TBS/044328 Mobile Safari/537.36" | |
couponUrl = "https://s.m.jd.com/activemcenter/mfreecoupon/getcoupon?key=7b5c4eff855945c6adfe623be7caf759&roleId=19169072&to=https%3A%2F%2Fpro.m.jd.com%2Fmall%2Factive%2F8up1CvzRnoncgbTBV8zcCtoRmwk%2Findex.html&verifycode=&verifysession=&_=1558946189824&sceneval=2&g_login_type=1&callback=jsonpCBKD&g_ty=ls" | |
scheduled_time = "2019-05-24 21:59:30" | |
end_time = "2019-05-29 22:01:30" | |
cst_tz = timezone('Asia/Shanghai') | |
utc_tz = timezone('UTC') | |
cokies = {} | |
for line in cookie.strip().split(";"): | |
key, value = line.strip().split("=") | |
cokies[key.strip()] = value.strip() | |
session = requests.Session() | |
session.headers['User-Agent'] = user_agent | |
session.headers['Referer'] = Referer | |
session.cookies = requests.utils.cookiejar_from_dict(cokies) | |
r = session.get(couponUrl) | |
print(r.text) | |
i = 0 | |
pre = "" | |
while True: | |
utcnow = datetime.datetime.utcnow().replace(tzinfo=utc_tz) | |
now = utcnow.astimezone(cst_tz).strftime('%Y-%m-%d %H:%M:%S') | |
sec = now[-4:] | |
if sec == pre: | |
changed = False | |
else: | |
changed = True | |
pre = sec | |
if "00" == now[-2:] and changed: | |
print("current time: ", now, "scheduled time", scheduled_time, "end time", end_time) | |
time.sleep((random.random()*10+5)/1000) | |
if now >= scheduled_time and "0:00" == now[-4:] and changed: | |
r = session.get(couponUrl) | |
print("the %s-st time to click, at %s." % (i, now)) | |
print(r.text) | |
i+=1 | |
if now >= end_time: | |
print("stop") | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment