import base64, json, os
from .tools import get_random_string
from .http import http
from misskaty.vars import GH_TOKEN
hmtl_content = """
{title}t
{msg}
"""
async def postToWeb(file, name):
fpath = base64.b64encode(open(file, "rb").read())
headers = {
'Accept': 'application/vnd.github+json',
'Authorization': f'Bearer {GH_TOKEN}',
'Content-Type': 'application/x-www-form-urlencoded',
}
data = {"message":"Added new HTML File","committer":{"name":"Yasir Aris M","email":"mail@yasir.eu.org"},"content": f"{fpath.decode('ascii')}"}
response = await http.put(f"https://api.github.com/repos/yasirarism/HTMLPaste/contents/{name}.html", headers=headers, data=json.dumps(data))
return f"https://yasirarism.github.io/HTMLPaste/{name}"
async def getMediaWeb(title, text):
mssg = ""
fname = get_random_string(7)
mssg += '' \
f'{title}
'
mssg += '' \
f'MediaInfo'
mssg += '' \
f"{text}
"
with open(f"{fname}.html", 'w', encoding='utf-8') as f:
f.write(hmtl_content.replace('{msg}', mssg))
try:
res = await postToWeb(f"{fname}.html", fname)
os.remove(f"{fname}.html")
return res
except:
return None