This repository has been archived by the owner on May 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
libXiami.py
91 lines (72 loc) · 2.46 KB
/
libXiami.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import urllib
import urllib2
import cookielib
import StrCookieJar
import json
import lxml.html
headers = {
"Referer": "http://www.xiami.com/member/login",
"User-Agent": 'Mozilla/5.0 (IsomByt; checker)',
}
class User:
def __init__(self):
self.opener = None
self._data = None
def loadCookie(self,cookie):
self.cookie = StrCookieJar.StrCookieJar(cookie)
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
def dumpCookie(self):
return self.cookie.dump()
def login(self,email,password):
self.cookie = StrCookieJar.StrCookieJar()
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
login_url = "https://login.xiami.com/member/login"
request = urllib2.Request(login_url,headers=headers)
response = self.opener.open(request)
data = response.read()
dom = lxml.html.fromstring(data)
args = dict(map(lambda x:(str(x.name),unicode(x.value).encode("u8")),dom.xpath("//form//input")))
args["email"] = email
args["password"] = password
request = urllib2.Request(login_url, urllib.urlencode(args), headers)
response = self.opener.open(request)
data = response.read()
def __getitem__(self,key):
if not self.data:
raise BaseException("please login")
return self.data[key]
@property
def data(self):
if not self._data:
data = self.getuserinfo()
if data["status"]:
self._data = data["data"]['userInfo']
return self._data
def getuserinfo(self):
url = "http://www.xiami.com/index/home"
request = urllib2.Request(url,headers=headers)
response = self.opener.open(request)
data = response.read()
return json.loads(data)
@property
def ischeckined(self):
if self.data and self.data["is"]:
return True
return False
@property
def islogined(self):
if self.data and self.data["user_id"]:
return True
return False
def checkin(self):
url = "http://www.xiami.com/task/signin"
request = urllib2.Request(url,urllib.urlencode({}),headers)
response = self.opener.open(request)
days = response.read()
if days:
return int(days)
return None
if __name__ == "__main__":
user = User()
user.login("email","password")
print user.checkin()