BGP-Ranking/bin/manual_ranking.py

34 lines
1.2 KiB
Python
Raw Normal View History

2019-04-09 11:32:57 +02:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import logging
from dateutil.parser import parse
from datetime import timedelta
2021-12-06 14:30:08 +01:00
from bgpranking.helpers import load_all_modules_configs
from .ranking import Ranking
2019-04-09 11:32:57 +02:00
logging.basicConfig(format='%(asctime)s %(name)s %(levelname)s:%(message)s',
2021-12-17 10:54:05 +01:00
level=logging.INFO)
2019-04-09 11:32:57 +02:00
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Manually force the ranking of a day or a time interval.')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-d', '--day', type=str, help='Day to rank (Format: YYYY-MM-DD).')
2019-04-09 13:33:14 +02:00
group.add_argument('-i', '--interval', type=str, nargs=2, help='Interval to rank, first to last (Format: YYYY-MM-DD YYYY-MM-DD).')
2019-04-09 11:32:57 +02:00
args = parser.parse_args()
ranking = Ranking(loglevel=logging.DEBUG)
2021-12-06 14:30:08 +01:00
config_files = load_all_modules_configs()
2019-04-09 11:32:57 +02:00
if args.day:
day = parse(args.day).date().isoformat()
2021-12-06 14:30:08 +01:00
ranking.rank_a_day(day)
2019-04-09 11:32:57 +02:00
else:
2019-04-09 13:33:14 +02:00
current = parse(args.interval[1]).date()
2019-04-09 11:32:57 +02:00
stop_date = parse(args.interval[0]).date()
while current >= stop_date:
2021-12-06 14:30:08 +01:00
ranking.rank_a_day(current.isoformat())
2019-04-09 11:32:57 +02:00
current -= timedelta(days=1)