# 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 *
    if file_type == "q" or file_type == "r":
        question_file = get_name() + "_" + file_type

    else:
        question_file = "voting"
    
    print("Writing to %s.bin ..." % question_file)

    with open(question_file, "wb") as f:
        for dictionary in dictionaries:
            # print("Writing to %s ..." % hex(f.tell()).rstrip("L"))
            for name, values in dictionary.items():
                f.write(values)
        f.write(pad(16))
        f.write('RIICONNECT24'.encode("ASCII"))
        f.flush()

    if config["production"]:
        sign_file(question_file)

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

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

    if file_type == "q" or file_type == "r":
        question_file = get_name() + "_" + file_type

    else:
        question_file = "voting"
    
    print("Writing to %s.bin ..." % question_file)

    with open(question_file, "wb") as f:
        for dictionary in dictionaries:
            # print("Writing to %s ..." % hex(f.tell()).rstrip("L"))
            for name, values in dictionary.items():
                f.write(values)
        f.write(pad(16))
        f.write('RIICONNECT24'.encode("ASCII"))
        f.flush()

    if config["production"]:
        sign_file(question_file)

    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)