From d5a7baed00a15e2691aa137f5c604eb278ff1f5d Mon Sep 17 00:00:00 2001 From: NateScarlet Date: Sun, 10 Oct 2021 02:59:32 +0800 Subject: [PATCH] fix: ics file change not trigger release --- update.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/update.py b/update.py index 2b9df7b..5bb48f8 100755 --- a/update.py +++ b/update.py @@ -8,6 +8,7 @@ import re import subprocess from datetime import datetime, timedelta, tzinfo from tempfile import mkstemp +from typing import Iterator from zipfile import ZipFile from tqdm import tqdm @@ -37,18 +38,12 @@ def _file_path(*other): return os.path.join(__dirname__, *other) -def update_data(year: int) -> str: - """Update and store data for a year. +def update_data(year: int) -> Iterator[str]: + """Update and store data for a year.""" - Args: - year (int): Year - - Returns: - str: Stored data path - """ - - filename = _file_path(f"{year}.json") - with open(filename, "w", encoding="utf-8", newline="\n") as f: + json_filename = _file_path(f"{year}.json") + ics_filename = _file_path(f"{year}.ics") + with open(json_filename, "w", encoding="utf-8", newline="\n") as f: data = fetch_holiday(year) json.dump( @@ -71,8 +66,9 @@ def update_data(year: int) -> str: cls=CustomJSONEncoder, ) - generate_ics(data["days"], filename=f"{year}.ics") - return filename + yield json_filename + generate_ics(data["days"], ics_filename) + yield ics_filename def update_main_ics(fr_year, to_year): @@ -85,10 +81,12 @@ def update_main_ics(fr_year, to_year): data = json.loads(inf.read()) all_days.extend(data.get("days")) + filename = _file_path("holiday-cn.ics") generate_ics( all_days, - filename="holiday-cn.ics", + filename, ) + return filename def main(): @@ -112,12 +110,11 @@ def main(): progress = tqdm(range(2007 if args.all else now.year, now.year + 2)) for i in progress: progress.set_description(f"Updating {i} data") - filename = update_data(i) - filenames.append(filename) + filenames += list(update_data(i)) + progress.set_description("Updating holiday-cn.ics") + filenames.append(update_main_ics(now.year - 4, now.year + 1)) print("") - update_main_ics(now.year - 4, now.year + 1) - subprocess.run(["hub", "add", *filenames], check=True) diff = subprocess.run( ["hub", "diff", "--stat", "--cached", "*.json", "*.ics"],