# 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)


import binascii
import calendar
import CloudFlare
import datetime
import json
import logging
import nlzss
import os
import struct
import subprocess
import sys
import textwrap
import time
import MySQLdb
import requests
import rsa
from utils import setup_log, log, u8, u16, u32
from Channels.Everybody_Votes_Channel.voteslists import *
    print("Writing Completed")

    for dictionary in dictionaries:
        dictionary.clear()

def make_header():
    header = collections.OrderedDict()
    dictionaries.append(header)

    header["timestamp"] = u32(get_timestamp(0, None, None))
    header["country_code"] = u8(country_code)
    header["publicity_flag"] = u8(0)
    header["question_version"] = u8(0 if file_type == "r" else 1)
    header["result_version"] = u8(1 if file_type == "r" else 0)
    header["national_question_number"] = u8(national)
    header["national_question_offset"] = u32(0)
    header["worldwide_question_number"] = u8(worldwide)
    header["worldwide_question_offset"] = u32(0)
    header["question_number"] = u8(questions * len(country_language[country_code]))
    header["question_offset"] = u32(0)
    header["national_result_entry"] = u8(national_results)
    header["national_result_offset"] = u32(0)
    header["national_result_detailed_number"] = u16(national_results * region_number[country_code])
    header["national_result_detailed_offset"] = u32(0)
    header["position_number"] = u16(0 if file_type == "q" or national_results == 0 else 22 if country_code == 77 else len(position_table[country_code]) if country_code in list(position_table.keys()) else 0)
    header["position_offset"] = u32(0)
    header["worldwide_result_number"] = u8(worldwide_results)
    header["worldwide_result_offset"] = u32(0)
    header["worldwide_result_detailed_number"] = u16(0)
    header["worldwide_result_detailed_offset"] = u32(0)

# 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)


# Path: Channels/Everybody_Votes_Channel/votes.py
import binascii
import calendar
import CloudFlare
import datetime
import json
import logging
import nlzss
import os
import struct
import subprocess
import sys
import textwrap
import time
import MySQLdb
import requests
import rsa
from utils import setup_log, log, u8, u16, u32
from Channels.Everybody_Votes_Channel.voteslists import *

    print("Writing Completed")

    for dictionary in dictionaries:
        dictionary.clear()

def make_header():
    header = collections.OrderedDict()
    dictionaries.append(header)

    header["timestamp"] = u32(get_timestamp(0, None, None))
    header["country_code"] = u8(country_code)
    header["publicity_flag"] = u8(0)
    header["question_version"] = u8(0 if file_type == "r" else 1)
    header["result_version"] = u8(1 if file_type == "r" else 0)
    header["national_question_number"] = u8(national)
    header["national_question_offset"] = u32(0)
    header["worldwide_question_number"] = u8(worldwide)
    header["worldwide_question_offset"] = u32(0)
    header["question_number"] = u8(questions * len(country_language[country_code]))
    header["question_offset"] = u32(0)
    header["national_result_entry"] = u8(national_results)
    header["national_result_offset"] = u32(0)
    header["national_result_detailed_number"] = u16(national_results * region_number[country_code])
    header["national_result_detailed_offset"] = u32(0)
    header["position_number"] = u16(0 if file_type == "q" or national_results == 0 else 22 if country_code == 77 else len(position_table[country_code]) if country_code in list(position_table.keys()) else 0)
    header["position_offset"] = u32(0)
    header["worldwide_result_number"] = u8(worldwide_results)
    header["worldwide_result_offset"] = u32(0)
    header["worldwide_result_detailed_number"] = u16(0)
    header["worldwide_result_detailed_offset"] = u32(0)

    header["country_name_number"] = u16(len(countries) * 7 if file_type == "r" and arg == "w" else 0 if file_type == "q" or file_type == "r" else len(countries) * 7)