#πŸ”’ API large data

8 messages Β· Page 1 of 1 (latest)

solar stratus
#

So basically i have an api which sends me like 3-4 hundred items, of which i need like last 20 (( api don't have limit param )). When request is sending my whole server is starting messing with lib (( not the d.py)) and causing lags which require a restart, how can I optimise this request so my whole server won't get melted

aiohttp is used.
aiogram for other lib

long swanBOT
#

@solar stratus

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

crisp jolt
#

send code

solar stratus
# crisp jolt send code
async def get_keyboard_domains(group: int):
    headers = {"Api-Key": KEITARO_API}
    async with aiohttp.ClientSession() as session:
        async with session.get(API_DOMAIN + "domains", headers=headers) as response:
            if response.status == 200:
                res_domains = await response.json()
                domains = []
                for i in range(len(res_domains)):
                    # ADD THIS TO IF AFTER TESTING {and res_domains[i]["state"] == "active"}
                    if res_domains[i]["campaigns_count"] == 0 and res_domains[i]["group_id"] == int(group) and res_domains[i]["state"] == "active" :
                        if len(domains) >= 10:
                            break
                        domains.append(res_domains[i])
                return domains

            else:
                return []
crisp jolt
#

async def get_keyboard_domains(group: int):
    headers = {"Api-Key": KEITARO_API}
    async with aiohttp.ClientSession() as session:
        async with session.get(API_DOMAIN + "domains", headers=headers) as response:
            domains = []
            if response.status != 200:
                return domains


            res_domains = await response.json()
            
            for domain in res_domains:
                if domain["campaigns_count"] == 0 and domain["group_id"] == group and domain["state"] == "active" :
                    if len(domains) >= 10:
                        break

                    domains.append(domain)
        
            return domains```
#

how does that perform?

long swanBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.