fixing how to get discussion comments
This commit is contained in:
parent
28e34de14b
commit
41c79f0a73
133
gh_gsql_req.py
133
gh_gsql_req.py
@ -19,7 +19,102 @@ def get_discussion_gql(repo_owner, repo_name):
|
|||||||
data_string = ("""
|
data_string = ("""
|
||||||
query {
|
query {
|
||||||
repository(owner: """ + repo_owner + """, name: """ + repo_name + """) {
|
repository(owner: """ + repo_owner + """, name: """ + repo_name + """) {
|
||||||
discussions(first: 3) {
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
data = {"query" : data_string}
|
||||||
|
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)
|
||||||
|
return r.json()
|
||||||
|
|
||||||
|
def within_time(comment_content, early_cutoff):
|
||||||
|
try:
|
||||||
|
list_of_comments = json.loads(comment_content)["data"]["repository"]["discussions"]["edges"]
|
||||||
|
valid_comments = []
|
||||||
|
for comment in list_of_comments:
|
||||||
|
if dt.datetime.fromisoformat(comment['node']['createdAt'][:-1]) < early_cutoff:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
valid_comments.append(comment)
|
||||||
|
return valid_comments
|
||||||
|
except TypeError:
|
||||||
|
print("no discussions found")
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
repo_name = '"' + 'numpy' + '"'
|
||||||
|
repo_owner = '"' + 'numpy' + '"'
|
||||||
|
get_discussion_gql(repo_owner, repo_name)
|
||||||
|
|
||||||
|
|
||||||
|
# stashed info about page cursors
|
||||||
|
''' pageInfo {
|
||||||
|
# type: PageInfo (from the public schema)
|
||||||
|
startCursor
|
||||||
|
endCursor
|
||||||
|
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
|
# type: DiscussionConnection
|
||||||
totalCount # Int!
|
totalCount # Int!
|
||||||
|
|
||||||
@ -53,41 +148,5 @@ def get_discussion_gql(repo_owner, repo_name):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
data = {"query" : data_string}
|
|
||||||
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)
|
|
||||||
return r.json()
|
|
||||||
|
|
||||||
def within_time(comment_content, early_cutoff):
|
|
||||||
try:
|
|
||||||
list_of_comments = json.loads(comment_content)["data"]["repository"]["discussions"]["edges"]
|
|
||||||
valid_comments = []
|
|
||||||
for comment in list_of_comments:
|
|
||||||
if dt.datetime.fromisoformat(comment['node']['createdAt'][:-1]) < early_cutoff:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
valid_comments.append(comment)
|
|
||||||
return valid_comments
|
|
||||||
except TypeError:
|
|
||||||
print("no discussions found")
|
|
||||||
return []
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
get_discussion_gql()
|
|
||||||
|
|
||||||
|
|
||||||
# stashed info about page cursors
|
|
||||||
''' pageInfo {
|
|
||||||
# type: PageInfo (from the public schema)
|
|
||||||
startCursor
|
|
||||||
endCursor
|
|
||||||
hasNextPage
|
|
||||||
hasPreviousPage
|
|
||||||
}
|
|
||||||
'''
|
'''
|
2
main.py
2
main.py
@ -41,8 +41,10 @@ def main():
|
|||||||
break
|
break
|
||||||
print(largest_object.keys())
|
print(largest_object.keys())
|
||||||
print(len(largest_object.keys()))
|
print(len(largest_object.keys()))
|
||||||
|
'''
|
||||||
for repo in largest_object:
|
for repo in largest_object:
|
||||||
print(largest_object[repo]['new_formality'])
|
print(largest_object[repo]['new_formality'])
|
||||||
|
'''
|
||||||
with open('result.json', 'w') as results_path:
|
with open('result.json', 'w') as results_path:
|
||||||
json.dump(largest_object, results_path)
|
json.dump(largest_object, results_path)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user