├── .github └── workflows │ └── content.yaml ├── README.md ├── load.py ├── notionclientwhocandownload.py └── requirements.txt /.github/workflows/content.yaml: -------------------------------------------------------------------------------- 1 | name: Build content 2 | on: 3 | push: 4 | branches: 5 | - main 6 | schedule: 7 | - cron: '0 0 1 * *' 8 | 9 | 10 | jobs: 11 | build-and-deploy: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@v2.3.1 # If you're using actions/checkout@v2 you must set persist-credentials to false in most cases for the deployment to work correctly. 16 | with: 17 | persist-credentials: false 18 | - name: Setup Python 3.9 19 | uses: actions/setup-python@v2 20 | with: 21 | python-version: 3.9 #install the python needed 22 | - name: Install Python dependencies 23 | uses: py-actions/py-dependency-install@v2 24 | - name: Execute load.py # run the run.py to get the latest data 25 | run: | 26 | python load.py 27 | env: 28 | NOTION_V2: ${{ secrets.NOTION_V2 }} 29 | - name: Copy content 30 | uses: JamesIves/github-pages-deploy-action@3.7.1 31 | with: 32 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 33 | BRANCH: content # The branch the action should deploy to. 34 | FOLDER: pdf # The folder the action should deploy. 35 | CLEAN: true # Automatically remove deleted files from the deploy branch 36 | COMMIT_MESSAGE: "copy pdf files to content branch" 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nsu-cheatsheet 2 | Репозиторий со всеми шпаргалками, которые я делал для учебы. 3 | 4 | Часть автоматически экспортируется с Notion. 5 | 6 | Все полезные файлы лежат в ветке `content`, в ветке `main` только скрипты для сборки. 7 | 8 | Если нашли ошибку или опечатку, оставьте issue или напишите мне. PDF обновляются с notion каждый день. 9 | 10 | Ставим звезды, подписываемся на аккаунт, скидываем донаты... 11 | 12 | 13 | ## 6 семестр (весна 2022) 14 | ### Инженерная графика: 15 | 1. [Репозиторий с лабораторными работами](https://github.com/zpix1/nsu-graphic-labs) 16 | 17 | ## 5 семестр (осень 2021) 18 | ### ОС: 19 | 1. [Репозиторий с лабораторными работами](https://github.com/zpix1/nsu-tr-labs) 20 | 21 | ### МТК 22 | 1. [Репозиторий с лабораторными работами](https://github.com/zpix1/nsu-mtk-labs/) 23 | 24 | ### Сети (2 семестр) 25 | 26 | 1. [Репозиторий с лабораторными работами](https://github.com/zpix1/nsu-socket-labs/) 27 | 28 | ## 4 семестр (весна 2021) 29 | ### ТВ и МС: 30 | 1. [Список определений по теории вероятностей](https://raw.githubusercontent.com/zpix1/nsu-cheatsheet/content/NSU-PUBLIC/4%20семестр/ТВ%20и%20МС/Список%20по%20ТВ.pdf) 31 | 2. [Список определений по математической статистике](https://raw.githubusercontent.com/zpix1/nsu-cheatsheet/content/NSU-PUBLIC/4%20семестр/ТВ%20и%20МС/Список%20по%20МС.pdf) 32 | 3. [Расписанные билеты к экзамену](https://github.com/zpix1/nsu-cheatsheet/blob/content/NSU-PUBLIC/4%20%D1%81%D0%B5%D0%BC%D0%B5%D1%81%D1%82%D1%80/%D0%A2%D0%92%20%D0%B8%20%D0%9C%D0%A1/%D0%91%D0%B8%D0%BB%D0%B5%D1%82%D1%8B/%D0%91%D0%B8%D0%BB%D0%B5%D1%82%D1%8B.md) 33 | 34 | ### ОС: 35 | 1. [Репозиторий с лабораторными работами](https://github.com/zpix1/nsu-os-labs) 36 | 37 | ### ООП (Java): 38 | 1. [Репозиторий с лабораторными работами](https://github.com/zpix1/nsu-java-labs) 39 | 40 | ### ОПП 41 | 1. [Репозиторий с лабораторными работами](https://github.com/zpix1/nsu-opp-labs/) 42 | 43 | ### Сети (1 семестр) 44 | 45 | 1. [Репозиторий с лабораторными работами](https://github.com/zpix1/nsu-network-labs/) 46 | 47 | ## Еще 48 | Смотрите файлы за другие семестры по [ссылке](https://github.com/zpix1/nsu-cheatsheet/blob/content/NSU-PUBLIC/NSU-PUBLIC.md). 49 | ## P.S. 50 | ### Благодарности 51 | **TODO** 52 | -------------------------------------------------------------------------------- /load.py: -------------------------------------------------------------------------------- 1 | from notionclientwhocandownload import NotionClientWhoCanDownload 2 | import pathlib 3 | import os 4 | from urllib.parse import quote 5 | 6 | client = NotionClientWhoCanDownload(token_v2=os.environ.get('NOTION_V2')) 7 | 8 | CONTENT_BRANCH_PDF_PREFIX = 'https://raw.githubusercontent.com/zpix1/nsu-cheatsheet/content/' 9 | CONTENT_BRANCH_DIR_PREFIX = 'https://github.com/zpix1/nsu-cheatsheet/tree/content/' 10 | 11 | page = client.get_block('https://www.notion.so/zpix/NSU-PUBLIC-033de7a6eece42c8af52bcf63ad540e5') 12 | 13 | def page_children(page): 14 | result = [] 15 | if page.type == 'collection_view_page': 16 | for c in page.collection.get_rows(): 17 | if c.get_property('status') == 'Completed': 18 | result.append(c) 19 | else: 20 | return [child for child in page.children if child.type in ('page', 'collection_view_page') ] 21 | return result 22 | 23 | def load_page_tree(page, path): 24 | print(f'Loading {page.title} to {path}') 25 | if len(page_children(page)) != 0: 26 | print(f'Found {len(page_children(page))} children, creating subdir + README') 27 | subdir = path / page.title 28 | subdir.mkdir(parents=True, exist_ok=True) 29 | page_list = f'' 30 | for i, child in enumerate(page_children(page)): 31 | print(f'Child {child.title}') 32 | if load_page_tree(child, subdir): 33 | child_path = subdir / f'{child.title}.pdf' 34 | page_list += f'* [{child.title}]({CONTENT_BRANCH_PDF_PREFIX}{quote(str(child_path))})\n' 35 | else: 36 | child_path = subdir / child.title / f'{child.title}.md' 37 | page_list += f'* [{child.title}]({CONTENT_BRANCH_DIR_PREFIX}{quote(str(child_path))})\n' 38 | 39 | with open(subdir / f'{page.title}.md', 'w') as f: 40 | f.write(f'### {page.title}\n' + page_list) 41 | else: 42 | print(f'No children found, a regular page, exporting') 43 | export_path = path / f'{page.title}.pdf' 44 | client.download_block(page.id, export_path, export_type='pdf') 45 | return True 46 | return False 47 | 48 | if __name__ == '__main__': 49 | pathlib.Path('./pdf').mkdir(exist_ok=True) 50 | os.chdir('./pdf') 51 | load_page_tree(page, pathlib.Path('.')) 52 | 53 | # for child in page.children: 54 | # print(f'Loading {child.title}') 55 | # pathlib.Path('pdf').mkdir(parents=True, exist_ok=True) 56 | # path = f'pdf/{child.title}.pdf' 57 | # client.download_block(child.id, path, export_type='pdf') -------------------------------------------------------------------------------- /notionclientwhocandownload.py: -------------------------------------------------------------------------------- 1 | from notion.client import NotionClient 2 | 3 | from requests import get 4 | import time 5 | import os 6 | from zipfile import ZipFile 7 | class NotionClientWhoCanDownload(NotionClient): 8 | def _get_task_id(self, response): 9 | """ 10 | When you export a file, notion creates a task to make the file with the 'enqueueTask' endpoint. 11 | Then another method looks at the task ID and returns the file when the task finishes. 12 | So, we need to save the taskId into a variable. This is a helper function to do that. 13 | """ 14 | return response.json()['taskId'] 15 | 16 | # Source from https://requests.readthedocs.io/en/master/user/quickstart/#raw-response-content 17 | def _download_url(self, url, save_path, chunk_size=128): 18 | """ 19 | Downloads the zip file and saves it to a file. 20 | url - string of the url from which to download. 21 | save_path - string of the file name to output the zip file into. 22 | chunk_size = size of the chunk. This is adjustable. See the documentation for more info. 23 | """ 24 | r = get(url, stream=True) 25 | with open(save_path, 'wb') as fd: 26 | for chunk in r.iter_content(chunk_size=chunk_size): 27 | fd.write(chunk) 28 | 29 | def _unzip_file(self, file, delete=True): 30 | """ 31 | Helper function to unzip the zipped download. 32 | file - string of the zip file name 33 | delete - delete the zip file or not. 34 | """ 35 | with ZipFile(file) as zipObj: 36 | zipObj.extractall() 37 | if delete: 38 | os.remove(file) 39 | 40 | def download_block( 41 | self, 42 | block_id: str, 43 | path: str, 44 | recursive: bool = False, 45 | export_type: str = "markdown", 46 | time_zone: str = "America/Chicago", 47 | locale: str = "en", 48 | ): 49 | """ 50 | Download block. 51 | 52 | TODO: Add support for downloading a list of blocks. 53 | 54 | 55 | Arguments 56 | --------- 57 | block_id : str 58 | ID of the block. 59 | 60 | recursive : bool, optional 61 | Whether or not to include sub pages. 62 | Defaults to False. 63 | 64 | export_type : str 65 | Type of the output file. 66 | The options are "markdown", "pdf", "html". 67 | Defaults to "markdown". 68 | 69 | time_zone : str, optional 70 | I don't know what values go here. I'm in the Chicago 71 | timezone (central) and this is what I saw in the request. 72 | Defaults to "America/Chicago". 73 | TODO: test? hard code? 74 | 75 | locale : str, optional 76 | Locale for the export. 77 | Defaults to "en". 78 | """ 79 | data = { 80 | "task": { 81 | "eventName": "exportBlock", 82 | "request": { 83 | "blockId": block_id, 84 | "recursive": recursive, 85 | "exportOptions": { 86 | "exportType": export_type, 87 | "timeZone": time_zone, 88 | "locale": locale, 89 | }, 90 | }, 91 | } 92 | } 93 | 94 | if export_type in ["pdf", "html"]: 95 | data["task"]["request"]["exportOptions"]["pdfFormat"] = "A4" 96 | 97 | def fetch(): 98 | time.sleep(0.1) 99 | return self.post("getTasks", {"taskIds": task_ids}).json() 100 | 101 | task_ids = [self.post("enqueueTask", data).json()["taskId"]] 102 | task = fetch() 103 | 104 | # Ensure that we're getting the data when it's ready. 105 | while "status" not in task["results"][0]: 106 | task = fetch() 107 | 108 | while "exportURL" not in task["results"][0]["status"]: 109 | task = fetch() 110 | 111 | url = task["results"][0]["status"]["exportURL"] 112 | self._download_url(url, path) -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | notion==0.0.28 2 | requests --------------------------------------------------------------------------------