Last active
February 4, 2024 17:08
-
-
Save P-rgb-max/925e9718c5fc61687741366007cf0cad to your computer and use it in GitHub Desktop.
Shows last GitHub gists via API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import requests as req | |
listUrl = 'https://api.github.com/gists/public' | |
rawGists = req.get(listUrl).json()[:30] | |
gists = {} | |
for gist in rawGists: | |
files = {} | |
for name, file in gist['files'].items(): | |
files[name] = file['raw_url'] | |
gists[gist['description']] = files | |
for i, desc in enumerate(gists.keys()): | |
print(f'{i + 1}. {desc}') | |
sel = 1 | |
while True: | |
sel = input('gist>') | |
try: | |
sel = int(sel) | |
except: | |
print('Enter a number!') | |
else: | |
break | |
files = gists[list(gists)[sel - 1]] | |
for i, name in enumerate(files.keys()): | |
print(f'{i + 1}. {name}') | |
sel = 1 | |
while True: | |
sel = input('file>') | |
try: | |
sel = int(sel) | |
except: | |
print('Enter a number!') | |
else: | |
break | |
name = list(files)[sel - 1] | |
file = req.get(files[name]).text | |
with open(name, 'w') as f: | |
f.write(file) | |
print(file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment