#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Coded by L1ghtM3n@protonmail.com

""" Geolocation info """
class GeoData(object):
    def __init__(self, geo_data: dict):
        u = "Unknown"
        self.ip_address = geo_data["ip_address"]
        try: self.city = geo_data["city"]["names"]["en"]
        except: self.city = u
        try: self.country = geo_data["country"]["names"]["en"]
        except: self.country = u
        try: self.iso_code = geo_data["country"]["iso_code"]
        except: self.iso_code = u

""" Get country statistics """
def GetCountryStatistics(reports: list) -> dict:
    stats = {}
    for report in reports:
        if not report.geo_data.iso_code in stats:
            stats[report.geo_data.iso_code] = []
        stats[report.geo_data.iso_code].append(report.geo_data)
    return stats
