From 41c79f0a7313474705ecfb0252b9c35792cc236a Mon Sep 17 00:00:00 2001 From: mjgaughan Date: Mon, 6 Nov 2023 22:18:30 -0600 Subject: [PATCH] fixing how to get discussion comments --- gh_gsql_req.py | 123 ++++++++++++++++++++++++++++++++++++------------- main.py | 2 + 2 files changed, 93 insertions(+), 32 deletions(-) diff --git a/gh_gsql_req.py b/gh_gsql_req.py index b977c3a..78abf73 100644 --- a/gh_gsql_req.py +++ b/gh_gsql_req.py @@ -19,40 +19,39 @@ def get_discussion_gql(repo_owner, repo_name): data_string = (""" query { repository(owner: """ + repo_owner + """, name: """ + repo_name + """) { - discussions(first: 3) { - # type: DiscussionConnection - totalCount # Int! - - edges { - # type: DiscussionEdge - cursor - node { - # type: Discussion - id - title # String! - bodyText # String! - createdViaEmail # Boolean! - createdAt # DateTime! - answer { - #type: DiscussionComment - bodyText # String! - } - comments(first: 10){ - # type: DiscussionCommentConnection - totalCount # Int! - edges { - # type: DiscussionCommentEdge - node { - # type: DiscussionComment - id - bodyText # String! + issues(last: 2) { + edges { + node { + id + title + url + number + state + author { + url } - + labels(first:5) { + edges { + node { + name + } + } + } + comments(first: 10) { + # edges.node is where the actual `Comment` object is + edges { + node { + author { + avatarUrl + } + body + } + } + } + body } } } - } - } } } """) @@ -60,7 +59,7 @@ def get_discussion_gql(repo_owner, repo_name): data_json = json.dumps(data) headers = {'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'Authorization': 'bearer ' + key} r = requests.post(url=url, data=data_json, headers=headers) - #print(r.content) + print(r.content) return r.json() def within_time(comment_content, early_cutoff): @@ -79,7 +78,9 @@ def within_time(comment_content, early_cutoff): if __name__ == "__main__": - get_discussion_gql() + repo_name = '"' + 'numpy' + '"' + repo_owner = '"' + 'numpy' + '"' + get_discussion_gql(repo_owner, repo_name) # stashed info about page cursors @@ -90,4 +91,62 @@ if __name__ == "__main__": hasNextPage hasPreviousPage } +''' + +''' +issue(number: 2) { + title + createdAt + # first 10 results + comments(first: 10) { + # edges.node is where the actual `Comment` object is + edges { + node { + author { + avatarUrl + } + body + } + } + } + } + +''' + +''' + discussions(first: 10) { + # type: DiscussionConnection + totalCount # Int! + + edges { + # type: DiscussionEdge + cursor + node { + # type: Discussion + id + title # String! + bodyText # String! + createdViaEmail # Boolean! + createdAt # DateTime! + answer { + #type: DiscussionComment + bodyText # String! + } + comments(first: 10){ + # type: DiscussionCommentConnection + totalCount # Int! + edges { + # type: DiscussionCommentEdge + node { + # type: DiscussionComment + id + bodyText # String! + } + + } + } + } + } + } + ''' \ No newline at end of file diff --git a/main.py b/main.py index 0c692c5..306ac4c 100644 --- a/main.py +++ b/main.py @@ -41,8 +41,10 @@ def main(): break print(largest_object.keys()) print(len(largest_object.keys())) + ''' for repo in largest_object: print(largest_object[repo]['new_formality']) + ''' with open('result.json', 'w') as results_path: json.dump(largest_object, results_path)