-
Notifications
You must be signed in to change notification settings - Fork 0
/
hastebin.py
61 lines (51 loc) · 1.69 KB
/
hastebin.py
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
from aiohttp import ClientSession
from requests import request
async def AsyncPaste(text: str, language: str = None) -> str:
"""
Async method to store online text for a short period of time
Args:
text (str): The text to paste.
language (str, optional): Syntax. Defaults to 'txt' if None is passed in.
Returns:
str: Returns the link
"""
async with ClientSession() as aioclient:
post = await aioclient.post("https://hastebin.com/documents",
data=text)
if post.status == 200:
response = await post.text()
return f"https://hastebin.com/{response[8:-2]}"
# Rollback bin
post = await aioclient.post(
"https://bin.readthedocs.fr/new",
data={
"code": text,
"lang": language or "txt",
},
)
if post.status == 200:
return post.url
def Paste(text: str, language: str = None) -> str:
"""
Synchronize method to store online text for a short period of time.
Args:
text (str): The text to paste.
language (str, optional): Syntax. Defaults to 'txt' if None is passed in.
Returns:
str: Returns the link
"""
post = request("POST", "https://hastebin.com/documents", data=text)
if post.status_code == 200:
response = post.text
return f"https://hastebin.com/{response[8:-2]}"
# Rollback bin
post = request(
"POST",
"https://bin.readthedocs.fr/new",
data={
"code": text,
"lang": language or "txt",
},
)
if post.status_code == 200:
return post.url