Skip to content

Commit f16e9d1

Browse files
committed
[TUT-65] python script 추가 - README를 복사해 옴
1 parent 3270289 commit f16e9d1

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

scripts/maintenance.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
import argparse
4+
import os
5+
import re
6+
import shutil
7+
import sys
8+
import tempfile
9+
import urllib
10+
from itertools import islice
11+
from pathlib import Path
12+
13+
from bs4 import BeautifulSoup
14+
import requests
15+
16+
17+
################################################################################################
18+
# todo :
19+
20+
################################################################################################
21+
22+
23+
################################################################################################
24+
# Constants
25+
#
26+
################################################################################################
27+
BLOG_MASTER_BRANCH_README_URL = 'https://raw.githubusercontent.com/kenshin579/advenoh.pe.kr/master/README.md'
28+
LOCAL_README_FILE = '../README.md'
29+
30+
################################################################################################
31+
# Functions
32+
#
33+
################################################################################################
34+
35+
def save_file(url, download_folder):
36+
download_filename = 'blog_README.md'
37+
mem = urllib.request.urlopen(url).read()
38+
full_path = os.path.join(download_folder, download_filename)
39+
with open(full_path, mode="wb") as tmp_dir:
40+
tmp_dir.write(mem)
41+
print("saved file")
42+
43+
return full_path
44+
45+
def update_readme():
46+
tmp_dir = tempfile.TemporaryDirectory(dir="/tmp")
47+
print('tmp dir', tmp_dir.name)
48+
remote_file = save_file(BLOG_MASTER_BRANCH_README_URL, tmp_dir.name)
49+
print('remote_file', remote_file)
50+
remote_file_size = Path(remote_file).stat().st_size
51+
local_file_size = Path(LOCAL_README_FILE).stat().st_size
52+
if remote_file_size > local_file_size:
53+
shutil.copy(remote_file, LOCAL_README_FILE)
54+
55+
################################################################################################
56+
# Main function
57+
#
58+
################################################################################################
59+
60+
def main():
61+
parser = argparse.ArgumentParser(description="Maintenance script for tutorials-java")
62+
63+
parser.add_argument("-u", "--update", action='store_true',
64+
help="Update README file from blog branch")
65+
66+
if len(sys.argv[1:]) == 0:
67+
parser.print_help()
68+
parser.exit()
69+
70+
args = parser.parse_args()
71+
72+
print('args', args)
73+
74+
if args.update:
75+
update_readme()
76+
77+
if __name__ == "__main__":
78+
sys.exit(main())

0 commit comments

Comments
 (0)