Skip to content

Commit

Permalink
Add Time Module
Browse files Browse the repository at this point in the history
  • Loading branch information
DefJia committed Oct 29, 2018
1 parent e9d56b6 commit f8d5800
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 125 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.config.ini*
data.db
.idea/
__pycache__/

data/
6 changes: 5 additions & 1 deletion Book.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# from General import General
import requests, time, datetime, json
from bs4 import BeautifulSoup
from configparser import ConfigParser
Expand All @@ -18,6 +17,11 @@ class Book:
"""
@staticmethod
def index(first, second=-1):
"""
:param first:
:param second:
:return:
"""
if second == -1:
if type(first) == str:
hash = cfg.get('Account', 'common_hash').split(',').index(first)
Expand Down
48 changes: 0 additions & 48 deletions Crawl.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,2 @@
from Manage import Manage
from Book import Book
import sqlite3


class Crawl:
@staticmethod
def crawl_user():
a = Manage().login()
conn = sqlite3.connect('data.db')
c = conn.cursor()
for i in range(69, 2047):
info = a.query_info('user', page=i)
for elem in info:
sql = "insert into user(sid, cid, name, type, department) values ("
for field in elem:
sql += "'" + elem[field] + "',"
sql = sql[:-1] + ')'
try:
c.execute(sql)
except sqlite3.IntegrityError:
print(sql)
except sqlite3.OperationalError:
print(sql)
conn.commit()
print("第%d页完成爬取" % i)
conn.close()

@staticmethod
def crawl_book():
a = Manage().login()
conn = sqlite3.connect('data.db')
c = conn.cursor()
for i in range(3270, 4550):
info = a.query_info('book', page=i)
for elem in info:
sql = "insert into book(bid, sid, name, room, start, end, status, book_time) values ("
for field in elem:
sql += "'" + elem[field] + "',"
sql = sql[:-1] + ')'
# print(elem)
try:
c.execute(sql)
except sqlite3.IntegrityError:
print(sql)
except sqlite3.OperationalError:
print(sql)
conn.commit()
print("第%d页完成爬取" % i)
conn.close()
13 changes: 0 additions & 13 deletions Init_DB.py

This file was deleted.

55 changes: 51 additions & 4 deletions Manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from configparser import ConfigParser
from collections import OrderedDict
from datetime import *
import sqlite3

cfg = ConfigParser()
cfg.read('.config.ini')
Expand Down Expand Up @@ -118,17 +119,63 @@ def get_book_time(self, href):
return string


class Crawl:
@staticmethod
def crawl_user():
a = Manage().login()
conn = sqlite3.connect('data.db')
c = conn.cursor()
for i in range(69, 2047):
info = a.query_info('user', page=i)
for elem in info:
sql = "insert into user(sid, cid, name, type, department) values ("
for field in elem:
sql += "'" + elem[field] + "',"
sql = sql[:-1] + ')'
try:
c.execute(sql)
except sqlite3.IntegrityError:
print(sql)
except sqlite3.OperationalError:
print(sql)
conn.commit()
print("第%d页完成爬取" % i)
conn.close()

@staticmethod
def crawl_book():
a = Manage().login()
conn = sqlite3.connect('data.db')
c = conn.cursor()
for i in range(3270, 4550):
info = a.query_info('book', page=i)
for elem in info:
sql = "insert into book(bid, sid, name, room, start, end, status, book_time) values ("
for field in elem:
sql += "'" + elem[field] + "',"
sql = sql[:-1] + ')'
# print(elem)
try:
c.execute(sql)
except sqlite3.IntegrityError:
print(sql)
except sqlite3.OperationalError:
print(sql)
conn.commit()
print("第%d页完成爬取" % i)
conn.close()


def rm_space(string):
string = string.replace('\r', '').replace('\n', '').replace('\t', '').replace(' ', '')
return string


if __name__ == '__main__':
a = Manage().login()
a.del_book(1120153332, 0)
# a.del_book(1120153332, 0)
# a.query_info('book')
'''
lst = cfg['Account']['commonu'].split(',')
for sid in lst:
n = a.del_renege(sid)
print("Delect %d logs of %d successfully" % (n, sid))
'''

80 changes: 55 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,73 @@
# LIT后花园观景台预约系统后台
# 图书馆座位预约系统辅助工具

​ 本系统由Defjia从2017.11开始开发,经过数次迭代和一次重构,这里是重构后的代码。

[TOC]

## 文件结构
- Core Codes
- Book.py
- Book (预约相关)
- login(self)
- prepare(self, room, seat, date)
- book(self)
- General.py
- General
通用的方法。
- Maintain.py
-
- Manage.py (包含后台操作,不对外公开)
- Manage
- login(self)
- query_info(self, action, student_id='', page=1)
-

## 代码结构
- Book.py
- Book (预约相关)

- *index(first, second=-1)*

定位配置文件中的账号密码

- login(self)

CAS登录

- prepare(self, room, seat, date)

预约准备

- book(self)

预约
- General.py
- General

通用的方法。
- Maintain.py
- detect()

检测僵尸账号是否正常
- Manage.py (包含后台操作,不对外公开)
- Manage
- login(self)
- query_info(self, action, student_id='', page=1)
- del_renege(self, student_id)
- del_book(self, sid, date_delta)
- get_book_time(self, href)

- Crawl

爬取数据

- *crawl_user()*

爬取用户信息

- *crawl_book()*

爬取预约记录

- rm_space(string)

## 版本记录

### 已修改内容
- 修改文件结构。
- Manage.del_reneges方法增加参数识别,方便切换删除账号的类别。
- index方法修改为Book类的静态方法,可以通过拼音码(常用用户)、序号(僵尸账号)指定学号密码。

- index方法修改为Book类的静态方法,可以通过拼音码(常用用户)、序号(僵尸账号)指定学号密码。
### 待修改内容

#### 重要
- 添加自动定时预约功能
- 添加自动维护未签到座位功能

#### 一般
- 增加关注座位入馆提醒功能

#### 不重要
- 在config.ini中标注僵尸账号的可用性,以及修改相关方法。
- 增加入馆时自动预约功能。
18 changes: 16 additions & 2 deletions Time.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime
import time
import datetime
import time, requests


class Time:
Expand All @@ -9,3 +9,17 @@ def wait_until(time_):
It needs to be clarified that the time is that on remote server.
:return: 0 -> time is up
"""

@staticmethod
def get_server_time(host):
r = requests.get(host)
_t = str(r.headers)[15:35]
t = datetime.datetime.strptime(_t, "%d %b %Y %H:%M:%S") + datetime.timedelta(hours=8)
return t


if __name__ == '__main__':
host = 'http://seat.lib.bit.edu.cn'
res = Time()
r = res.get_server_time(host)
print(r)
20 changes: 0 additions & 20 deletions init.sql

This file was deleted.

20 changes: 10 additions & 10 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,13 @@
from Book import Book
from Query import Query
from Manage import Manage
import time

if __name__ == '__main__':
date = 1
date = 0
cur = 0
while True:
query = Query(date, 17)
res = query.get_list()
if res:
for elem in res:
account = Book(cur).login()
account.prepare(elem[0], elem[1], date)
account.book()
cur += 1
query = Query(date, 16)
query = Query(date, 311)
res = query.get_list()
if res:
for elem in res:
Expand All @@ -23,3 +16,10 @@
account.book()
cur += 1
time.sleep(1)
'''
a = Manage().login()
test = Book('ljq').login()
test = test.prepare(311, 2, 1)
a.del_book(1120132559, 1)
test.book()
'''

0 comments on commit f8d5800

Please sign in to comment.