def main(): try: CoinMarketBot() except Exception as e: logging.error('Bot failed to run: {}'.format(str(e))) print(e) logger.info("Bot is now offline.")
def main(): try: logger.info('Starting bot..') print("Starting bot..") PokeBot() except Exception as e: logging.error('Bot failed to run: {}'.format(str(e))) print(e) logger.info("Bot is now offline.")
async def _continuous_updates(self): await self._update_data() self.started = True print('CoinMarketDiscordBot is online.') logger.info('Bot is online.') while True: time = datetime.datetime.now() if time.minute % 5 == 0: await self._update_data(time.minute) await asyncio.sleep(60) else: await asyncio.sleep(20)
async def on_ready(): for extension in initial_extensions: try: logger.info('Starting bot..') bot.load_extension(extension) print('CoinMarketDiscordBot is online.') print('Bot is currently running on {} servers.'.format( len(bot.servers))) logger.info('Bot is online.') except Exception as e: error_msg = 'Failed to load extension {}\n{}: {}'.format( extension, type(e).__name__, e) print(error_msg) logger.error(error_msg)
def _load_acronyms(self): """ Loads all acronyms of existing crypto-coins out there @return - list of acronyms """ try: acronym_list, duplicate_count = self.coin_market.load_all_acronyms( ) print("Acronyms have successfully loaded.") logger.info("Acronyms have successfully loaded.") return acronym_list except CoinMarketException as e: print("Failed to load cryptocurrency acronyms. See error.log.") logger.error("CoinMarketException: {}".format(str(e))) return None
def load_all_acronyms(self): """ Loads all available acronyms for cryptocurrencies @return - all cryptocurrency acronyms """ try: acronym_list = {} duplicate_count = 0 data = self.fetch_currency_data(load_all=True) for currency in data: if currency['symbol'] in acronym_list: duplicate_count += 1 logger.warning( "Found duplicate acronym. Creating seperate " "separate definition...") if currency['symbol'] not in acronym_list[ currency['symbol']]: acronym_list[currency['symbol'] + str(1)] = acronym_list[currency['symbol']] acronym_list[currency['symbol']] = ( "Duplicate acronyms " "found. Possible " "searches are:\n" "{}1 ({})\n".format( currency['symbol'], acronym_list[currency['symbol']])) dupe_acronym = re.search('\\d+', acronym_list[currency['symbol']]) dupe_num = str( int(dupe_acronym.group(len(dupe_acronym.group()) - 1)) + 1) dupe_key = currency['symbol'] + dupe_num acronym_list[dupe_key] = currency['id'] acronym_list[currency['symbol']] = ( acronym_list[currency['symbol']] + "{} ({})".format(dupe_key, currency['id'])) dupe_msg = "Created duplicate acronym: {} ({})".format( dupe_key, currency['id']) logger.info(dupe_msg) else: acronym_list[currency['symbol']] = currency['id'] return acronym_list, duplicate_count except Exception as e: raise CoinMarketException( "Failed to load all acronyms: {}".format(e))