Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
FINAL VERSION
Browse files Browse the repository at this point in the history
  • Loading branch information
JayYoung2021 authored Aug 28, 2020
1 parent 6a6239d commit 4721f07
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 11 deletions.
116 changes: 116 additions & 0 deletions AwesomePU_CLI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import sys
from PUWebSpider import *

try: # Network monitoring module
requests.get('http://njtech.pocketuni.net/')
except requests.exceptions.ProxyError:
sys.exit()

# example = PU(None, '10086', 'password')
# example = PU('480', '10086', 'password')
# example.set_college('斯莱特林学院', '魔法类9.75')
print('输入 1 使用手机号登录')
print('输入 2 使用学号登录(南京工业大学独占)')
while True:
while True:
mode = input()
if mode == '1':
account = str(input('手机号:'))
password = str(input('密码:'))
example = PU(None, account, password)
break
elif mode == '2':
sid = '480'
account = str(input('学号:'))
password = str(input('密码:'))
example = PU(sid, account, password)
break
else:
print('输入有误,请重试')
if example.verification():
print('登陆成功')
break
else:
print('登录失败,请重试')

college_list = example.get_college_list()
for i in range(len(college_list)):
print(i + 1, college_list[i])
college = college_list[int(input('学院序号:')) - 1]
class_ = input('班级:')
example.set_college(college, class_)

list_ = example.filtered_activities
page = 0
totalCount = len(list_) # 内容总数量
loadCount = 10 # 每页加载数量
totalPage = (totalCount + loadCount - 1) // loadCount # 所求总页数


def end(p):
if totalCount - loadCount * (p + 1) < 0:
return totalCount - loadCount * p
else:
return loadCount


if not list_:
print('无可用活动')
else:
for i in range(0, end(page)):
print(i + 1, list_[i]['title'])
while True:
print('查看上一页输入"<" 查看活动详情输入序号 查看下一页输入">"')
print('退出程序输入0')
cmd = input('请输入命令:')
if cmd == '<':
if page > 0:
page -= 1
for i in range(loadCount * page, end(page)):
print(i % 10 + 1, list_[i]['title'])
elif cmd == '>':
if page < totalPage - 1:
page += 1
for i in range(loadCount * page, end(page)):
print(i % 10 + 1, list_[i]['title'])
elif ('0' <= cmd <= '9') or cmd == '10':
if cmd == '0':
break
# for k, v in list_[loadCount * page + int(cmd) - 1].items():
# print(k, v)
tmp = loadCount * page + int(cmd) - 1
print('活动名称:' + list_[tmp]['title'])
print('归属组织:' + list_[tmp]['author'])
print('活动分类:' + list_[tmp]['class'])
print('活动地点:' + list_[tmp]['location'])
print('活动院系:', end='')
if list_[tmp]['college'] is None:
print("限制")
else:
print(list_[tmp]['college'])
print('活动年级:', end='')
if list_[tmp]['grade'] is None:
print("限制")
else:
print(list_[tmp]['grade'])
print('可参与部落:', end='')
if list_[tmp]['tribe'] is None:
print("无限制")
else:
print(list_[tmp]['tribe'])
print('活动时间:' + list_[tmp]['time'])
print('报名起止:' + list_[tmp]['reg'])
print('外勤打卡:' + list_[tmp]['clock_in'])
print('参加费用:' + list_[tmp]['cost'])
print('参加人数:' + list_[tmp]['exist'])
print('剩余名额:' + list_[tmp]['surplus'])
print('联系方式:', end='')
if list_[tmp]['contact'] is None:
print("无限制")
else:
print(list_[tmp]['contact'])
print('活动简介:' + list_[tmp]['intro'])
for i in range(loadCount * page, end(page)):
print(i % 10 + 1, list_[i]['title'])
else:
print('输入有误,请重试')
23 changes: 12 additions & 11 deletions PUWebSpider.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ def parse_one_activity(html): # str -> list

class PU:
def __init__(self, sid, account, password):
self.password = str(password)
self.password = password
if sid is None: # Judge login method
self.mobile = str(account)
self.mobile = account
self.post_url = 'http://pocketuni.net/index.php?app=home&mod=Public&act=doMobileLogin' # Mobile login url
post_data = {
'mobile': self.mobile,
'password': self.password,
'remember': 'on'
}
else:
self.sid = str(sid)
self.number = str(account)
self.sid = sid
self.number = account
self.post_url = 'http://pocketuni.net/index.php?app=home&mod=Public&act=doLogin' # Sid and number login url
post_data = {
'sid': self.sid,
Expand All @@ -115,8 +115,8 @@ def verification(self): # Verify whether the login process is successful

def set_college(self, college, tribe): # Set user's college and tribe
self.college = college
self.tribe = tribe.split()
self.grade = '20' + re.search('\\d+', self.tribe[0])[0][:2]
self.tribe = tribe
self.grade = '20' + re.search('\\d+', self.tribe)[0][:2]

def get_college_list(self): # Get the college list of user's school
chrome_options = Options()
Expand All @@ -129,6 +129,7 @@ def get_college_list(self): # Get the college list of user's school
result = html.xpath('/html/body/div[2]/div/div[3]/div[2]/div[1]/div[1]/div[2]/a/text()')
return result

@property
def filtered_activities(self): # Filter out expired and other unavailable activities
p = 0
list_ = []
Expand All @@ -140,18 +141,18 @@ def filtered_activities(self): # Filter out expired and other unavailable activ

count = 0
for item in items:
if item['status'] != ['活动已结束']:
bool_ = False
if item['status'] != ['活动已结束'] and item['status'] !=['报名已结束']:
flag = False
info_activity = parse_one_activity(self.session.get(item['link']).text)
if info_activity['tribe'] is None:
if (self.college in info_activity['college']) or (info_activity['college'] == '全部'):
if (self.grade in info_activity['grade']) or (info_activity['grade'] == '全部'):
bool_ = True
flag = True
else:
for item_ in self.tribe:
if item_ in info_activity['tribe']:
bool_ = True
if bool_ is True:
flag = True
if flag is True:
list_.append(info_activity)
else:
count += 1
Expand Down

0 comments on commit 4721f07

Please sign in to comment.