First Commit
This commit is contained in:
commit
86ee20229a
89
getHours.py
Normal file
89
getHours.py
Normal file
@ -0,0 +1,89 @@
|
||||
import openpyxl;
|
||||
import gi
|
||||
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gtk
|
||||
|
||||
class AppWindow(Gtk.Window):
|
||||
def __init__(self):
|
||||
Gtk.Window.__init__(self, title="Hours Reporting Tool")
|
||||
self.set_border_width(10)
|
||||
|
||||
hbox = Gtk.Box(spacing=6)
|
||||
self.add(hbox)
|
||||
|
||||
chooseFileBtn = Gtk.Button.new_with_label("Hours File")
|
||||
chooseFileBtn.connect("clicked", self.onChooseFileClicked)
|
||||
hbox.pack_start(chooseFileBtn, False, False, 0)
|
||||
|
||||
def onChooseFileClicked(self, button):
|
||||
dialog = Gtk.FileChooserDialog(title="Choose a file", parent=self, action=Gtk.FileChooserAction.OPEN)
|
||||
dialog.add_buttons(
|
||||
Gtk.STOCK_CANCEL,
|
||||
Gtk.ResponseType.CANCEL,
|
||||
Gtk.STOCK_OPEN,
|
||||
Gtk.ResponseType.OK,
|
||||
)
|
||||
|
||||
self.add_filters(dialog)
|
||||
|
||||
response = dialog.run()
|
||||
if response == Gtk.ResponseType.OK:
|
||||
filePath = dialog.get_filename()
|
||||
print("Loading: " + filePath)
|
||||
dialog.destroy()
|
||||
self.runExcelFiltering(filePath)
|
||||
|
||||
|
||||
def add_filters(self, dialog):
|
||||
filter_excel = Gtk.FileFilter()
|
||||
filter_excel.set_name("Excel Files")
|
||||
filter_excel.add_pattern("*.xlsx")
|
||||
filter_excel.add_pattern("*.xls")
|
||||
dialog.add_filter(filter_excel)
|
||||
|
||||
def runExcelFiltering(self, file):
|
||||
wb = openpyxl.load_workbook(file)
|
||||
sheet = wb.active
|
||||
|
||||
namecolumn = sheet['E']
|
||||
datecolumn = sheet['F']
|
||||
hourscolumn = sheet['G']
|
||||
|
||||
report=[]
|
||||
|
||||
for x in range(1,sheet.max_row):
|
||||
currentName = namecolumn[x].value
|
||||
currentDate = datecolumn[x].value
|
||||
currentHours = hourscolumn[x].value
|
||||
|
||||
if not any (entry['name'] == currentName for entry in report):
|
||||
report.append({
|
||||
"name" : currentName,
|
||||
"entries" : [{
|
||||
"date":currentDate,
|
||||
"hours":currentHours
|
||||
}]
|
||||
})
|
||||
else:
|
||||
for entry in report:
|
||||
if entry['name'] == currentName:
|
||||
entry['entries'].append({
|
||||
"date":currentDate,
|
||||
"hours":currentHours
|
||||
})
|
||||
|
||||
for entry in report:
|
||||
print(entry['name'])
|
||||
hoursTotal = 0
|
||||
for time in entry['entries']:
|
||||
hoursTotal += int(time['hours'])
|
||||
print(str(time['date']) + ", " + time['hours'])
|
||||
print("Total Worked Hours: " + str(hoursTotal))
|
||||
print("------------------------------")
|
||||
|
||||
win = AppWindow()
|
||||
win.connect("destroy", Gtk.main_quit)
|
||||
win.show_all()
|
||||
Gtk.main()
|
||||
|
Loading…
Reference in New Issue
Block a user