mirror of
https://github.com/NotXia/unibo-ai-notes.git
synced 2025-12-15 19:12:22 +01:00
Moved readme updater
This commit is contained in:
30
.github/read_metadata.py
vendored
Normal file
30
.github/read_metadata.py
vendored
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
def readMetadata(src_path, gh_link="", metadata_file_name="metadata.json"):
|
||||||
|
notes_metadata = {}
|
||||||
|
|
||||||
|
# Reads courses metadata
|
||||||
|
for root, _, files in os.walk(src_path):
|
||||||
|
if metadata_file_name in files:
|
||||||
|
with open(os.path.join(root, metadata_file_name)) as f:
|
||||||
|
metadata = json.load(f)
|
||||||
|
dir_name = os.path.relpath(root, src_path)
|
||||||
|
gh_path = os.path.join(gh_link, dir_name)
|
||||||
|
|
||||||
|
if metadata["year"] not in notes_metadata: notes_metadata[metadata["year"]] = {}
|
||||||
|
if metadata["semester"] not in notes_metadata[metadata["year"]]: notes_metadata[metadata["year"]][metadata["semester"]] = {}
|
||||||
|
|
||||||
|
notes_metadata[metadata["year"]][metadata["semester"]][metadata["name"]] = {
|
||||||
|
"name": metadata["name"],
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"name": pdf["name"],
|
||||||
|
"url": os.path.join(gh_path, pdf["path"])
|
||||||
|
}
|
||||||
|
for pdf in metadata["pdfs"]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
return notes_metadata
|
||||||
@ -1,9 +1,5 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import os
|
from read_metadata import readMetadata
|
||||||
import pathlib
|
|
||||||
import json
|
|
||||||
|
|
||||||
METADATA_FILENAME = "metadata.json"
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -13,29 +9,7 @@ if __name__ == "__main__":
|
|||||||
parser.add_argument("--gh-link", type=str, required=True, help="Link to the GitHub repo")
|
parser.add_argument("--gh-link", type=str, required=True, help="Link to the GitHub repo")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
notes_metadata = {}
|
notes_metadata = readMetadata(args.src_path, args.gh_link)
|
||||||
|
|
||||||
# Reads courses metadata
|
|
||||||
for root, dirs, files in os.walk(args.src_path):
|
|
||||||
if METADATA_FILENAME in files:
|
|
||||||
with open(os.path.join(root, METADATA_FILENAME)) as f:
|
|
||||||
metadata = json.load(f)
|
|
||||||
dir_name = os.path.relpath(root, args.src_path)
|
|
||||||
gh_path = os.path.join(args.gh_link, dir_name)
|
|
||||||
|
|
||||||
if metadata["year"] not in notes_metadata: notes_metadata[metadata["year"]] = {}
|
|
||||||
if metadata["semester"] not in notes_metadata[metadata["year"]]: notes_metadata[metadata["year"]][metadata["semester"]] = {}
|
|
||||||
|
|
||||||
notes_metadata[metadata["year"]][metadata["semester"]][metadata["name"]] = {
|
|
||||||
"name": metadata["name"],
|
|
||||||
"content": [
|
|
||||||
{
|
|
||||||
"name": pdf["name"],
|
|
||||||
"url": os.path.join(gh_path, pdf["path"])
|
|
||||||
}
|
|
||||||
for pdf in metadata["pdfs"]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
# Appends links to README
|
# Appends links to README
|
||||||
with open(args.readme_path, "a") as readme_f:
|
with open(args.readme_path, "a") as readme_f:
|
||||||
13
.github/workflows/compile.yml
vendored
13
.github/workflows/compile.yml
vendored
@ -4,7 +4,7 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths: ["src/**", .github/workflows/**, compile.sh]
|
paths: ["src/**", .github/**, compile.sh]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
compile:
|
compile:
|
||||||
@ -32,17 +32,20 @@ jobs:
|
|||||||
|
|
||||||
- name: Prepare output directory
|
- name: Prepare output directory
|
||||||
run: |
|
run: |
|
||||||
mkdir .compiled
|
mkdir ${GITHUB_WORKSPACE}/.compiled
|
||||||
cp LICENSE .compiled
|
cp ${GITHUB_WORKSPACE}/LICENSE ${GITHUB_WORKSPACE}/.compiled
|
||||||
|
|
||||||
- name: Compile
|
- name: Compile
|
||||||
run: |
|
run: |
|
||||||
bash ./utils/compile.sh src .compiled .currpdfs
|
bash ${GITHUB_WORKSPACE}/utils/compile.sh src ${GITHUB_WORKSPACE}/.compiled ${GITHUB_WORKSPACE}/.currpdfs
|
||||||
|
|
||||||
- name: Generate README
|
- name: Generate README
|
||||||
run: |
|
run: |
|
||||||
cp README.md .compiled/README.md
|
cp README.md .compiled/README.md
|
||||||
python3 ./utils/update_readme.py --src-path ./src --readme-path .compiled/README.md --gh-link https://github.com/NotXia/unibo-ai-notes/blob/pdfs
|
python3 ${GITHUB_WORKSPACE}/.github/update_readme.py \
|
||||||
|
--src-path ${GITHUB_WORKSPACE}/src \
|
||||||
|
--readme-path ${GITHUB_WORKSPACE}/.compiled/README.md \
|
||||||
|
--gh-link https://github.com/NotXia/unibo-ai-notes/blob/pdfs
|
||||||
|
|
||||||
|
|
||||||
- name: Move to pdfs branch
|
- name: Move to pdfs branch
|
||||||
|
|||||||
Reference in New Issue
Block a user