# coding=utf-8

"""
This module, excel_file_generator.py, will be used to generate Excel files.
"""

# This is for creating a new file, I just want to modify an existing template excel file though.
'''
import xlsxwriter

workbook = xlsxwriter.Workbook('hello_world.xlsx')

hours_worksheet = workbook.add_worksheet('Hours')
hours_worksheet.write('A1', 'HELLO HELLO?!')

workbook.close()
'''

import openpyxl

# Check if Ubuntu is running this script.
from sys import platform as _platform
# Needed to get today's date and do other time logic.
import time
import datetime

if _platform == "linux" or _platform == "linux2":
	import sys
	# sys.path.remove('/home/dev_usr/urbtek/nexus_django')
	sys.path.append('/home/dev_usr/urbtek')
	file_path = '/dev/urbtek/universal_code/excel/base_excel_hours_logging.xlsx'
else:
	file_path = '/Users/utarsuno/git_repos/urbtek/urbtek/universal_code/excel/base_excel_hours_logging.xlsx'

# The date format.
FORMAT = '%m/%d/%Y'

today = datetime.datetime.today()
day_of_week = today.weekday()
to_end_of_week = datetime.timedelta(days = 6 - day_of_week)
end_of_week = today + to_end_of_week
to_beginning_of_week = datetime.timedelta(days = day_of_week)
beginning_of_week = today - to_beginning_of_week

monday     = beginning_of_week
tuesday    = beginning_of_week + datetime.timedelta(days=1)
wednesday  = beginning_of_week + datetime.timedelta(days=2)
thursday   = beginning_of_week + datetime.timedelta(days=3)
friday     = beginning_of_week + datetime.timedelta(days=4)
saturday   = beginning_of_week + datetime.timedelta(days=5)
sunday     = beginning_of_week + datetime.timedelta(days=6)
submit_day = beginning_of_week + datetime.timedelta(days=7)

# The cells to work with.
date_submitted  = 'K1'
monday_cells    = ['E4', 'E199', 'E207', monday.strftime(FORMAT)]
tuesday_cells   = ['F4', 'F199', 'F207', tuesday.strftime(FORMAT)]
wednesday_cells = ['G4', 'G199', 'G207', wednesday.strftime(FORMAT)]
thursday_cells  = ['H4', 'H199', 'H207', thursday.strftime(FORMAT)]
friday_cells    = ['I4', 'I199', 'I207', friday.strftime(FORMAT)]
saturday_cells  = ['J4', 'J199', 'J207', saturday.strftime(FORMAT)]
sunday_cells    = ['K4', 'K199', 'K207', sunday.strftime(FORMAT)]
hour_cells      = [monday_cells, tuesday_cells, wednesday_cells, thursday_cells, friday_cells, saturday_cells, sunday_cells]

# Load the Excel file here.
xfile = openpyxl.load_workbook('/Users/utarsuno/git_repos/urbtek/urbtek/universal_code/excel/base_excel_hours_logging.xlsx')

sheet = xfile.get_sheet_by_name('Sheet1')

sheet[date_submitted] = submit_day.strftime(FORMAT)
for c in hour_cells:
	sheet[c[0]] = c[3]
	sheet[c[1]] = c[1]
	sheet[c[2]] = c[2]

xfile.save('HELLO_TEST_YES.xlsx')

'''
today    = datetime.datetime.today()
tomorrow = today + datetime.timedelta(days=1)
print(today.strftime('%m/%d/%Y'))
print(tomorrow.strftime('%m/%d/%Y'))
'''
