From 7ac84c7a328987b0d75ce47c1cffdecb92c23cd9 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Mon, 5 Sep 2022 20:15:43 +0200 Subject: [PATCH 1/2] allow appending to file --- generate_markdown.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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'") From fce6b505725ed2db9585f9ae169f177ff00c2632 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Mon, 5 Sep 2022 20:16:10 +0200 Subject: [PATCH 2/2] be more explicit for which user it failed --- fetch_repos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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