Skip to content

Instantly share code, notes, and snippets.

@jianghu52
Forked from fdb713/xiami.py
Last active August 29, 2015 14:10
Show Gist options
  • Save jianghu52/bcbe1e0ae8d82c607884 to your computer and use it in GitHub Desktop.
Save jianghu52/bcbe1e0ae8d82c607884 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
File: xiami.py
Author: Luigi Fan
Description: Auto check-in script for xiami.
'''
import requests
import re
import sys
from argparse import ArgumentParser
url_login = 'http://www.xiami.com/web/login'
url_home = 'http://www.xiami.com/web'
data = {
'LoginButton': '登录'
}
headers= {
'Origin': "http://www.xiami.com",
'Referer': 'http://www.xiami.com/web/login',
'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36',
}
if __name__ == '__main__':
if len(sys.argv) < 3:
print "Arguments missing. Usage: python xiami.py email password."
sys.exit(1)
data["email"] = sys.argv[1]
data["password"] = sys.argv[2]
s = requests.Session()
r = s.post(url_login, data=data, headers=headers)
if r.url == url_login:
print "[Failed] Log in failed."
s.close()
sys.exit(1)
c = s.get(url_home, headers=headers)
checkin_pattern = re.compile(r'<a class="check_in" href="(.*?)">')
checkin_button = checkin_pattern.search(c.text)
if checkin_button:
checkin_url = "http://www.xiami.com%s" % checkin_button.group(1)
checkin_response = s.get(checkin_url, headers=headers)
else:
checkin_response = c
checkin_days = re.compile(ur'已连续签到(\d+)天').search(checkin_response.text)
print "[Succeed] Checked in already! %s days." % checkin_days.group(1)
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment