Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 128 additions & 0 deletions HSS.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,132 @@ def default_timelineindex(self,number) -> int:
return None
UserData = UserData['userDatas'][number]
return UserData['defaultTimelineIndex']
def return_patch_data(self,id,key,grade,clas,date):
return {
"schoolId": id,
"bodies" : [{"headKey" : "userDatas",
"key" : key,
"grade" : grade,
"class" : clas,
"date" : date,
}]}

def patch_timetable(self,grade:int,clas:int,date:str,name:str,index=None,place=None)-> str:

"""
一週間の時間割変更するやつです。

----------
:param grade: 変更する学年
:param clas : 変更するクラス
:param date : 月:"mon",火:"tue","水":"wed",木:"thu",金:"fri",土:"sat",日:"sun"
:param index: 変更する時数
:param name : 教科名
:param place: 授業場所

:return: 変更に成功した場合、変更後の時間割
:rtype: json
:raises APIからのエラー
"""
ch ={"name" : name}
if place != None: ch["place"] = place
data = self.return_patch_data(self.schoolid,"timelineData",grade,clas,date)
data['bodies'][0]["value"] = ch
if index != None:
data['bodies'][0]['index'] = (index +1 )
url= "https://hss-dev.aknet.tech/v1/school"
response = Request_HSSAPI.patch_with_token(url, self.toke,data)
if errors.ErrorPrint.handle_http_error(response):
return response.text
datas = self.get_timeline(0,date)
return datas

def patch_homework(self,grade:int,clas:int,date:str,name:str,istoobig:bool,start:int,end:int,index=None,comment="")-> str:

"""
一週間の宿題を変更するやつです。

----------
:param grade: 変更する学年
:param clas : 変更するクラス
:param date : 月:"mon",火:"tue","水":"wed",木:"thu",金:"fri",土:"sat",日:"sun"
:param index: 変更する宿題の時数
:param name: 変更する宿題名
:param istoobig : 変更する宿題が大きいか
:param start:変更する宿題の開始ページ数
:param end: 変更する宿題の終了ページ数
:param comment : 補足

:return: 変更に成功した場合、変更後の時間割
:rtype: json
:raises APIからのエラー
"""
data ={
"schoolId": self.schoolid,
"bodies" : [{"headKey" : "userDatas",
"key" : "timelineData",
"grade" : grade,
"class" : clas,
"date" : date,
"value" : {
"homework" : [
{
"name": name,
"istoobig":istoobig,
"page":{
"start":start,
"end":end,
"comment":comment
}
}
]}}]}
if index != None:data['bodies'][0]['index'] = index

url= "https://hss-dev.aknet.tech/v1/school"
response = Request_HSSAPI.patch_with_token(url, self.toke,data)
if errors.ErrorPrint.handle_http_error(response):
return response.text
datas = self.get_timeline(0,date)
return datas

def patch_event(self,grade:int,clas:int,date:str,index,name:str,place="")-> str:

"""
一週間の時間割変更するやつです。

----------
:param grade: 変更する学年
:param clas : 変更するクラス
:param date : 月:"mon",火:"tue","水":"wed",木:"thu",金:"fri",土:"sat",日:"sun"

:param index: 変更する時数
:param name : 変更するイベント名
:param place: イベント場所
:param start: 開始時刻
:param end : 終了時刻
:param isEndofDay : 終日続くかどうか

:return: 変更に成功した場合、変更後の時間割
:rtype: json
:raises APIからのエラー
"""
data ={
"schoolId": self.schoolid,
"bodies" : [{"headKey" : "userDatas",
"key" : "timelineData",
"grade" : grade,
"class" : clas,
"date" : date,
"index" :index,
"value" : {
"name" : name,
"place" : place,
}}]}
url= "https://hss-dev.aknet.tech/v1/school"
response = Request_HSSAPI.patch_with_token(url, self.toke,data)
if errors.ErrorPrint.handle_http_error(response):
return response.text
datas = self.get_timeline(0,date)
return datas


14 changes: 8 additions & 6 deletions Request_HSSAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@ def get_with_token(url, token):
response = requests.get(url, headers=headers)
return response

def patch_with_token(url, token):
def patch_with_token(url, token,data):
headers = {
'Authorization':f"Bearer {token}"
'Authorization':f"Bearer {token}",
"Content-Type" : "application/json"
}
response = requests.patch(url, headers=headers)
response = requests.patch(url, headers= headers,json=data)
return response

def post_with_token(url, token):
def post_with_token(url, token,data):
headers = {
'Authorization':f"Bearer {token}"
'Authorization':f"Bearer {token}",
"Content-Type" : "application/json"
}
response = requests.post(url, headers=headers)
response = requests.post(url, headers=headers,data=data)
return response

def delete_with_token(url, token):
Expand Down
8 changes: 5 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from HSS import User, School
async def main():
token = "孤独のバカがTOKEN貼り付け"
token = "ne4iliC2NLKNIeSvZjpNGUcYiEUhGdIaAM8Ainjj4_Q"


# ユーザーの情報を取得
Expand All @@ -10,7 +10,7 @@ async def main():
print(schoolid)
print(userdata)

userdata = user.get_id(0000000000000000)
userdata = user.get_id(6392857473606222848)
print(userdata)

# # 学校の情報を取得
Expand All @@ -27,8 +27,10 @@ async def main():
mon = school.get_default_timeline(0, "tue")
print(mon)

index = school.default_TimelineIndex(0)
index = school.default_timelineindex(0)
print(index)
rep =school.patch_timetable(1,1,"mon","孤独は最強",5,"北海道札幌市")
print(rep)
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Expand Down
44 changes: 44 additions & 0 deletions tst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Request_HSSAPI
import json
token = "ne4iliC2NLKNIeSvZjpNGUcYiEUhGdIaAM8Ainjj4_Q"
url= "https://hss-dev.aknet.tech/v1/school"
data ={
"schoolId":"6392857634709439488",
"bodies" : [{"headKey" : "userDatas",
"key" : "timelineData",
"grade" : 1,
"class" : 1,
"date" : "mon",
"index" :1,
"value" : {
"name" : "教科名",
"place" : "場所です。 nullableです。",
"homework" : [
{
"name" : "s",
"istooBig" : True,
"page" : {
"start" : 1,
"end" : 2,
"comment" : "補足です。 nullableです。"
}
}
],

}}]}

data1 = data ={
"schoolId":"6392857634709439488",
"bodies" : [{"headKey" : "userDatas",
"key" : "timelineData",
"grade" : 1,
"class" : 1,
"date" : "mon",
"index" :1,
"value" : {
"name" : "教科名",
"place" : "場所です。 nullableです。",
}}]}
response = Request_HSSAPI.patch_with_token(url, token,data)

print(response.text)