Skip to content

Commit

Permalink
添加版本文件
Browse files Browse the repository at this point in the history
  • Loading branch information
youyou-sudo committed Sep 13, 2024
1 parent 57d2e6a commit 184611b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
36 changes: 35 additions & 1 deletion .github/workflows/vndb-process.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
run: |
python script/vn_data_json.py
- name: Upload to GitHub Release
- name: Upload vn_data.json to GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down Expand Up @@ -68,3 +68,37 @@ jobs:
"https://uploads.github.com/repos/$REPO/releases/$RELEASE_ID/assets?name=$FILE_NAME")
echo "Response: $RESPONSE"
- name: Upload timeVersion.json to GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Define variables
RELEASE_TAG="v1.0.0"
FILE_PATH="timeVersion.json"
FILE_NAME="timeVersion.json"
REPO="youyou-sudo/vndb-search-datas"
# Get the release ID
RELEASE_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/releases/tags/$RELEASE_TAG" | jq -r '.id')
# Get the asset ID for the old file
ASSET_ID=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/releases/$RELEASE_ID/assets" | jq -r '.[] | select(.name == "'"$FILE_NAME"'") | .id')
# Delete the old file
if [ "$ASSET_ID" != "null" ]; then
curl -s -X DELETE -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO/releases/assets/$ASSET_ID"
fi
# Upload the new file
RESPONSE=$(curl -s -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "Content-Type: application/zip" \
--data-binary @"$FILE_PATH" \
"https://uploads.github.com/repos/$REPO/releases/$RELEASE_ID/assets?name=$FILE_NAME")
echo "Response: $RESPONSE"
13 changes: 8 additions & 5 deletions script/vn_data_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ def clean_entry(entry):
for release in entry['releases']:
clean_entry(release)


def tsv_to_json(vn_tsv_file_path, vn_titles_tsv_file_path, releases_titles_tsv_file_path, releases_vn_tsv_file_path,
releases_file_path, json_file_path):
releases_file_path, json_file_path, timestamp_file_path):
# 使用defaultdict来组织数据
vn_data = defaultdict(
lambda: {"id": None, "titles": [], "image": None, "olang": None, "alias": [], "releases": []})
Expand Down Expand Up @@ -164,12 +163,16 @@ def tsv_to_json(vn_tsv_file_path, vn_titles_tsv_file_path, releases_titles_tsv_f
"data": transformed_data_list
}

# 将数据转换为JSON格式并写入文件
# 将数据转换为JSON格式并写入主文件
with open(json_file_path, 'w', encoding='utf-8') as json_file:
json.dump(output_data, json_file, ensure_ascii=False, indent=4)

# 输出一个只有时间戳的 JSON 文件
timestamp_data = {"timeVersion": timestamp}
with open(timestamp_file_path, 'w', encoding='utf-8') as timestamp_file:
json.dump(timestamp_data, timestamp_file, ensure_ascii=False, indent=4)


# 使用示例
tsv_to_json('./vndb_data/db/vn', './vndb_data/db/vn_titles', './vndb_data/db/releases_titles',
'./vndb_data/db/releases_vn',
'./vndb_data/db/releases', 'vn_data.json')
'./vndb_data/db/releases_vn', './vndb_data/db/releases', 'vn_data.json', 'timeVersion.json')

0 comments on commit 184611b

Please sign in to comment.