BGP-Ranking/bin/loadprefixes.py

31 lines
872 B
Python
Raw Normal View History

2018-03-29 22:37:28 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import logging
import requests
2018-03-30 14:33:33 +02:00
from bgpranking.abstractmanager import AbstractManager
from bgpranking.prefixdb import PrefixDatabase
2018-03-29 22:37:28 +02:00
logging.basicConfig(format='%(asctime)s %(name)s %(levelname)s:%(message)s',
level=logging.INFO, datefmt='%I:%M:%S')
2018-03-30 14:33:33 +02:00
class PrefixDBManager(AbstractManager):
2018-03-29 22:37:28 +02:00
def __init__(self, loglevel: int=logging.DEBUG):
2018-03-30 14:33:33 +02:00
super().__init__(loglevel)
2018-03-29 22:37:28 +02:00
self.prefix_db = PrefixDatabase(loglevel=loglevel)
2018-03-30 14:33:33 +02:00
def _to_run_forever(self):
try:
if self.prefix_db.update_required():
self.prefix_db.load_prefixes()
except requests.exceptions.ConnectionError as e:
self.logger.critical(f'Unable to download the prefix database: {e}')
2018-03-29 22:37:28 +02:00
if __name__ == '__main__':
p = PrefixDBManager()
2018-03-30 14:33:33 +02:00
p.run(sleep_in_sec=3600)