BGP-Ranking/bin/manual_ranking.py

34 lines
1.3 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
from bgpranking.libs.helpers import load_config_files
from bgpranking.ranking import Ranking
logging.basicConfig(format='%(asctime)s %(name)s %(levelname)s:%(message)s',
level=logging.DEBUG, datefmt='%I:%M:%S')
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)
config_files = load_config_files()
if args.day:
day = parse(args.day).date().isoformat()
ranking.rank_a_day(day, config_files)
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:
ranking.rank_a_day(current.isoformat(), config_files)
current -= timedelta(days=1)