This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/api | |
/api-blueprint.md | |
/api-docs | |
/api-docs/ | |
/api.apib | |
/api.json | |
/api.md | |
/api.proto | |
/api.raml | |
/api.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM python:3.9 | |
LABEL maintainer="Jarno Timmermans" | |
RUN groupadd -r netinfo && useradd -r -g netinfo netinfo | |
RUN chsh -s /usr/sbin/nologin root | |
WORKDIR /home/netinfo | |
COPY requirements.txt . | |
RUN pip install -r requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def delta(t1: Counter, t2: Counter, limit: Optional[int] = 5) -> List[Tuple[str, int]]: | |
return (t2 - t1).most_common(limit) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from yesterday_asof import yesterday | |
def test_yesterday(): | |
assert yesterday(asof=datetime(1983, 1, 1)) == datetime(1982, 12, 31) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
from datetime import timedelta | |
def yesterday(asof: datetime) -> datetime: | |
return asof - timedelta(days=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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)), |
NewerOlder