I hereby claim:
- I am netletic on github.
- I am netletic (https://keybase.io/netletic) on keybase.
- I have a public key ASCAh-V2qMJm3urSkK7b0TZxfHYv4t7KcFDALU9qJ6MwDQo
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
def parse_date_from_incomplete_string(incomplete_dt: str) -> datetime: | |
current_year = datetime.today().year | |
search_range = range(current_year, current_year - 28, -1) | |
candidate_dates = _find_possible_dates(search_range, incomplete_dt) | |
for dt in candidate_dates: | |
if _weekdays_match(dt, incomplete_dt): | |
return dt | |
raise ValueError("Impossible date") |
@pytest.mark.parametrize( | |
"partial_date, expected", | |
[ | |
("THU OCT 02 14:07:47", datetime(2014, 10, 2, 14, 7, 47)), | |
("MON MAR 02 11:40:47", datetime(2020, 3, 2, 11, 40, 47)), | |
("TUE JAN 26 00:16:32", datetime(2016, 1, 26, 0, 16, 32)), | |
("WED JUN 28 17:03:26", datetime(2017, 6, 28, 17, 3, 26)), | |
("FRI NOV 30 10:55:55", datetime(2018, 11, 30, 10, 55, 55)), | |
("MON SEP 09 14:58:19", datetime(2019, 9, 9, 14, 58, 19)), | |
("MON FEB 29 13:37:00", datetime(2016, 2, 29, 13, 37, 0)), |
@freeze_time("2020-03-03") | |
@pytest.mark.parametrize( | |
"partial_date, expected", | |
[ | |
("THU OCT 02 14:07:47", datetime(2014, 10, 2, 14, 7, 47)), | |
("MON MAR 02 11:40:47", datetime(2020, 3, 2, 11, 40, 47)), | |
("TUE JAN 26 00:16:32", datetime(2016, 1, 26, 0, 16, 32)), | |
("WED JUN 28 17:03:26", datetime(2017, 6, 28, 17, 3, 26)), | |
("FRI NOV 30 10:55:55", datetime(2018, 11, 30, 10, 55, 55)), | |
("MON SEP 09 14:58:19", datetime(2019, 9, 9, 14, 58, 19)), |
from datetime import datetime | |
from datetime import timedelta | |
def yesterday(asof: datetime) -> datetime: | |
return asof - timedelta(days=1) |
def get_rx_bytes(file: Path) -> Counter: | |
rx = {} | |
with open(file) as fp: | |
for line in fp.readlines(): | |
if "Chassis/Slot/Port" in line: | |
_, port, _ = line.split() | |
elif "Bytes Received" in line: | |
_, bytes_rx, *_ = line.split(":") | |
bytes_rx = bytes_rx.replace(", Unicast Frames ", "").lstrip() | |
rx[port] = int(bytes_rx) |
def get_rx_bytes(file: Path) -> Counter: | |
with open(file) as fp: | |
pattern = re.compile( | |
r"Chassis/Slot/Port\s(\d+/\d+/\d+).*?Bytes Received :\s*(\d{1,})", | |
re.DOTALL, | |
) | |
matches = re.findall(pattern, fp.read()) | |
rx = {port: int(bytes_rx) for port, bytes_rx in matches} | |
return Counter(rx) |
def delta(t1: Counter, t2: Counter, limit: Optional[int] = 5) -> List[Tuple[str, int]]: | |
return (t2 - t1).most_common(limit) |
def main() -> int: | |
t1 = get_rx_bytes(t1_file) | |
t2 = get_rx_bytes(t2_file) | |
pprint(delta(t1, t2)) | |
return 0 | |
if __name__ == "__main__": | |
exit(main()) |
rx = {} | |
delta = {} | |
with open("t2.txt") as f_t2: | |
for line in f_t2.readlines(): | |
if "Chassis/Slot/Port" in line: | |
port = line.split()[1].strip() | |
rx[port] = {} | |
if "Bytes Received" in line: | |
t2_bytes_rx = line.split(":")[1].strip().rstrip(", Unicast Frames ") |