What is the best way to go about making this work? Since Selenium doesn't work well with asyncio, the bot will eventually die. It works as intended, but will crash eventually. I do understand what the issue is, especially since selenium is so heavy, but is there a good work around?
I get the error message: Task was destroyed but it is pending!
I don't have anything else, no traceback. I have to reboot the bot (discord) and it'll work again for a bit.
@bot.command(pass_context=True)
async def weather(ctx, arg):
if ctx:
list = ('lf','oahu')
await bot.say('*Loading webdriver.....*')
if arg in list:
if arg == 'lf':
website = '--'
name = 'Los Feliz Map'
if arg == 'oahu':
website = '--'
name = 'Oahu Map'
load_site = webdriver.Chrome()
# load site on chrome
load_site.get(website)
await bot.say('*Loading ' + str(name) + '...*')
load_site.find_element_by_xpath('//*[@id="main-map"]/div[2]/div[1]/div/a[2]').click()
load_site.find_element_by_xpath('//*[@id="main-map"]/div[2]/div[2]').click()
load_site.find_element_by_xpath('//*[@id="main-map"]/div[2]/div[2]/div/form/div[3]/label[6]/div/span').click()
await asyncio.sleep(2) #sleep to ensure weather loads on site before screenshot
load_site.save_screenshot('weather.png')
await bot.say('*Taking screenshot and saving image....*')
await bot.send_file(ctx.message.channel, 'weather.png')
load_site.quit()
print('Succesfully sent image of ' + str(arg) + ' - ' + str(ctx.message.author.name))
I left out the website because it's a private one.