forked from isayme/smzdm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
smzdm_daily.py
executable file
·66 lines (53 loc) · 1.84 KB
/
smzdm_daily.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import json
import sys
import requests
import re
SMZDM_USERNAME = os.getenv('SMZDM_DAILY_USERNAME') or '' # username or email
SMZDM_PASSWORD = os.getenv('SMZDM_DAILY_PASSWORD') or '' # password
class SMZDMDailyException(Exception):
def __init__(self, req):
self.req = req
def __str__(self):
return str(self.req)
class SMZDMDaily(object):
BASE_URL = 'https://zhiyou.smzdm.com'
LOGIN_URL = BASE_URL + '/user/login/ajax_check'
CHECKIN_URL = BASE_URL + '/user/checkin/jsonp_checkin'
def __init__(self, username, password):
self.username = username
self.password = password
self.session = requests.Session()
def checkin(self):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101 Firefox/20.0',
'Host': 'zhiyou.smzdm.com',
'Referer': 'http://www.smzdm.com/'
}
params = {
'username': self.username,
'password': self.password,
}
r = self.session.get(self.BASE_URL, headers=headers, verify=True)
r = self.session.post(self.LOGIN_URL, data=params, headers=headers, verify=True)
r = self.session.get(self.CHECKIN_URL, headers=headers, verify=True)
if r.status_code != 200:
raise SMZDMDailyException(r)
data = r.text
jdata = json.loads(data)
return jdata
if __name__ == '__main__':
if SMZDM_USERNAME is '' or SMZDM_PASSWORD is '':
print('SMZDM_USERNAME and SMZDM_PASSWORD required')
sys.exit()
try:
smzdm = SMZDMDaily(SMZDM_USERNAME, SMZDM_PASSWORD)
result = smzdm.checkin()
except SMZDMDailyException as e:
print('fail', e)
except Exception as e:
print('fail', e)
else:
print('success', result)