Skip to content

Instantly share code, notes, and snippets.

@dongweiming
Created February 16, 2019 15:38
Show Gist options
  • Save dongweiming/7392913b17f2d9f9b504b2936f5e5d58 to your computer and use it in GitHub Desktop.
Save dongweiming/7392913b17f2d9f9b504b2936f5e5d58 to your computer and use it in GitHub Desktop.
小鹅通新用户抽奖脚本
from datetime import datetime
from collections import defaultdict
from http.cookies import SimpleCookie
import requests
URL = 'https://admin.xiaoe-tech.com/new/customerList?is_pay=0&ruler=0&search=&page={page}'
cookie = SimpleCookie()
with open('cookie.txt') as f:
cookie.load(f.read())
cookies = {}
for key, morsel in cookie.items():
cookies[key] = morsel.value
headers = {
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36',
'x-requested-with': 'XMLHttpRequest',
'referer': 'https://admin.xiaoe-tech.com/new/customer'
}
page = 1
TIMEOUT = 2
flag = False
session = requests.Session()
NUMBER_MAP = defaultdict(list)
class attrdict(dict):
def __init__(self, *args, **kwargs):
dict.__init__(self, *args, **kwargs)
self.__dict__ = self
while 1:
r = session.get(URL.format(page=page), timeout=TIMEOUT,
headers=headers, cookies=cookies)
rv = r.json()
for item in rv.get('data')['list']:
item = attrdict(item)
nickname = item.nickname
created_at = datetime.strptime(item.created_at, '%Y-%m-%d %H:%M:%S')
if created_at > datetime(2019, 2, 16):
continue
if created_at < datetime(2019, 2, 2):
flag = True
break
NUMBER_MAP[created_at.minute].append((nickname, created_at))
if flag:
break
page += 1
number = int(input('输入幸运数字❯ '))
values = NUMBER_MAP.get(number, [])
def lucky_user(values):
return sorted(values, key=lambda x: x[1], reverse=True)[0]
if values:
nickname, created_at = lucky_user(values)
else:
offset = 1
while 1:
values = sorted(sum([NUMBER_MAP.get(number + o, [])
for o in (offset, -offset)], []),
key=lambda x: x[1])
if values:
nickname, created_at = lucky_user(values)
break
offset += 1
print(f'\n恭喜昵称为 {nickname} 的小鹅通同学可以任意选择一门爱湃森课程, 它的加入时间为 {created_at}\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment