Upgrading the stability of the warframe api

This commit is contained in:
Rafael Vargas
2021-12-28 20:00:45 -04:00
parent 10d7a430a8
commit 1f20b6c583

View File

@@ -1,7 +1,6 @@
import requests import requests
import json import json
import discord import discord
from dotenv import dotenv_values
from discord.ext import commands from discord.ext import commands
from config import config from config import config
@@ -21,30 +20,32 @@ class Warframe(commands.Cog):
self.__bot = newBot self.__bot = newBot
@commands.command(name='cetus', help='Informa o tempo atual de Cetus - Warframe') @commands.command(name='cetus', help='Informa o tempo atual de Cetus - Warframe')
async def get_cetus(self, ctx): async def cetus(self, ctx):
description = await self.__get_api()
embed = discord.Embed(
title='Warframe Cetus Timing',
description=description,
colour=config.COLOURS['blue']
)
await ctx.send(embed=embed)
async def __get_api(self):
"""Return the information of the Warframe API"""
tries = 0
while True:
tries += 1
if tries > config.MAX_API_CETUS_TRIES:
return 'Os DE baiano não tão com o banco de dados ligado'
try: try:
response = requests.get(config.CETUS_API) response = requests.get(config.CETUS_API)
data = json.loads(response.content) data = json.loads(response.content)
short = data['shortString'] short = data['shortString']
responseText = f'{short}' return short
embed = discord.Embed(
title='Warframe Cetus Timing',
description=responseText,
colour=0xFF0000
)
await ctx.send(embed=embed)
except Exception as e: except Exception as e:
print(e) continue
responseText = f'Houve um erro inesperado :/'
embed = discord.Embed(
title='Warframe Cetus Timing',
description=responseText,
colour=0xFF0000
)
await ctx.send(embed=embed)
def setup(bot): def setup(bot):