diff --git a/HSS.py b/HSS.py index b300bac..c9d6e9c 100644 --- a/HSS.py +++ b/HSS.py @@ -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 + \ No newline at end of file diff --git a/Request_HSSAPI.py b/Request_HSSAPI.py index ecad75b..bb407e1 100644 --- a/Request_HSSAPI.py +++ b/Request_HSSAPI.py @@ -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): diff --git a/main.py b/main.py index d4fc228..0181fe0 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,6 @@ from HSS import User, School async def main(): - token = "孤独のバカがTOKEN貼り付け" + token = "ne4iliC2NLKNIeSvZjpNGUcYiEUhGdIaAM8Ainjj4_Q" # ユーザーの情報を取得 @@ -10,7 +10,7 @@ async def main(): print(schoolid) print(userdata) - userdata = user.get_id(0000000000000000) + userdata = user.get_id(6392857473606222848) print(userdata) # # 学校の情報を取得 @@ -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()) diff --git a/tst.py b/tst.py new file mode 100644 index 0000000..8e2fdc8 --- /dev/null +++ b/tst.py @@ -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)