Skip to content

Instantly share code, notes, and snippets.

@exemplum100
Created July 16, 2023 07:32
Show Gist options
  • Save exemplum100/1783e0c22784675dcd451759db08e9bd to your computer and use it in GitHub Desktop.
Save exemplum100/1783e0c22784675dcd451759db08e9bd to your computer and use it in GitHub Desktop.
Gists update
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