modify the struct of schedule
This commit is contained in:
parent
bac05cb9df
commit
c1b10eeac0
@ -3,6 +3,7 @@ import requests
|
||||
from urllib.parse import quote
|
||||
import base64
|
||||
from bs4 import BeautifulSoup
|
||||
import random
|
||||
|
||||
def connection(username,password):
|
||||
s = requests.Session()
|
||||
@ -64,36 +65,65 @@ def getSchedule(Ip, S):
|
||||
return {'errcode': 102, 'errmsg':'教务挂了'}
|
||||
time = ['AM__TimePieces','PM__TimePieces','EV__TimePieces']
|
||||
data = data['data']['AdjustDays']
|
||||
data_cache = [[0] * 7 for _ in range(6)]
|
||||
days_per_week = [0] * 23
|
||||
lesson = [[0] * 7 for _ in range(6)]
|
||||
colors = [0] * 10
|
||||
color_set = {}
|
||||
for i in range(7):
|
||||
for j in range(3):
|
||||
for k in range(2):
|
||||
if( data[i][time[j]][k]['Dtos'] ):
|
||||
data_cache[j*2+k][i] = []
|
||||
lesson[j*2+k][i] = []
|
||||
for l in data[i][time[j]][k]['Dtos']:
|
||||
temp_lesson = {}
|
||||
Time = [0] * 23
|
||||
mod = ''
|
||||
for m in l['Content']:
|
||||
if temp_lesson.get(m['Key']):
|
||||
temp_lesson[m['Key']] += ','+m['Name']
|
||||
else:
|
||||
temp_lesson[m['Key']] = m['Name']
|
||||
if color_set.get(temp_lesson['Lesson']):
|
||||
temp_lesson['color'] = color_set.get(temp_lesson['Lesson'])
|
||||
else:
|
||||
color = random.randint(0,9)
|
||||
if colors[color] == 1:
|
||||
color = random.randint(0,9)
|
||||
else:
|
||||
colors[color] = 1
|
||||
temp_lesson['color'] = color
|
||||
color_set[temp_lesson['Lesson']] = color
|
||||
temp_Time = temp_lesson['Time']
|
||||
if '单周' in temp_Time:
|
||||
temp_lesson['mod'] = 'single'
|
||||
mod = 'single'
|
||||
temp_Time = temp_Time[0:len(temp_Time)-5]
|
||||
elif '双周' in temp_Time:
|
||||
temp_lesson['mod'] = 'double'
|
||||
mod = 'double'
|
||||
temp_Time = temp_Time[0:len(temp_Time)-5]
|
||||
else:
|
||||
temp_lesson['mod'] = 'all'
|
||||
mod = 'all'
|
||||
temp_Time = temp_Time[0:-1]
|
||||
temp_Time = temp_Time.split(',')
|
||||
index = 0
|
||||
for n in temp_Time:
|
||||
temp_Time[index] = n.split('-')
|
||||
index += 1
|
||||
temp_lesson['Time']=temp_Time
|
||||
data_cache[j*2+k][i].append(temp_lesson)
|
||||
index = 0
|
||||
for n in temp_Time:
|
||||
if len(n) > 1 :
|
||||
for o in range( int(n[0]) , int(n[1]) + 1):
|
||||
if ( o%2==0 and mod is 'double' ) or ( o%2==1 and mod is 'single' ) or ( mod is 'all' ):
|
||||
days_per_week[o] = max(days_per_week[o] , i+1)
|
||||
Time[o] = 1
|
||||
else:
|
||||
Time[o] = 0
|
||||
else:
|
||||
days_per_week[n[0]] = max(days_per_week[n[0]] , i+1)
|
||||
Time[n[0]] = 1
|
||||
index += 1
|
||||
temp_lesson['Time'] = Time
|
||||
lesson[j*2+k][i].append(temp_lesson)
|
||||
data_cache = {'lesson':lesson,'days_per_week':days_per_week}
|
||||
return {'errcode': 200, 'errmsg': 'ok', 'data': data_cache}
|
||||
|
||||
def getCurrentTime(Ip, S):
|
||||
@ -105,4 +135,10 @@ def getCurrentTime(Ip, S):
|
||||
)
|
||||
data = json.loads(r.content.decode('utf-8'))
|
||||
data_cache = data['data'].pop('DateList')
|
||||
return {'errcode': 200, 'errmsg': 'ok', 'data': data_cache}
|
||||
return {'errcode': 200, 'errmsg': 'ok', 'data': data_cache}
|
||||
|
||||
data = connection("2018002129","cust5313.")
|
||||
data = getSchedule(data['ip'],data['s'])
|
||||
for d in data['data']['lesson']:
|
||||
print(d)
|
||||
print(data['data']['days_per_week'])
|
Loading…
x
Reference in New Issue
Block a user