File size: 2,304 Bytes
bc92a1b
 
 
6506ce9
bc92a1b
 
 
 
6506ce9
 
 
bc92a1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4680ed9
bc92a1b
 
 
 
 
4fbb7a3
 
 
bc92a1b
 
 
 
 
 
 
 
4680ed9
bc92a1b
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from io import BytesIO
from openpyxl import Workbook
from openpyxl.styles import Font, NamedStyle, PatternFill
# from openpyxl.styles.differential import DifferentialStyle
import logging
from logging.handlers import RotatingFileHandler
import os
import configparser
import logging

logger = logging.getLogger(__name__)

def setup_logging():
    # Set up logging
    log_dir = 'logs'
    os.makedirs(log_dir, exist_ok=True)
    log_file = os.path.join(log_dir, 'app.log')

    # Create a RotatingFileHandler
    file_handler = RotatingFileHandler(log_file, maxBytes=1024 * 1024, backupCount=5)
    file_handler.setFormatter(logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s'))

    # Configure the root logger
    logging.basicConfig(level=logging.INFO,
                        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                        handlers=[file_handler, logging.StreamHandler()])

    # Return a logger instance
    return logging.getLogger(__name__)


def getconfig(configfile_path: str):
    """
    Read the config file
    Params
    ----------------
    configfile_path: file path of .cfg file
    """
    config = configparser.ConfigParser()
    try:
        config.read_file(open(configfile_path))
        return config
    except:
        logging.warning("config file not found")

# Function for creating Upload template file
def create_excel():
    wb = Workbook()
    sheet = wb.active
    sheet.title = "template"
    columns = ['id',
               'country',
               'organization',
               'scope',
               'technology',
               'financial',
               'barrier',
               'technology_rationale',
               'project_rationale',
               'project_objectives',
               'maf_funding_requested',
               'contributions_public_sector',
               'contributions_private_sector',
               'contributions_other',
               'mitigation_potential']
    sheet.append(columns)  # Appending columns to the first row

    # formatting
    for c in sheet['A1:O4'][0]:
        c.fill = PatternFill('solid', fgColor = 'bad8e1')
        c.font = Font(bold=True)

    # Save to a BytesIO object
    output = BytesIO()
    wb.save(output)
    return output.getvalue()