forked from FrostiestBunny/yet-another-waifu-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_api.py
More file actions
99 lines (86 loc) · 2.54 KB
/
github_api.py
File metadata and controls
99 lines (86 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import aiohttp
import os
GITHUB_API_TOKEN = os.getenv("GITHUB_API_TOKEN")
GITHUB_API_URL = "https://api.github.com/"
USER_AGENT = "User-Agent: yet-another-waifu-bot"
CUSTOM_ACCEPT = "application/vnd.github.inertia-preview+json"
PROJECT_ID = "2029170"
COLUMN_ID = "4039174"
async def create_card(body):
body = body.strip('*')
url = GITHUB_API_URL + "projects/columns/" + COLUMN_ID + "/cards"
params = {
'access_token': GITHUB_API_TOKEN
}
headers = {
'Accept': CUSTOM_ACCEPT
}
payload = {
'note': body
}
response = ""
async with aiohttp.ClientSession() as session:
async with session.post(url, json=payload, params=params, headers=headers) as resp:
response = await resp.json()
return response
async def create_gist(desc, body):
url = GITHUB_API_URL + "gists"
params = {
'access_token': GITHUB_API_TOKEN
}
headers = {
'Accept': CUSTOM_ACCEPT
}
payload = {
'description': desc,
'files': {
'waifus.txt': {
'content': body
}
}
}
response = ""
async with aiohttp.ClientSession() as session:
async with session.post(url, json=payload, params=params, headers=headers) as resp:
response = await resp.json()
return response
async def get_gist(gist_id):
url = GITHUB_API_URL + "gists/" + str(gist_id)
params = {
'access_token': GITHUB_API_TOKEN
}
response = ""
async with aiohttp.ClientSession() as session:
async with session.get(url, params=params) as resp:
response = await resp.json()
return response
async def update_gist(gist_id, body):
url = GITHUB_API_URL + "gists/" + str(gist_id)
params = {
'access_token': GITHUB_API_TOKEN
}
headers = {
'Accept': CUSTOM_ACCEPT
}
payload = {
'files': {
'waifus.txt': {
'content': body
}
}
}
response = ""
async with aiohttp.ClientSession() as session:
async with session.patch(url, json=payload, params=params, headers=headers) as resp:
response = await resp.json()
return response
async def get_commits():
url = GITHUB_API_URL + "repos/zackunfair/yet-another-waifu-bot/commits"
params = {
'access_token': GITHUB_API_TOKEN
}
response = ""
async with aiohttp.ClientSession() as session:
async with session.get(url, params=params) as resp:
response = await resp.json()
return response