├── src ├── mapping.pkl ├── requirements.txt ├── 35-37.py ├── 21-22.py ├── query.py └── BF.py ├── inspect └── inspect.txt └── README.md /src/mapping.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NUAA-Open-Source/nuaa-ElectriFee/master/src/mapping.pkl -------------------------------------------------------------------------------- /src/requirements.txt: -------------------------------------------------------------------------------- 1 | flask==1.0.2 2 | requests==2.20.1 3 | beautifulsoup4==4.6.3 4 | pyyaml==3.13 5 | -------------------------------------------------------------------------------- /inspect/inspect.txt: -------------------------------------------------------------------------------- 1 | drlouming 2 | { 3 | 将军路校区:1 4 | DropDownList1 5 | { 6 | 1-6|10-22栋房间用电:1 7 | 1-22栋空调用电:2 8 | drceng 9 | { 10 | 01-22栋:51-72 11 | 21栋:71 12 | dr_ceng 13 | { 14 | 01-19层:214-232 15 | { 16 | 各层房间 17 | drfangjian:2647-3160 18 | //每层01、02各4个空调,其余各5个。每层28个空调,按顺序排列。第1层01、02只有3个空调,但是仍然占用一个序号。19层只有10个空调 19 | //第15层及18层的排序很乱 20 | } 21 | } 22 | 22栋:72 23 | dr_ceng 24 | { 25 | 01-19层:233-251 26 | { 27 | 各层房间 28 | drfangjian:3161-3674 29 | //每层01、02各4个空调,其余各5个。每层28个空调,按顺序排列。第1层01、02只有3个空调,但是仍然占用一个序号。19层只有10个空调,按顺序排列 30 | } 31 | } 32 | } 33 | 23-24栋房间用电:3 34 | 23-24栋空调用电:4 35 | 7-10|12|15|30|32|35-37栋房间用电:7 36 | drceng 37 | { 38 | 35-37栋:0235-0237 (实际上是"02"+楼栋号) 39 | dr_ceng 40 | { 41 | "02"+楼栋号+层数(用两位数表示) 42 | { 43 | drfangjian:为dr_ceng+下拉菜单中的序号(用两位数表示) 44 | } 45 | } 46 | } 47 | } 48 | 49 | 明故宫校区:2 50 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nuaa-ElectriFee 2 | 3 | ## 开发目的 4 | 5 | 此项目旨在为南京航空航天大学住宿生提供更方便的电费查询方式。 6 | 7 | ## 说明 8 | 9 | `src/*`是获取电费的python脚本。 10 | 11 | `inspect/inspect.txt`是部分对应关系。 12 | 13 | ## Usage 14 | Before you can query Electricity Fee via query.py, you have to generate data by running ```python3 BF.py``` 15 | 16 | You need to install some requirements 17 | 18 | ``` 19 | pip install -r requirements.txt 20 | ``` 21 | 22 | This script will retrieve all the info from the Electricity Query Website and build a tree structure which a dorm is pointed to a dict of arguments required to be submitted. 23 | 24 | By executing so, you shall have a pkl file in the current working directory. 25 | 26 | Simply run ```python3 query.py ``` and make a HTTP request to http://localhost:5000/query 27 | 28 | Here is a sample curl request: 29 | ``` 30 | curl -d "campus=1&building=22&public_dorm=702&private_dorm=3" http://localhost:5000/query -vvv 31 | ``` 32 | 33 | Then it will return all the information including remaining balance and history of electricity purchase in JSON format. 34 | 35 | ## 附录 36 | 电费查询网址(需校园内网)`http://222.192.89.21/sims3/default.aspx` 37 | -------------------------------------------------------------------------------- /src/35-37.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import requests 4 | import re 5 | import sys 6 | import random 7 | 8 | 9 | def getViewstate(text): 10 | # 这里使用这样的正则表达式匹配__VIEWSTATE字段,使用Python requests应该这样匹配,其他浏览器可能不一样 11 | data = re.match( 12 | r'.*id\=\"\_\_VIEWSTATE\" value\=\"(.*)\" \/\>\r\n\r\n\
', text, re.S) 13 | return data.group(1) 14 | 15 | 16 | def getFee(text): 17 | # 匹配剩余电费 18 | data = re.match( 19 | r'.*\(\-*\d+\.\d\d)\<\/span\>', text, re.S) 20 | # 居然会有负数,坑死我了 21 | return data.group(1) 22 | 23 | def getRoom(number, text): 24 | # 匹配房间号前面的option代号。这里我不想算号码了,机智一点直接匹配 25 | if number[2]=='1': # emmm,这里,10层以下他是不加0的 26 | toFind = number[0:2]+'\\-'+number[2:6]+'\\-'+number[7:] 27 | else: 28 | toFind = number[0:2]+'\\-'+number[3:6]+'\\-'+number[7:] 29 | data = re.match( 30 | r'.*\