Skip to content

Instantly share code, notes, and snippets.

@CzBiX
Last active Dec 24, 2015
Embed
What would you like to do?
查询上海公交卡的余额和消费情况。注意数据有延时!
#!/usr/bin/env python3
#
# Usage: sptcc.py 60XXXXXXXXX
import sys
import hashlib
import json
import re
import requests
__author__ = 'czbix'
def get_md5_key(data):
hasher = hashlib.md5()
hasher.update(data.encode("ascii"))
return hasher.hexdigest()
def main():
card_no = sys.argv[1]
md5 = get_md5_key(card_no)[8:16]
resp = requests.get("http://220.248.75.36/handapp/PGcardDAServlet",
params={"arg1": card_no, "arg2": md5, "callback": ""})
content = "{\"" + resp.text[2:-2]
content = re.sub(",(?!['\d ])", ',"', content)
content = content.replace(":", "\":")
content = content.replace("'", "\"")
result = json.loads(content)
print("Bal:\t%.1f" % float(result["yue"]))
print("Amount:\t%.1f" % result["xiaofei"])
print("Save:\t%.1f" % result["jiesheng"])
print("Date:\t%s-%s" % (result["date_arr"][0], result["date_arr"][1]))
data_arr = result["data_arr"]
length = len(data_arr)
text_arr = result["text_arr"]
data_arr_js = result["data_arr_js"]
for i in range(length):
print("%s:\t%.1f\t%.1f" % (text_arr[i], data_arr[i], data_arr_js[i]))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment