Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! python3
- # dailycheck automatization
- import os, isoweek, locale
- from openpyxl import *
- import datetime as dt
- import logging, copy
- logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
- kw_num = input("Bitte die Nummer der Kalenderwoche eingeben ")
- jahr = dt.date.today().year
- kw = isoweek.Week(jahr, int(kw_num)) # getting the week object from isoweek
- daterange = [x for x in kw.days()] # generating days of given week
- daterange.pop() #removing sunday
- strdate = []
- #creating date range for give week
- for dat in daterange:
- strdate.append(dt.date.strftime(dat, "%Y%m%d"))
- # setting german locale for Month-folder name
- locale.setlocale(locale.LC_ALL, 'de_DE')
- # finding the month
- monat = dt.date.strftime(dt.datetime.strptime(str(dt.date.today().month), '%m'), "%B")
- monat1 = dt.date.today().month
- #changing dirs to where the EoS' are
- os.chdir(f"C:\\Users\\CarolaNiemeier\\Dropbox\\Shared_PrimeNow\\EoS\\{jahr}\\{monat}\\KW{kw_num}")
- hours_from_eos = []
- # building a list of daily workhours
- for a,b in enumerate(strdate):
- eos_name = f'{b} UDE3 SystemLogistik EoS Hours.xlsm'
- try:
- wb =load_workbook(eos_name, data_only=True)
- ws = wb['SITE-DSP-EOS']
- hours_from_eos.append(ws['Y16'].value)
- wb.close()
- except:
- print("Error encountered. File not found")
- #creating a stringified daterange
- for i in strdate:
- print(i)
- dcwb = load_workbook(f"C:\\Users\\CarolaNiemeier\\Dropbox\\Shared_PrimeNow\\Daily-Check\\DailyCheck_{kw.year}-bak.xlsx")
- dcws_source = dcwb['KW_XX']
- dcws = dcwb.copy_worksheet(dcws_source)
- dcws.title = str(kw)
- #setting the daterange in cells
- for x,y in enumerate(daterange, start=2):
- dcws[f'A{x}'] = y
- for x,y in enumerate(daterange, start=12):
- #cell = 'A' + str(x)
- dcws[f'A{x}'] = y
- print(hours_from_eos)
- for x,y in enumerate(hours_from_eos, start=2):
- #cell = 'E' + str(x)
- dcws[f'E{x}'] = y
- dcwb.move_sheet(dcwb[f'{str(kw)}'], -(len(dcwb._sheets) -1))
- #going to the endlist folder
- os.chdir("C:\\Users\\CarolaNiemeier\\Dropbox\\Shared_PrimeNow\\Endlist\\Neu\\2019")
- endlist = load_workbook(f"Endlist_{monat1}_2019.xlsx", data_only=True)
- endlistws = endlist.active
- ###############find the week and add the hours to a list
- endlist_hrs = {}
- #creating a dict with dates as keys and empty lists as values
- for cell in endlistws['B']:
- if cell.value == int(kw_num):
- logging.debug(f"cell value is {cell.value}")
- if endlistws[f'A{cell.row}'].value in endlist_hrs.keys():
- continue
- else:
- endlist_hrs[str(endlistws[f'A{cell.row}'].value)] = []
- for cell in endlistws['B']:
- logging.debug(f"iterating cols, cell value is {cell.value}")
- if cell.value == int(kw_num):
- if str(endlistws[f'A{cell.row}'].value) in endlist_hrs.keys():
- ##vector = vector + int(dt.time.strftime(endlistws[f'J{cell.row}'].value, "%H"))
- endlist_hrs[endlistws[f'A{cell.row}'].value].append(int(dt.time.strftime(endlistws[f'J{cell.row}'].value, "%H")))
- else:
- pass
- #endlist_hrs[str(endlistws[f'A{cell.row}'].value)] = int(dt.time.strftime(endlistws[f'J{cell.row}'].value, "%H"))#int(endlistws[f'J{cell.row}'].value)
- #vector += int(dt.time.strftime(endlistws[f'J{cell.row}'].value, "%H"))
- print_ready_hrs = {k:sum(v) for (k,v) in endlist_hrs.items()}
- ##
- ##for x,y in enumerate(endlist_hrs, start=2):
- ## dcws[f'D{x}'] = y
- ##endlist.close()
- ##os.chdir("C:\\Users\\CarolaNiemeier\\Documents\\testfolder\\rbwdc")
- ##dcwb.save("dailychecktest.xlsx")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement