from openpyxl import load_workbook
import flask
import json
import pandas as pd

months = ['Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun',
          'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez']

wb = load_workbook(filename='Budget_2020.xlsx', data_only=True)

expenses = {}

for month in months:
    expenses[month] = {
        'Needs': '',
        'Wants': '',
        'Savings': ''
    }

sheet_range = wb.sheetnames

for sheet in sheet_range:
    if sheet in months:
        monthNeeds = {}
        monthWants = {}
        for cell in range(9, 28):
            if wb[sheet][f'D{cell}'].value != 0:
                monthNeeds[wb[sheet]
                           [f'A{cell}'].value] = wb[sheet][f'D{cell}'].value
            elif wb[sheet][f'I{cell}'].value != 0:
                monthWants[wb[sheet]
                           [f'F{cell}'].value] = wb[sheet][f'I{cell}'].value
        expenses[sheet]['Needs'] = monthNeeds
        expenses[sheet]['Wants'] = monthWants
        expenses[sheet]['Savings'] = wb[sheet]['N7'].value

# Serialize json
with open("sample.json", "w") as outfile:
    json.dump(expenses, outfile, ensure_ascii=False)

df = pd.DataFrame(expenses["Mar"])
print(df)

# --------------------------------------------------------------------FLASK

# app = flask.Flask(__name__)
# app.config["DEBUG"] = True


# @app.route("/home")
# def home():
#     return flask.render_template("home.html")


# if __name__ == '__main__':
#     app.run(host="localhost", port=8000, debug=True)
