Skip to content

Instantly share code, notes, and snippets.

@lmolkova
Last active August 7, 2024 20:46
Show Gist options
  • Save lmolkova/50565fc77fb417a5932028793b6d8137 to your computer and use it in GitHub Desktop.
Save lmolkova/50565fc77fb417a5932028793b6d8137 to your computer and use it in GitHub Desktop.
import requests
import time
def retry_request(url):
max_retries = 3
retry_delay = 60
for r in range(max_retries):
try:
print(f"Fetching {url}, try {r}")
# add your token here
response = requests.get(url, headers={"Authorization": "Bearer YOUR_PERSONAL_TOKEN"})
if response.status_code == 200:
return response
print(f"Request failed: {response.json()}")
except requests.exceptions.RequestException as e:
print(f"Request failed: {e}")
print("Retrying in 1 minute...")
time.sleep(retry_delay)
return None
def reactions_to_dict(reactions):
keys = ["+1", "-1", "laugh", "hooray", "confused", "heart", "rocket", "eyes"]
return {k:v for k,v in reactions.items() if k in keys}
repo = "semantic-conventions"
issues_list = []
reactions_count = {}
issues = {}
reactions = {}
for page in range(1, 10):
url = f'https://api.github.com/repos/open-telemetry/{repo}/issues?state=open&sort=updated&direction=desc&per_page=100&page={page}'
response = retry_request(url)
if response is None:
break
i = response.json()
if len(i) == 0:
break
print(f"Received {len(i)} issues")
issues_list.extend(i)
for issue in issues_list:
if 'pull_request' in issue:
continue
issue_id = issue['number']
reactions_raw = issue['reactions']
count = reactions_raw['total_count']
if count > 0:
reactions_count[issue_id] = count
reactions[issue_id] = reactions_to_dict(reactions_raw)
issues[issue_id] = issue
print("| Title | Link | # of reactions | Reactions |")
print("| ------ | ---- | -------------- | --------- |")
for issue_id, count in sorted(reactions_count.items(), key=lambda r: r[1], reverse=True):
issue = issues[issue_id]
print(f"| {issue['title']} | {issue['html_url']} | {count} | {reactions[issue_id] } |")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment