Skip to content

Instantly share code, notes, and snippets.

@raj1rana
Last active May 20, 2022 09:37
Show Gist options
  • Save raj1rana/6e89c4c39c93626cddf44eb9f9dd9564 to your computer and use it in GitHub Desktop.
Save raj1rana/6e89c4c39c93626cddf44eb9f9dd9564 to your computer and use it in GitHub Desktop.
Create excel sheet with github data
from openpyxl import Workbook
import json
import requests
workbook = Workbook()
sheet = workbook.active
row = 1
########################### VARIABLES #########################################################
# github Admin user token, while using change it to your own token
token = ''
# github API URL
url = 'https://api.github.com/'
# sheet name
sheet_name = 'TagManager.xlsx'
############################# VARIABLES ENDED ########################################################
############################## HEADERS #################################################
headers = {'Authorization': 'token %s' % token,
'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'}
def json_formator(json_text):
json_text = json_text.decode('utf8')
data = json.loads(json_text)
return json.dumps(data, indent=4)
# data loader in object
def get_object_from_response(response):
response = response.decode('utf8')
data = json.loads(response)
return data
def insert_repoName():
global row
sheet["A1"] = "REPO NAME"
sheet["B1"] = "ORG"
sheet["C1"] = "LATEST TAG AS PER GIT"
repos = requests.get(url + 'user/repos', headers=headers)
repos = get_object_from_response(repos.content)
for repo in repos:
row = row + 1
sheet["A" + str(row)] = repo['name']
sheet["B" + str(row)] = repo['full_name']
tagUrl = url + 'repos/' + repo['full_name'] + '/tags'
tags = requests.get(tagUrl, headers=headers)
# tags = get_object_from_response(tags.content)
for index, value in enumerate(tags.json()):
if index == 0:
sheet["C" + str(row)] = value['name']
else:
pass
int(row)
workbook.save(filename=sheet_name)
print("done")
return
if __name__ == '__main__':
insert_repoName()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment