Here are the examples of the python api requests.status_code taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
0
Source : misc.py
with GNU General Public License v3.0
from Madushankabro
with GNU General Public License v3.0
from Madushankabro
def paste(update, context):
args = context.args
BURL = "https://del.dog"
message = update.effective_message
if message.reply_to_message:
data = message.reply_to_message.text
elif len(args) >= 1:
data = message.text.split(None, 1)[1]
else:
message.reply_text("What am I supposed to do with this?!")
return
r = requests.post(f"{BURL}/documents", data=data.encode("utf-8"))
if r.status_code == 404:
update.effective_message.reply_text("Failed to reach dogbin")
r.raise_for_status()
res = r.json()
if r.status_code != 200:
update.effective_message.reply_text(res["message"])
r.raise_for_status()
key = res["key"]
if res["isUrl"]:
reply = "Shortened URL: {}/{}\nYou can view stats, etc. [here]({}/v/{})".format(
BURL, key, BURL, key
)
else:
reply = f"{BURL}/{key}"
update.effective_message.reply_text(
reply, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True
)
@run_async
0
Source : misc.py
with GNU General Public License v3.0
from Madushankabro
with GNU General Public License v3.0
from Madushankabro
def get_paste_content(update, context):
args = context.args
BURL = "https://del.dog"
message = update.effective_message
chat = update.effective_chat # type: Optional[Chat]
if len(args) >= 1:
key = args[0]
else:
message.reply_text("Please supply a dogbin url!")
return
format_normal = f"{BURL}/"
format_view = f"{BURL}/v/"
if key.startswith(format_view):
key = key[len(format_view) :]
elif key.startswith(format_normal):
key = key[len(format_normal) :]
r = requests.get(f"{BURL}/raw/{key}")
if r.status_code != 200:
try:
res = r.json()
update.effective_message.reply_text(res["message"])
except Exception:
if r.status_code == 404:
update.effective_message.reply_text("Failed to reach dogbin")
else:
update.effective_message.reply_text("Unknown error occured")
r.raise_for_status()
update.effective_message.reply_text(
"```" + escape_markdown(r.text) + "```", parse_mode=ParseMode.MARKDOWN
)
@run_async