diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ae0bfed --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.7-alpine + +RUN apk add curl jq + +ENV PYTHONDONTWRITEBYTECODE 1 + +WORKDIR /app + +COPY . /app/ + +RUN python3 -m venv /venv/bin/python3 +RUN pip install -r requirements.txt \ No newline at end of file diff --git a/fetch_repos.py b/fetch_repos.py index 0dc131f..9821674 100755 --- a/fetch_repos.py +++ b/fetch_repos.py @@ -65,7 +65,7 @@ def get_repo_list(user): return repo_list - print("Unable to fetch repositories") + print("Unable to fetch repositories for", user) return None diff --git a/generate_markdown.py b/generate_markdown.py index d8a4de7..ba43746 100755 --- a/generate_markdown.py +++ b/generate_markdown.py @@ -5,14 +5,15 @@ GitHub. Usage: - generate_markdown.py [-o ] [-r] - generate_markdown.py -o table [-c ] [-r] + generate_markdown.py [-o ] [-r] [-a] + generate_markdown.py -o table [-c ] [-r] [-a] generate_markdown.py -h Options: -o , --output-as Generate Markdown for either a list or a table [default: list]. -c , --columns Number of columns for the table [default: 3]. + -a, --append Append to file. -r, --reverse-order Generate output in reverse chronological order. -h, --help Display this help text. @@ -35,8 +36,8 @@ ''' -def output_list(user, repo_list, output_file): - with open(output_file, "w") as file: +def output_list(user, repo_list, output_file, mode): + with open(output_file, mode) as file: for repo in repo_list: owner, repo_name = repo.split("/") file.write(LIST_ITEM.format(user=user, repo=repo, owner=owner, @@ -45,8 +46,8 @@ def output_list(user, repo_list, output_file): .format(output_file)) -def output_table(user, repo_list, num_columns, output_file): - with open(output_file, "w") as file: +def output_table(user, repo_list, num_columns, output_file, mode): + with open(output_file, mode) as file: file.write("\n\n") repos_written = 0 for repo in repo_list: @@ -64,6 +65,7 @@ def output_table(user, repo_list, num_columns, output_file): if __name__ == '__main__': arguments = docopt(__doc__) + mode = "a" if arguments['--append'] else "w" user = arguments[''] repo_list = get_repo_list(user) if repo_list: @@ -76,10 +78,10 @@ def output_table(user, repo_list, num_columns, output_file): output_file = os.path.join(output_dir, "contribution-" + output_as + ".md") if output_as == 'list': - output_list(user, repo_list, output_file) + output_list(user, repo_list, output_file, mode) elif output_as == 'table': num_columns = int(arguments['--columns']) - output_table(user, repo_list, num_columns, output_file) + output_table(user, repo_list, num_columns, output_file, mode) else: print("Invalid value for output type! Possible values: 'list', " "'table'")