# This Script uses the following dependancies
# pip install nums_from_string
#
# To Run this script type:
# python snow.py <Log File Name>
#
# Example:
# python snow.py snow.log
#
# Written By Allstreamer_
# Licenced Under MIT

import nums_from_string
import sys

lines = []

with open(sys.argv[1], "r") as file:
    lines = file.readlines()

lines = [row.strip() for row in lines]
lines = filter(lambda row: "In the" in row, lines)
lines = [row.split(",", 1)[1] for row in lines]

lines = list(filter(lambda row: not nums_from_string.get_nums(row)[0] == 0, lines))

connections = lines
connections = sum([nums_from_string.get_nums(row)[0] for row in connections])


lines = [row.split("Relayed")[1] for row in lines]

upload = [row.split(",")[0].strip() for row in lines]
# print("\n".join(upload))
# print(f"'{upload[4]}'")

download = [row.split(",")[1].strip()[:-1] for row in lines]
# print(download)
# print(f"'{download[4]}'")

def get_byte_count(log_lines):
    byte_count = 0
    for row in log_lines:
        symbols = row.split(" ")

        if symbols[2] == "B":
           byte_count += int(symbols[1])
        elif symbols[2] == "KB":
           byte_count += int(symbols[1]) * 1024
        elif symbols[2] == "MB":
           byte_count += int(symbols[1]) * 1024 * 1024
        elif symbols[2] == "GB":
           byte_count += int(symbols[1]) * 1024 * 1024 * 1024
    return byte_count

upload_gb = get_byte_count(upload) / 1024 / 1024 / 1024
download_gb = get_byte_count(download) / 1024 / 1024 / 1024

print(f"Served {connections} People with ↑ {round(upload_gb,4)} GB, ↓ {round(download_gb,4)} GB")