Created
December 19, 2024 05:43
-
-
Save exemplum100/992fab733139e63038ae587e44d0d3b7 to your computer and use it in GitHub Desktop.
Gists update
This file contains hidden or 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
import requests | |
import json | |
GITHUB_API="https://api.github.com" | |
API_TOKEN = config.token | |
# | |
a = [] | |
x=open(config.discr, 'r') | |
for s in x.readlines(): | |
new=s.strip('\n') | |
a.append(new) | |
# | |
path = config.path | |
file_list = os.listdir(path) | |
full_list = [os.path.join(path, i) for i in file_list] | |
time_sorted_list = sorted(full_list, key = os.path.getmtime) | |
sortes=[] | |
for i in time_sorted_list: | |
i=i.split('\\name\\')[1] | |
sortes.append(i) | |
# | |
texts=[] | |
for i in time_sorted_list: | |
x=open(i,'r',encoding='utf-8') | |
b = '' | |
b = x.read() | |
texts.append(b) | |
url=GITHUB_API+"/gists" | |
print("Request URL: %s"%url) | |
for i in range(len(a)): | |
headers={'Authorization':'token %s'%API_TOKEN} | |
params={'scope':'gist'} | |
payload={"description":a[i],"public":True,"files":{sortes[i]:{"content":texts[i]}}} | |
res=requests.post(url,headers=headers,params=params,data=json.dumps(payload)) | |
print('Done!') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment