# Path: utils.py
# def setup_log(sentry_url, print_errors):
#     global logger, production
#     sentry_logging = LoggingIntegration(
#         level=logging.INFO,
#         event_level=logging.INFO
#     )
#     sentry_sdk.init(dsn=sentry_url, integrations=[sentry_logging])
#     logger = logging.getLogger(__name__)
#     p_errors = print_errors
#     production = True
# 
# def log(msg, level):  # TODO: Use number levels, strings are annoying
#     if p_errors:
#         print(msg)
# 
#     if production:
#         if level == "VERBOSE":
#             logger.debug(msg)
#         elif level == "INFO":
#             logger.info(msg)
#         elif level == "WARNING":
#             logger.warning(msg)
#         elif level == "CRITICAL":
#             logger.critical(msg)
# 
# def u8(data):
#     if not 0 <= data <= 255:
#         log("u8 out of range: %s" % data, "INFO")
#         data = 0
#     return struct.pack(">B", data)
# 
# def u16(data):
#     if not 0 <= data <= 65535:
#         log("u16 out of range: %s" % data, "INFO")
#         data = 0
#     return struct.pack(">H", data)
# 
# def u32(data):
#     if not 0 <= data <= 4294967295:
#         log("u32 out of range: %s" % data, "INFO")
#         data = 0
#     return struct.pack(">I", data)
# 
# def s8(data):
#     if not -128 <= data <= 127:
#         log("s8 out of range: %s" % data, "INFO")
#         data = 0
#     return struct.pack(">b", data)


import binascii
import calendar
import CloudFlare
import io
import json
import math
import os
import pickle
import queue
import shutil
import subprocess
import sys
import threading
import time
import nlzss
import requests
import rsa
from datetime import datetime
from Channels.Forecast_Channel import forecastlists
from datadog import statsd
from utils import setup_log, log, u8, u16, u32, s8
    )  # Offset for the weather condition code table.
    header["uv_index_number"] = u32(
        len(forecastlists.uvindex)
    )  # Number of UV Index entries.
    header["uv_index_offset"] = u32(0)  # Offset for the UV Index table.
    header["laundry_index_number"] = u32(
        len(forecastlists.laundry)
    )  # Number of Laundry Index entries.
    header["laundry_index_offset"] = u32(0)  # Offset for the Laundry Index table.
    header["pollen_count_number"] = u32(
        len(forecastlists.pollen)
    )  # Number of Pollen Count entries.
    header["pollen_count_offset"] = u32(0)  # Offset for the Pollen Count table.
    header["location_number"] = u32(len(forecast_list))  # Number of location entries.
    header["location_offset"] = u32(0)  # Offset for the location table.

    return header


def make_long_forecast_table(forecast_list):
    long_forecast_table = {}
    for key in forecast_list.keys():
        if (
            matches_country_code(forecast_list, key)
            and get_region(forecast_list, key) != ""
        ):
            keyIndex = list(forecast_list).index(key)
            long_forecast_table["location_code_%s" % keyIndex] = binascii.unhexlify(
                get_locationkey(forecast_list, key)
            )  # Wii Location Code.

# Path: utils.py
# def setup_log(sentry_url, print_errors):
#     global logger, production
#     sentry_logging = LoggingIntegration(
#         level=logging.INFO,
#         event_level=logging.INFO
#     )
#     sentry_sdk.init(dsn=sentry_url, integrations=[sentry_logging])
#     logger = logging.getLogger(__name__)
#     p_errors = print_errors
#     production = True
# 
# def log(msg, level):  # TODO: Use number levels, strings are annoying
#     if p_errors:
#         print(msg)
# 
#     if production:
#         if level == "VERBOSE":
#             logger.debug(msg)
#         elif level == "INFO":
#             logger.info(msg)
#         elif level == "WARNING":
#             logger.warning(msg)
#         elif level == "CRITICAL":
#             logger.critical(msg)
# 
# def u8(data):
#     if not 0 <= data <= 255:
#         log("u8 out of range: %s" % data, "INFO")
#         data = 0
#     return struct.pack(">B", data)
# 
# def u16(data):
#     if not 0 <= data <= 65535:
#         log("u16 out of range: %s" % data, "INFO")
#         data = 0
#     return struct.pack(">H", data)
# 
# def u32(data):
#     if not 0 <= data <= 4294967295:
#         log("u32 out of range: %s" % data, "INFO")
#         data = 0
#     return struct.pack(">I", data)
# 
# def s8(data):
#     if not -128 <= data <= 127:
#         log("s8 out of range: %s" % data, "INFO")
#         data = 0
#     return struct.pack(">b", data)


# Path: Channels/Forecast_Channel/forecast.py
import binascii
import calendar
import CloudFlare
import io
import json
import math
import os
import pickle
import queue
import shutil
import subprocess
import sys
import threading
import time
import nlzss
import requests
import rsa
from datetime import datetime
from Channels.Forecast_Channel import forecastlists
from datadog import statsd
from utils import setup_log, log, u8, u16, u32, s8

    )  # Offset for the weather condition code table.
    header["uv_index_number"] = u32(
        len(forecastlists.uvindex)
    )  # Number of UV Index entries.
    header["uv_index_offset"] = u32(0)  # Offset for the UV Index table.
    header["laundry_index_number"] = u32(
        len(forecastlists.laundry)
    )  # Number of Laundry Index entries.
    header["laundry_index_offset"] = u32(0)  # Offset for the Laundry Index table.
    header["pollen_count_number"] = u32(
        len(forecastlists.pollen)
    )  # Number of Pollen Count entries.
    header["pollen_count_offset"] = u32(0)  # Offset for the Pollen Count table.
    header["location_number"] = u32(len(forecast_list))  # Number of location entries.
    header["location_offset"] = u32(0)  # Offset for the location table.

    return header


def make_long_forecast_table(forecast_list):
    long_forecast_table = {}
    for key in forecast_list.keys():
        if (
            matches_country_code(forecast_list, key)
            and get_region(forecast_list, key) != ""
        ):
            keyIndex = list(forecast_list).index(key)
            long_forecast_table["location_code_%s" % keyIndex] = binascii.unhexlify(
                get_locationkey(forecast_list, key)
            )  # Wii Location Code.

            long_forecast_table["timestamp_1_%s" % keyIndex] = u32(