# Path: lib/sitkaAPI.py
# def APIGet(url, absolute=False):
#     """
#     GET Wrapper around APIGet
#     :param url:
#     :param absolute:
#     :return:
#     """
#     log = Logger("APIGet")
#     #log.info("Making Call: GET {}".format(url))
#     return APICall(url, absolute, method=requests.get)
# 
# Path: lib/env.py
# def setEnvFromFile(batFilePath, verbose = False):
# 
# Path: lib/loghelper.py
# class Logger():
#     """
#     Think of this class like a light interface
#     """
# 
#     def __init__(self, method=""):
#         self.instance = _LoggerSingleton()
#         self.method = method
# 
#     def setup(self, **kwargs):
#         self.instance.setup(**kwargs)
# 
#     def print_(self, message, **kwargs):
#         self.instance.logprint(message, **kwargs)
# 
#     def debug(self, *args):
#         """
#         This works a little differently. You can basically throw anything you want into it.
#         :param message:
#         :return:
#         """
#         msgarr =  []
#         for arg in args:
#             if type(arg) is str:
#                 msgarr.append(arg)
#             else:
#                 msgarr.append(pformat(arg))
#         finalmessage = '\n'.join(msgarr).replace('\n', '\n              ')
#         self.instance.logprint(finalmessage, self.method, "debug")
# 
#     def destroy(self):
#         self.instance = None
#         self.method = None
# 
#     def info(self, message):
#         self.instance.logprint(message, self.method, "info")
# 
#     def error(self, message, exception=None):
#         self.instance.logprint(message, self.method, "error", exception)
# 
#     def warning(self, message, exception=None):
#         self.instance.logprint(message, self.method, "warning", exception)


import os
import sys, traceback
import argparse
import sqlite3
import json
from lib.sitkaAPI import APIGet
from lib import env
from lib.loghelper import Logger
from datetime import datetime

    log = Logger('Download')

    if not file_dict['name']:
        log.warning('Missing file name in folder {}'.format(folder))
        return

    if not file_dict['downloadUrl'] or file_dict['downloadUrl'].lower() == '?download':
        log.warning('Missing download URL in folder {}'.format(folder))
        return

    file_path = os.path.join(folder, file_dict['name'])

    if not os.path.isdir(folder):
        os.makedirs(folder)

    # Write file info as JSON
    with open( os.path.splitext(file_path)[0] + '.json', 'w') as json_file:
        json.dump(file_dict, json_file)

    # Skip files that exist unless they are zero bytes in which case remove them
    if os.path.isfile(file_path):
        if os.stat(file_path).st_size == 0:
            log.warning('Removing zero byte file {}'.format(file_path))
            os.remove(file_path)
        else:
            return

    # Download missing file
    with open(file_path, 'w+b') as f:

# Path: lib/sitkaAPI.py
# def APIGet(url, absolute=False):
#     """
#     GET Wrapper around APIGet
#     :param url:
#     :param absolute:
#     :return:
#     """
#     log = Logger("APIGet")
#     #log.info("Making Call: GET {}".format(url))
#     return APICall(url, absolute, method=requests.get)
# 
# Path: lib/env.py
# def setEnvFromFile(batFilePath, verbose = False):
# 
# Path: lib/loghelper.py
# class Logger():
#     """
#     Think of this class like a light interface
#     """
# 
#     def __init__(self, method=""):
#         self.instance = _LoggerSingleton()
#         self.method = method
# 
#     def setup(self, **kwargs):
#         self.instance.setup(**kwargs)
# 
#     def print_(self, message, **kwargs):
#         self.instance.logprint(message, **kwargs)
# 
#     def debug(self, *args):
#         """
#         This works a little differently. You can basically throw anything you want into it.
#         :param message:
#         :return:
#         """
#         msgarr =  []
#         for arg in args:
#             if type(arg) is str:
#                 msgarr.append(arg)
#             else:
#                 msgarr.append(pformat(arg))
#         finalmessage = '\n'.join(msgarr).replace('\n', '\n              ')
#         self.instance.logprint(finalmessage, self.method, "debug")
# 
#     def destroy(self):
#         self.instance = None
#         self.method = None
# 
#     def info(self, message):
#         self.instance.logprint(message, self.method, "info")
# 
#     def error(self, message, exception=None):
#         self.instance.logprint(message, self.method, "error", exception)
# 
#     def warning(self, message, exception=None):
#         self.instance.logprint(message, self.method, "warning", exception)


# Path: scripts/download_champ_data.py
import os
import sys, traceback
import argparse
import sqlite3
import json
from lib.sitkaAPI import APIGet
from lib import env
from lib.loghelper import Logger
from datetime import datetime


    log = Logger('Download')

    if not file_dict['name']:
        log.warning('Missing file name in folder {}'.format(folder))
        return

    if not file_dict['downloadUrl'] or file_dict['downloadUrl'].lower() == '?download':
        log.warning('Missing download URL in folder {}'.format(folder))
        return

    file_path = os.path.join(folder, file_dict['name'])

    if not os.path.isdir(folder):
        os.makedirs(folder)

    # Write file info as JSON
    with open( os.path.splitext(file_path)[0] + '.json', 'w') as json_file:
        json.dump(file_dict, json_file)

    # Skip files that exist unless they are zero bytes in which case remove them
    if os.path.isfile(file_path):
        if os.stat(file_path).st_size == 0:
            log.warning('Removing zero byte file {}'.format(file_path))
            os.remove(file_path)
        else:
            return

    # Download missing file
    with open(file_path, 'w+b') as f:

        response = APIGet(file_dict['downloadUrl'], absolute=True)