# 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

def make_short_forecast_table(forecast_list):
    short_forecast_table = {}
    for key in forecast_list.keys():
        keyIndex = list(forecast_list).index(key)
        short_forecast_table["location_code_%s" % keyIndex] = binascii.unhexlify(
            get_locationkey(forecast_list, key)
        )  # Wii location code for city
        short_forecast_table["timestamp_1_%s" % keyIndex] = u32(
            timestamps(1, key)
        )  # Timestamp 1
        short_forecast_table["timestamp_2_%s" % keyIndex] = u32(
            timestamps(0, key)
        )  # Timestamp 2
        short_forecast_table["current_forecast_%s" % keyIndex] = binascii.unhexlify(
            current[key][5]
        )  # Current forecast
        short_forecast_table["unknown_%s" % keyIndex] = u8(0)  # 0xE unknown
        short_forecast_table["current_tempc_%s" % keyIndex] = s8(
            current[key][4]
        )  # Current temperature in Celsius
        short_forecast_table["current_tempf_%s" % keyIndex] = s8(
            current[key][3]
        )  # Current temperature in Fahrenheit
        short_forecast_table["current_winddirection_%s" % keyIndex] = u8(
            int(get_wind_direction(current[key][0]))
        )  # Current wind direction
        short_forecast_table["current_windkm_%s" % keyIndex] = u8(
            current[key][1]
        )  # Current wind in km/hr

# 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


def make_short_forecast_table(forecast_list):
    short_forecast_table = {}
    for key in forecast_list.keys():
        keyIndex = list(forecast_list).index(key)
        short_forecast_table["location_code_%s" % keyIndex] = binascii.unhexlify(
            get_locationkey(forecast_list, key)
        )  # Wii location code for city
        short_forecast_table["timestamp_1_%s" % keyIndex] = u32(
            timestamps(1, key)
        )  # Timestamp 1
        short_forecast_table["timestamp_2_%s" % keyIndex] = u32(
            timestamps(0, key)
        )  # Timestamp 2
        short_forecast_table["current_forecast_%s" % keyIndex] = binascii.unhexlify(
            current[key][5]
        )  # Current forecast
        short_forecast_table["unknown_%s" % keyIndex] = u8(0)  # 0xE unknown
        short_forecast_table["current_tempc_%s" % keyIndex] = s8(
            current[key][4]
        )  # Current temperature in Celsius
        short_forecast_table["current_tempf_%s" % keyIndex] = s8(
            current[key][3]
        )  # Current temperature in Fahrenheit
        short_forecast_table["current_winddirection_%s" % keyIndex] = u8(
            int(get_wind_direction(current[key][0]))
        )  # Current wind direction
        short_forecast_table["current_windkm_%s" % keyIndex] = u8(
            current[key][1]
        )  # Current wind in km/hr

        short_forecast_table["current_windmph_%s" % keyIndex] = u8(