From 10cd5e06a2821a6c1e0afcb67f82d5fee8f92680 Mon Sep 17 00:00:00 2001 From: Satwik Kansal Date: Fri, 19 Jan 2018 19:02:56 +0530 Subject: [PATCH] Generate CONTRIBUTORS.md automatically --- CONTRIBUTORS.md | 14 +++++++++++ generate_contributions.py | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 CONTRIBUTORS.md create mode 100644 generate_contributions.py diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md new file mode 100644 index 0000000..46a771a --- /dev/null +++ b/CONTRIBUTORS.md @@ -0,0 +1,14 @@ +I'm really greatful to all the contributors. Following are the awesome people (in no specific order) who have contributed their examples to wtfpython. + +| Contributor | Github | Issues | +|-------------|--------|--------| +| Lucas-C | [Lucas-C](https://github.com/Lucas-C) | [#36](https:/github.com/satwikkansal/wtfpython/issues/36) | +| MittalAshok | [MittalAshok](https://github.com/MittalAshok) | [#23](https:/github.com/satwikkansal/wtfpython/issues/23) | +| asottile | [asottile](https://github.com/asottile) | [#40](https:/github.com/satwikkansal/wtfpython/issues/40) | +| MostAwesomeDude | [MostAwesomeDude](https://github.com/MostAwesomeDude) | [#1](https:/github.com/satwikkansal/wtfpython/issues/1) | +| tukkek | [tukkek](https://github.com/tukkek) | [#11](https:/github.com/satwikkansal/wtfpython/issues/11), [#26](https:/github.com/satwikkansal/wtfpython/issues/26) | +| PiaFraus | [PiaFraus](https://github.com/PiaFraus) | [#9](https:/github.com/satwikkansal/wtfpython/issues/9) | +| chris-rands | [chris-rands](https://github.com/chris-rands) | [#32](https:/github.com/satwikkansal/wtfpython/issues/32) | + +Thank you all for taking out time, and making this project better! + diff --git a/generate_contributions.py b/generate_contributions.py new file mode 100644 index 0000000..136f653 --- /dev/null +++ b/generate_contributions.py @@ -0,0 +1,51 @@ +""" +Parses the README.md and generated the table +`CONTRIBUTORS.md`. +""" + +import pprint +import re +import requests + +regex = ("[sS]uggested by @(\S+) in \[this\]\(https:\/\/github\.com\/satwikkansal" + "\/wtf[pP]ython\/issues\/(\d+)\) issue") + + +fname = "README.md" +contribs = {} + +table_header = """ +| Contributor | Github | Issues | +|-------------|--------|--------| +""" + +table_row = '| {} | [{}](https://github.com/{}) | {} |' +issue_format = '[#{}](https:/github.com/satwikkansal/wtfpython/issues/{})' +rows_so_far = [] + +github_rest_api = "https://api.github.com/users/{}" + + +with open(fname, 'r') as f: + file_content = f.read() + matches = re.findall(regex, file_content) + for match in matches: + if contribs.get(match[0]) and match[1] not in contribs[match[0]]: + contribs[match[0]].append(match[1]) + else: + contribs[match[0]] = [match[1]] + +for handle, issues in contribs.items(): + issue_string = ', '.join([issue_format.format(i, i) for i in issues]) + resp = requests.get(github_rest_api.format(handle)) + name = handle + if resp.status_code is 200: + pprint.pprint(resp.json()['name']) + else: + print(handle, resp.content) + rows_so_far.append(table_row.format(name, + handle, + handle, + issue_string)) + +print(table_header + "\n".join(rows_so_far)) \ No newline at end of file