0

So I am using MurkAPI and had gotten help with this but I cannot seem to get it so when someone does $adfly and a url which is a adfly shortend link, the bot returns the link through the API and into the bot. This is the current code I have.

@commands.command(pass_context=True)
async def adfly(self, ctx):
    async with aiohttp.ClientSession() as session:
            await self.client.say(await fetch_adfly(session))
async def fetch_adfly(session):
    async with session.get(adfly_url) as response:
        return await response.text()

I have the MURKKEY working, however, I cannot get the URL part working.

adfly_url = 'https://murkapi.com/adfly.php?key={}&url={}'.format(MURKKEY)
  • What part of the URL isn't working? Also, your command doesn't have an argument for the url, did you mean to add one? –  Aug 21 '18 at 22:16
  • So basically the users do like $adfly (adfly link) and the bot will return the link behind the adfly link. I just can't figure that part out as I am not really good with Python. And yes, I mean to add one –  Aug 21 '18 at 22:18

1 Answers1

0

If fetch_adfly is meant to handle transforming your url into an adfly url, you want the session in that function. Instead of passing a session, we want to pass the url that we want transformed. That might give us something like:

async def fetch_adfly(url):
  async with aiohttp.ClientSession() as session:
    adfly_url = 'https://murkapi.com/adfly.php?key={}&url={}'.format(MURKKEY, url)
    async with session.get(adfly_url) as response:
        return await response.text()

Then, you want to add a url parameter to your command and pass it to your function:

@commands.command(pass_context=True)
async def adfly(self, ctx, url):
  await self.client.say(await fetch_adfly(url))

FWIW, I would suggest validating URLs.

  • It's supposed to transform an adfly link into the link behind it which is done via the API –  Aug 21 '18 at 22:41
  • Can you please clarify how the intended behavior differs from this solution? –  Aug 21 '18 at 22:45
  • When using your solution, I do $adfly (Adfly link I want to get the actual link from behidn it) It says URL cannot be found. I want it so when someone does $adfly (adfly url) they get the real URL behind the adfly link –  Aug 21 '18 at 22:50
  • Do a `print(adfly_url)` and see what the full url it's trying to call is. However it sounds like the 'not found' issue may be on murkapi's end. –  Aug 21 '18 at 22:55
  • 1
    It is their end, I have called the API through my browser and got the same results. I have contact MurkAPI staff about this issue. –  Aug 21 '18 at 22:58