圖書館有個長這個樣子的網頁。。。我有點想知道去幾樓會比較空,什么時間去座位比較多。又懶得不停地查這個網頁,那只能編個程序讓它替我干這個瑣事了。。。
結論:從人數變動圖來看,今天的學霸們從8:15就開始涌入圖書館了,人數直到17:00才開始下降,晚上又有小幅度上升。
在中午的就餐時間出去的人比較少,應該是下午還要學習。而晚飯時間出去的人多很多,而且一去不回,大概是學了一天回去休息了。晚飯后又涌進來一些人,大概學到21:00就大部分開始回去了。
按照空座/有人座位來看,一樓晚上坐著最空,其次3樓和四樓差不多,比較空吧。
所有圖表、代碼在下面:
還好這個網頁還比較好看懂。。。
程序代碼:
需要python2.7 BeautifulSoup支持
# get library seats
# Designed By Xc.Li
import urllib
import BeautifulSoup
import re
import time
import os
def find_number(keyword):
for tag in tags:
s_tag = str(tag)
flag = re.match(keyword,s_tag)
if flag is not None:
return s_tag[54:-18]
while (True):
url = 'http://lib.ecust.edu.cn:8081/gateseat/lrp.aspx'
html = urllib.urlopen(url).read()
soup = BeautifulSoup.BeautifulSoup(html)
tags = soup('span')
output = list()
output.append(time.ctime()[11:-4])
for floor in [1, 2, 3, 4, 5, 6]:
# print 'Floor:', floor
keyword = '^'
# print 'Used:', find_number(keyword)
output.append(int(find_number(keyword)))
keyword = '^'
# print 'Left:', find_number(keyword)
output.append(int(find_number(keyword)))
print output
tf = open('lib-rec.csv','a')
for data in output:
tf.write(str(data))
tf.write(',')
tf.write('\n')
tf.close()
i = -5
while (i<=900):
i = i+5
print 'Running!'
print 900-i,'seconds left'
time.sleep(5)
os.system('cls')