# 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 mkdir_p(path):
#     try:
#         os.makedirs(path)
#     except:
#         pass
# 
# 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 u32_littleendian(data):
#     if not 0 <= data <= 4294967295:
#         log("u32 little endian out of range: %s" % data, "INFO")
#         data = 0
#     return struct.pack("<I", data)


import binascii
import calendar
import CloudFlare
import difflib
import glob
import json
import nlzss
import os
import pickle
import requests
import subprocess
import sys
import time
import utils
import rsa
from datetime import timedelta, datetime, date
from . import newsdownload
from datadog import statsd
from utils import setup_log, log, mkdir_p, u8, u16, u32, u32_littleendian
    )  # Number of entries for the pictures table.

    if config["production"]:
        statsd.increment("news.total_pictures", pictures_number)

    return pictures_table


# Add the articles


def make_articles(articles_table, pictures_table, data):
    articles = {}
    dictionaries.append(articles)

    numbers = 0

    for article in list(data.values()):
        numbers += 1
        articles_table[
            "headline_%s_offset" % numbers
        ] = offset_count()  # Offset for the headline.
        articles["headline_%s_read" % numbers] = article[3].replace(
            b"\n", b""
        )  # Read the headline.
        articles["padding_%s_headline" % numbers] = u16(0)  # Padding for the headline.
        articles_table[
            "article_%s_offset" % numbers
        ] = offset_count()  # Offset for the article.
        articles["article_%s_read" % numbers] = article[2]  # Read the article.

# 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 mkdir_p(path):
#     try:
#         os.makedirs(path)
#     except:
#         pass
# 
# 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 u32_littleendian(data):
#     if not 0 <= data <= 4294967295:
#         log("u32 little endian out of range: %s" % data, "INFO")
#         data = 0
#     return struct.pack("<I", data)


# Path: Channels/News_Channel/newsmake.py
import binascii
import calendar
import CloudFlare
import difflib
import glob
import json
import nlzss
import os
import pickle
import requests
import subprocess
import sys
import time
import utils
import rsa
from datetime import timedelta, datetime, date
from . import newsdownload
from datadog import statsd
from utils import setup_log, log, mkdir_p, u8, u16, u32, u32_littleendian

    )  # Number of entries for the pictures table.

    if config["production"]:
        statsd.increment("news.total_pictures", pictures_number)

    return pictures_table


# Add the articles


def make_articles(articles_table, pictures_table, data):
    articles = {}
    dictionaries.append(articles)

    numbers = 0

    for article in list(data.values()):
        numbers += 1
        articles_table[
            "headline_%s_offset" % numbers
        ] = offset_count()  # Offset for the headline.
        articles["headline_%s_read" % numbers] = article[3].replace(
            b"\n", b""
        )  # Read the headline.
        articles["padding_%s_headline" % numbers] = u16(0)  # Padding for the headline.
        articles_table[
            "article_%s_offset" % numbers
        ] = offset_count()  # Offset for the article.
        articles["article_%s_read" % numbers] = article[2]  # Read the article.

        articles["padding_%s_article" % numbers] = u16(0)  # Padding for the article.