-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add workflow * Update generate-index.yml * Update generate-index.yml * Update generate-index.yml * Update generate-index.yml * Update generate-index.yml * fix stupid bug * Update generate-index.yml * Update generate-index.yml * Update generate-index.yml * Update generate-index.yml * Update generate-index.yml * Update 博丽神社例大祭 in 台湾_ev-5.json * Revert "Update 博丽神社例大祭 in 台湾_ev-5.json" This reverts commit 10dc7e4. * Update generate-index.yml * Update generate-index.yml * Update niconico超会议_ev-14.json * Update generate-index.yml * Update generate-index.yml * Update generate-index.yml * Update generate-index.yml * Update generate-index.yml * Update generate-index.yml * Revert "Update niconico超会议_ev-14.json" This reverts commit 07d933c. * Update generate-index.yml * Update generate-index.yml * change trigger
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: generate-index | ||
run-name: Generate touhou.events archive index | ||
on: | ||
push: | ||
paths: | ||
- '*.json' | ||
branches: | ||
- main | ||
permissions: write-all | ||
jobs: | ||
generate-index: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Python 3.8 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
|
||
- name: Run Generate Index | ||
run: python mnt/generate-index.py | ||
env: | ||
WORKSPACE: ${{ github.workspace }} | ||
|
||
- name: Release | ||
uses: softprops/action-gh-release@v1 | ||
with: | ||
tag_name: latest | ||
files: 'mnt/indexes.json' | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
mnt/indexes.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import os | ||
import sys | ||
import json | ||
|
||
exclude_folder = [".git", ".github", "mnt", ".gitignore", "README.md"] | ||
rootPath = ( | ||
os.environ["WORKSPACE"] | ||
if "WORKSPACE" in os.environ | ||
else os.path.dirname(os.path.abspath(__file__)) | ||
) | ||
|
||
|
||
def scan_files(): | ||
files = [] | ||
for dirs in os.listdir(rootPath): | ||
if dirs in exclude_folder: | ||
continue | ||
for root, _, file in os.walk(os.path.join(rootPath, dirs)): | ||
for f in file: | ||
relative_path = os.path.relpath(os.path.join(root, f), rootPath) | ||
files.append(relative_path) | ||
return files | ||
|
||
|
||
def read_every_file_to_lists(files): | ||
file_data = [] | ||
for f in files: | ||
if f.endswith(".json"): | ||
with open(f, "r") as fileData: | ||
eventData = json.load(fileData) | ||
file_data.append(eventData) | ||
return file_data | ||
|
||
|
||
def generate_index(): | ||
files = scan_files() | ||
file_data = read_every_file_to_lists(files) | ||
with open(os.path.join(rootPath, "mnt", "indexes.json"), "w") as f: | ||
json.dump(file_data, f, indent=4, sort_keys=True, ensure_ascii=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
generate_index() |