-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
48 lines (39 loc) · 1.48 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import argparse
import json
import os
from lib.builder import ReadMeBuilder
from lib.extractor import DataExtractor
from lib.loader import load_config
from lib.logger import logger
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("command", type=str, help="The action you want to run: fetch, build, update, all")
parser.add_argument("-t", "--token", help="GitHub Personal Access Token")
args = parser.parse_args()
script_path = os.path.realpath(".")
config_path = os.path.join(script_path, "config", "config.yml")
cfg = load_config(config_path)
output_path = os.path.join(script_path, "output", cfg["github"]["output"])
command = args.command
if command in ["fetch", "all"]:
if args.token:
token = args.token
extractor = DataExtractor(token=token)
extractor.fetch()
extractor.dump_json()
else:
logger.error("Please provide a GitHub Personal Access Token with the `-t` flag")
raise SystemExit
if command in ["build", "all"]:
with open(output_path, "r") as f:
data = json.load(f)
builder = ReadMeBuilder(data)
builder.build()
if command == "update":
extractor = DataExtractor(local_only=True)
extractor.update()
extractor.dump_json()
with open(output_path, "r") as f:
data = json.load(f)
builder = ReadMeBuilder(data)
builder.build()