Fix update.py

This commit is contained in:
NateScarlet 2019-03-09 19:50:28 +08:00
parent ea1a247bc0
commit 482be408af
No known key found for this signature in database
GPG Key ID: 5C242793B070309C

View File

@ -86,21 +86,25 @@ def main():
print('Already up to date.') print('Already up to date.')
return return
tag = now.strftime('%Y.%m.%d')
temp_note_fd, temp_note_name = mkstemp() temp_note_fd, temp_note_name = mkstemp()
with open(temp_note_fd, 'w', encoding='utf-8') as f: with open(temp_note_fd, 'w', encoding='utf-8') as f:
f.write(now.strftime('%Y.%m.%d') + '\n\n```diff' + diff + '\n```') f.write(tag + '\n\n```diff' + diff + '\n```')
temp_zip_fd, temp_zip_name = mkstemp() temp_zip_fd, temp_zip_name = mkstemp(suffix='.zip')
with open(temp_zip_fd, 'w', encoding='utf-8') as f: f = open(temp_zip_fd, 'wb')
pack_data(f) pack_data(f)
f.close()
subprocess.run(['hub', 'release', 'create', '-F', temp_note_name, subprocess.run(['hub', 'release', 'create', '-F', temp_note_name,
'-a', temp_zip_name + '#JSON数据打包', '-a', f'{temp_zip_name}#holiday-cn-{tag}.zip',
now.strftime('%Y.%m.%d')], check=True) tag], check=True)
os.unlink(temp_note_fd) os.unlink(temp_note_fd)
os.unlink(temp_note_name) os.unlink(temp_note_name)
def pack_data(file): def pack_data(file):
"""Pack data json in zip file. """
zip_file = ZipFile(file, 'w') zip_file = ZipFile(file, 'w')
for i in os.listdir(__dirname__): for i in os.listdir(__dirname__):
if not re.match(r'\d+\.json', i): if not re.match(r'\d+\.json', i):