├── requirements.txt ├── Makefile ├── README.md ├── setup.py ├── .gitignore ├── LICENSE └── librus └── __init__.py /requirements.txt: -------------------------------------------------------------------------------- 1 | . 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: release 2 | release: 3 | rm -rf dist/ 4 | . .venv/bin/activate && \ 5 | pip install setuptools twine wheel && \ 6 | ./setup.py sdist bdist_wheel && \ 7 | twine upload dist/* 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Librus API 2 | 3 | ## Usage 4 | 5 | ```python 6 | from librus import LibrusSession 7 | session = LibrusSession() 8 | session.login("1234567u", "p4ssw0rD") 9 | for announcement in session.list_announcements(): 10 | print(announcement.title) 11 | ``` 12 | 13 | ## API completeness 14 | 15 | 3%. Currently only announcements, messages and exams are covered. PRs welcomed. 16 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from setuptools import setup, find_packages 4 | 5 | setup( 6 | name='librus', 7 | description="Librus Synergia API", 8 | url="https://github.com/findepi/librus-api-python", 9 | version='0.0.15', 10 | packages=find_packages(), 11 | setup_requires=[ 12 | # 'pytest-runner==3.0', 13 | ], 14 | install_requires=[ 15 | 'requests-html', 16 | ], 17 | tests_require=[ 18 | # 'pytest==3.3.1', 19 | ], 20 | zip_safe=True, # just to silence setuptools 21 | python_requires='>=3', 22 | classifiers=[ 23 | "Programming Language :: Python :: 3", 24 | "Programming Language :: Python :: 3.7", 25 | "License :: OSI Approved :: Apache Software License", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | /.idea 3 | 4 | # Byte-compiled / optimized / DLL files 5 | __pycache__/ 6 | *.py[cod] 7 | *$py.class 8 | 9 | # C extensions 10 | *.so 11 | 12 | # Distribution / packaging 13 | .Python 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | wheels/ 26 | *.egg-info/ 27 | .installed.cfg 28 | *.egg 29 | MANIFEST 30 | 31 | # PyInstaller 32 | # Usually these files are written by a python script from a template 33 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 34 | *.manifest 35 | *.spec 36 | 37 | # Installer logs 38 | pip-log.txt 39 | pip-delete-this-directory.txt 40 | 41 | # Unit test / coverage reports 42 | htmlcov/ 43 | .tox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | 53 | # Translations 54 | *.mo 55 | *.pot 56 | 57 | # Django stuff: 58 | *.log 59 | local_settings.py 60 | db.sqlite3 61 | 62 | # Flask stuff: 63 | instance/ 64 | .webassets-cache 65 | 66 | # Scrapy stuff: 67 | .scrapy 68 | 69 | # Sphinx documentation 70 | docs/_build/ 71 | 72 | # PyBuilder 73 | target/ 74 | 75 | # Jupyter Notebook 76 | .ipynb_checkpoints 77 | 78 | # pyenv 79 | .python-version 80 | 81 | # celery beat schedule file 82 | celerybeat-schedule 83 | 84 | # SageMath parsed files 85 | *.sage.py 86 | 87 | # Environments 88 | .env 89 | .venv 90 | env/ 91 | venv/ 92 | ENV/ 93 | env.bak/ 94 | venv.bak/ 95 | 96 | # Spyder project settings 97 | .spyderproject 98 | .spyproject 99 | 100 | # Rope project settings 101 | .ropeproject 102 | 103 | # mkdocs documentation 104 | /site 105 | 106 | # mypy 107 | .mypy_cache/ 108 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /librus/__init__.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import requests_html 3 | from urllib.parse import urljoin 4 | 5 | 6 | class LibrusSession(object): 7 | 8 | def __init__(self): 9 | self._html_session = None 10 | 11 | def login(self, username, password): 12 | """ 13 | Creates authenticated session. 14 | """ 15 | 16 | self._html_session = requests_html.HTMLSession() 17 | self._html_session.get(url='https://api.librus.pl/OAuth/Authorization?client_id=46&response_type=code&scope=mydata') 18 | response = self._html_session.post(url='https://api.librus.pl/OAuth/Authorization?client_id=46', 19 | data={'action': 'login', 'login': username, 'pass': password}) 20 | if not response.json().get('status') == 'ok' or not response.json().get('goTo'): 21 | raise RuntimeError("Login failed") 22 | self._html_session.get(url=urljoin(response.url, response.json()['goTo'])) 23 | # TODO somehow validate the login was truly successful 24 | 25 | def list_announcements(self): 26 | """ 27 | Gets announcements (AKA 'ogłoszenia') 28 | """ 29 | response = self._html_session.get(url='https://synergia.librus.pl/ogloszenia') 30 | 31 | for element in response.html.find('table.decorated.big'): 32 | yield self._parse_announcement(element) 33 | 34 | def list_exams(self): 35 | """ 36 | Gets Exams from Calendar 37 | """ 38 | response = self._html_session.get(url="https://synergia.librus.pl/terminarz") 39 | # TODO we should be iterating explicitly over links to calendar items' details; doing unstructured "grepping" for now 40 | for element in response.html.search_all("szczegoly/{}'"): 41 | details = self._html_session.get(url=f"https://synergia.librus.pl/terminarz/szczegoly/{element[0]}") 42 | yield self._parse_exam(details.html.find('table.decorated.medium')) 43 | 44 | def list_absences(self): 45 | """ 46 | Get Absences (AKA 'nieobecnosci') 47 | """ 48 | response = self._html_session.get(url='https://synergia.librus.pl/przegladaj_nb/uczen') 49 | for element in response.html.search_all("szczegoly/{}'"): 50 | details = self._html_session.get(url=f"https://synergia.librus.pl/przegladaj_nb/szczegoly/{element[0]}") 51 | yield self._parse_absence(details.html.find('table.decorated.medium')) 52 | 53 | @staticmethod 54 | def _parse_exam(element): 55 | date = lesson = teacher = category = subject = classroom = specification = publish_date = interval = online_lesson_link = None 56 | for data_row in element[0].find("tbody tr"): 57 | description = _only_element(data_row.find('th')).full_text.strip() 58 | text = _sanitize_text(_only_element(data_row.find('td')).full_text.strip()) 59 | if description == "Data": 60 | assert date is None, "date already set" 61 | date = text 62 | 63 | elif description == "Nr lekcji": 64 | assert lesson is None, "lesson already set" 65 | lesson = text 66 | 67 | elif description == "Nauczyciel": 68 | assert teacher is None, "teacher already set" 69 | teacher = text 70 | 71 | elif description == "Rodzaj": 72 | assert category is None, "category already set" 73 | category = text 74 | 75 | elif description == "Przedmiot": 76 | assert subject is None, "subject already set" 77 | subject = text 78 | 79 | elif description == "Sala": 80 | assert classroom is None, "classroom already set" 81 | classroom = text 82 | 83 | elif description == "Opis": 84 | assert specification is None, "specification already set" 85 | specification = text 86 | 87 | elif description == "Data dodania": 88 | assert publish_date is None, "publish date already set" 89 | publish_date = text 90 | 91 | elif description == "Przedział czasu": 92 | assert interval is None, "interval already set" 93 | interval = text 94 | else: 95 | print(f"{repr(description)} is unrecognized") 96 | 97 | # for online lessons it additionally saves a link to zoom meeting 98 | if "lekcja online" in category and len(element[0].absolute_links) == 1: 99 | online_lesson_link = list(element[0].absolute_links)[0] 100 | 101 | return Exam(date, lesson, teacher, category, subject, 102 | classroom, specification, publish_date, interval, online_lesson_link) 103 | 104 | @staticmethod 105 | def _parse_announcement(element): 106 | title = _only_element(element.find('thead')).full_text.strip() 107 | content = author = date = None 108 | for data_row in element.find('tbody tr'): 109 | description = _only_element(data_row.find('th')).full_text.strip() 110 | text = _only_element(data_row.find('td')).full_text.strip() 111 | 112 | if description == "Dodał": 113 | assert author is None, "author already set" 114 | author = text 115 | 116 | elif description == "Treść": 117 | assert content is None, "content already set" 118 | content = text 119 | 120 | elif description == "Data publikacji": 121 | assert date is None, "date already set" 122 | date = datetime.datetime.strptime(text, '%Y-%m-%d') 123 | current_year = datetime.datetime.now().year 124 | assert current_year - 2 <= date.year <= current_year # Sanity check 125 | 126 | else: 127 | raise RuntimeError(f"{repr(description)} is unrecognized") 128 | 129 | return Announcement(title, content, author, date) 130 | 131 | def list_grades(self): 132 | response = self._html_session.get(url='https://synergia.librus.pl/przegladaj_oceny/uczen') 133 | grades = [] 134 | for grade_row in response.html.find('table.decorated.stretch')[1].find('tr.detail-grades'): 135 | grade_data = grade_row.find('td') 136 | grade = grade_data[0].text # ocena 137 | comment = grade_data[1].text # komentarz 138 | title = grade_data[2].text # tytuł oceny 139 | added_date = grade_data[3].text # data wstawienia 140 | teacher = grade_data[4].text # nauczyciel 141 | correction_grade = grade_data[5].text # poprawa oceny 142 | added_by = grade_data[6].text # dodał 143 | grades.append(Grade(grade, comment, title, added_date, teacher, correction_grade, added_by)) 144 | return grades 145 | 146 | def list_subject_semester_info(self): 147 | response = self._html_session.get(url='https://synergia.librus.pl/przegladaj_oceny/uczen') 148 | subjects = [] 149 | for subject in response.html.find('.line0') + response.html.find('.line1'): 150 | if len(subject.find('td')) == 10 and subject.find('td')[1].text != 'Ocena' and subject.find('td')[1].text != '1': 151 | subject_name = subject.find('td')[1].text 152 | grades_first_semester = subject.find('td')[2].text 153 | grade_first_semester_prediction = subject.find('td')[3].text 154 | grade_first_semester = subject.find('td')[4].text 155 | grades_second_semester = subject.find('td')[5].text 156 | grade_second_semester_prediction = subject.find('td')[6].text 157 | grade_second_semester = subject.find('td')[7].text 158 | grade_final_prediction = subject.find('td')[8].text 159 | grade_final = subject.find('td')[9].text 160 | subjects.append(SubjectSemesterInfo(subject_name, grades_first_semester, grade_first_semester_prediction, grade_first_semester, 161 | grades_second_semester, grade_second_semester_prediction, grade_second_semester, 162 | grade_final_prediction, grade_final)) 163 | return subjects 164 | 165 | def schedule(self): 166 | response = self._html_session.get(url='https://synergia.librus.pl/przegladaj_plan_lekcji') 167 | lessons = [] 168 | for subject_line in response.html.find('tr.line1'): 169 | index = subject_line.find('td')[0].text 170 | time = _sanitize_text(subject_line.find('th')[0].text) 171 | for day, cell in enumerate(subject_line.find('td')[1:]): 172 | if not cell.find('div.text'): 173 | continue 174 | subject_data = _only_element(cell.find('div.text')).text.split('-') 175 | subject_name = _sanitize_text(subject_data[0]) 176 | teacher = subject_data[1] 177 | classroom = None 178 | if 's.' in teacher: 179 | subject_data = teacher.split('s.') 180 | teacher = _sanitize_text(subject_data[0]) 181 | classroom = _sanitize_text(subject_data[1]) 182 | else: 183 | teacher = _sanitize_text(teacher) 184 | lessons.append(Lesson(day, index, subject_name, time, teacher, classroom)) 185 | lessons.sort(key=(lambda lesson: (lesson.day, lesson.index))) 186 | return lessons 187 | 188 | def list_messages(self, get_content=False): 189 | """ 190 | Gets messages (AKA 'wiadomości') 191 | """ 192 | response = self._html_session.get(url='https://synergia.librus.pl/wiadomosci') 193 | 194 | for row in response.html.find('.stretch > tbody > tr'): 195 | cells = row.find('td') 196 | messages_available = len(cells) >= 4 197 | if messages_available: 198 | href = cells[3].find('a')[0].attrs['href'] 199 | message = Message( 200 | message_id=href.strip(), 201 | sender=cells[2].text, 202 | subject=cells[3].text, 203 | sent_at=datetime.datetime.strptime(cells[4].text, '%Y-%m-%d %H:%M:%S'), 204 | is_read=('font-weight: bold' not in cells[3].attrs.get('style', '')) 205 | ) 206 | if get_content: 207 | url = 'https://synergia.librus.pl' + href 208 | content = self._html_session.get(url=url).html.find('.container-message-content')[0] 209 | message.content = content.text 210 | 211 | yield message 212 | 213 | @staticmethod 214 | def _parse_absence(element): 215 | category = date = subject = topic = lesson = teacher = school_trip = added_by = None 216 | for data_row in element[0].find('tbody tr'): 217 | if not data_row.find('th'): 218 | continue 219 | description = _only_element(data_row.find('th')).full_text.strip() 220 | text = _sanitize_text(_only_element(data_row.find('td')).full_text.strip()) 221 | if description == "Data": 222 | assert date is None, "date already set" 223 | date = text 224 | 225 | elif description == "Godzina lekcyjna": 226 | assert lesson is None, "lesson already set" 227 | lesson = text 228 | 229 | elif description == "Nauczyciel": 230 | assert teacher is None, "teacher already set" 231 | teacher = text 232 | 233 | elif description == "Rodzaj": 234 | assert category is None, "category already set" 235 | category = text 236 | 237 | elif description == "Przedmiot": 238 | assert subject is None, "subject already set" 239 | subject = text 240 | elif description == "Temat zajęć": 241 | assert topic is None, "topic already set" 242 | topic = text 243 | elif description == "Czy wycieczka": 244 | assert school_trip is None, "school_trip already set" 245 | school_trip = text 246 | elif description == "Dodał": 247 | assert added_by is None, "added_by already set" 248 | added_by = text 249 | else: 250 | print(f"{repr(description)} is unrecognized") 251 | 252 | return Absence(date, lesson, teacher, category, subject, topic, school_trip, added_by) 253 | 254 | 255 | class Announcement(object): 256 | def __init__(self, title, content, author, date): 257 | self.title = title 258 | self.content = content 259 | self.author = author 260 | self.date = date 261 | 262 | 263 | class Exam(object): 264 | def __init__(self, date, lesson, teacher, category, subject, 265 | classroom, specification, publish_date, interval, online_lesson_link=None): 266 | self.date = date 267 | self.lesson = lesson 268 | self.teacher = teacher 269 | self.category = category 270 | self.subject = subject 271 | self.classroom = classroom 272 | self.specification = specification 273 | self.publish_date = publish_date 274 | self.interval = interval 275 | self.online_lesson_link = online_lesson_link 276 | 277 | 278 | class Grade(object): 279 | def __init__(self, grade, comment, title, added_date, teacher, correction_grade, added_by): 280 | self.grade = grade 281 | self.comment = comment 282 | self.title = title 283 | self.added_date = added_date 284 | self.teacher = teacher 285 | self.correction_grade = correction_grade 286 | self.added_by = added_by 287 | 288 | 289 | class SubjectSemesterInfo(object): 290 | def __init__(self, subject_name, grades_first_semester, grade_first_semester_prediction, grade_first_semester, grades_second_semester, 291 | grade_second_semester_prediction, grade_second_semester, grade_final_prediction, grade_final): 292 | self.subject_name = subject_name 293 | self.grades_first_semester = grades_first_semester 294 | self.grade_first_semester_prediction = grade_first_semester_prediction 295 | self.grade_first_semester = grade_first_semester 296 | self.grades_second_semester = grades_second_semester 297 | self.grade_second_semester_prediction = grade_second_semester_prediction 298 | self.grade_second_semester = grade_second_semester 299 | self.grade_final_prediction = grade_final_prediction 300 | self.grade_final = grade_final 301 | 302 | 303 | class Lesson(object): 304 | def __init__(self, day, index, subject, time, teacher, classroom): 305 | self.day = day 306 | self.index = index 307 | self.name = subject 308 | self.time = time 309 | self.teacher = teacher 310 | self.classroom = classroom 311 | 312 | 313 | class Message(object): 314 | def __init__(self, message_id, sender, subject, sent_at, is_read): 315 | self.message_id = message_id 316 | self.sender = sender 317 | self.subject = subject 318 | self.sent_at = sent_at 319 | self.is_read = is_read 320 | self.content = None 321 | 322 | 323 | class Absence(object): # nieobecność 324 | def __init__(self, date, lesson, teacher, category, subject, topic, school_trip, added_by): 325 | self.date = date 326 | self.lesson = lesson 327 | self.teacher = teacher 328 | self.category = category 329 | self.subject = subject 330 | self.topic = topic 331 | self.school_trip = school_trip 332 | self.added_by = added_by 333 | 334 | 335 | def _only_element(values): 336 | value, = values 337 | return value 338 | 339 | 340 | def _sanitize_text(text): 341 | text = text.replace('\N{NO-BREAK SPACE}', ' ') 342 | text = text.replace(' ', ' ') 343 | text = text.replace(' ', ' ') 344 | text = text.strip() 345 | return text 346 | 347 | --------------------------------------------------------------------------------