async def main(self): if self.bot.auto_update_running: return self.bot.news = utils.load_news() if self.bot.http_session is None: self.bot.http_session = ClientSession(loop=self.bot.loop) await self.bot.wait_until_ready() utils.png_clean() starting = True self.bot.auto_update_running = True while True: before = time.time() try: if not starting: self.interval_update += 1 await utils._write(utils.NEWS_URL, utils.NEWS_PATH, self.bot.http_session) self.bot.news = utils.load_news() utils.png_clean() await self.send_notifications() await self.send_tracker() else: starting = False except Exception as e: logger.exception(e, exc_info=True) finally: after = time.time() await asyncio.sleep(3600 - int(after - before))
async def main(self): self.bot.news = utils.load_news() self.bot._data = utils.load_pickle() self.bot._populations = utils.load_populations() self.bot.http_session = ClientSession() await self.parse_and_update() await self.bot.wait_until_ready() starting = True while True: try: before = time.time() if not starting: self.interval_update += 1 try: await self.parse_and_update() except Exception as e: logger.exception(e, exc_info=True) finally: await self.send_notifications() await self.send_tracker() else: starting = False after = time.time() except: pass await asyncio.sleep(3600 - int(after - before))
async def news(self, ctx): if self.bot.news is None: self.bot.news = utils.load_news() embed = discord.Embed( title= ":newspaper: Recent news about Coronavirus COVID-19 :newspaper:", timestamp=utils.discord_timestamp(), color=utils.COLOR) sources = [] length = 0 max_size = 5800 for n in self.bot.news["articles"]: source = n["source"]["name"] if source not in sources: sources.append(source) else: continue try: length += len( f"🞄 **{source}** : {n['title']} {n['description']} [Link]({n['url']})" ) if length >= max_size: break embed.add_field( name=f"🞄 **{source}** : {n['title']}", value=f"{n['description']} [Link]({n['url']})", inline=False) except discord.errors.HTTPException: break embed.set_thumbnail( url="https://avatars2.githubusercontent.com/u/32527401?s=400&v=4") embed.set_footer(text=utils.last_update(utils.NEWS_PATH) + " | newsapi.org", icon_url=ctx.me.avatar_url) await ctx.send(embed=embed)
async def parse_and_update(self): updating = await up.update(self.bot.http_session) self.bot.news = utils.load_news() self.bot._data = utils.load_pickle() logger.info("New data downloaded") try: await plot_csv(utils.STATS_PATH, self.bot._data) await plot_csv(utils.STATS_LOG_PATH, self.bot._data, logarithmic=True) except Exception as e: logger.exception(e, exc_info=True) logger.info("New plot generated")