Advertisement
larsmrx

dailycheck

Nov 13th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.85 KB | None | 0 0
  1. #! python3
  2. # dailycheck automatization
  3.  
  4. import os, isoweek, locale
  5. from openpyxl import *
  6. import datetime as dt
  7. import logging, copy
  8.  
  9. logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
  10. kw_num = input("Bitte die Nummer der Kalenderwoche eingeben ")
  11. jahr = dt.date.today().year
  12. kw = isoweek.Week(jahr, int(kw_num)) # getting the week object from isoweek
  13. daterange = [x for x in kw.days()] # generating days of given week
  14. daterange.pop() #removing sunday
  15. strdate = []
  16.  
  17. #creating date range for give week
  18. for dat in daterange:
  19.         strdate.append(dt.date.strftime(dat, "%Y%m%d"))
  20.  
  21. # setting german locale for Month-folder name
  22. locale.setlocale(locale.LC_ALL, 'de_DE')
  23.  
  24. # finding the month
  25. monat = dt.date.strftime(dt.datetime.strptime(str(dt.date.today().month), '%m'), "%B")
  26. monat1 = dt.date.today().month
  27.  
  28. #changing dirs to where the EoS' are
  29. os.chdir(f"C:\\Users\\CarolaNiemeier\\Dropbox\\Shared_PrimeNow\\EoS\\{jahr}\\{monat}\\KW{kw_num}")
  30. hours_from_eos = []
  31.  
  32. # building a list of daily workhours
  33. for a,b in enumerate(strdate):
  34.         eos_name = f'{b} UDE3 SystemLogistik EoS Hours.xlsm'
  35.         try:
  36.                 wb =load_workbook(eos_name, data_only=True)
  37.                 ws = wb['SITE-DSP-EOS']
  38.                 hours_from_eos.append(ws['Y16'].value)
  39.                 wb.close()
  40.         except:
  41.                 print("Error encountered. File not found")
  42.  
  43. #creating a stringified daterange
  44. for i in strdate:
  45.         print(i)
  46. dcwb = load_workbook(f"C:\\Users\\CarolaNiemeier\\Dropbox\\Shared_PrimeNow\\Daily-Check\\DailyCheck_{kw.year}-bak.xlsx")
  47. dcws_source = dcwb['KW_XX']
  48. dcws = dcwb.copy_worksheet(dcws_source)
  49. dcws.title = str(kw)
  50.  
  51. #setting the daterange in cells
  52. for x,y in enumerate(daterange, start=2):
  53.         dcws[f'A{x}'] = y
  54. for x,y in enumerate(daterange, start=12):
  55.         #cell = 'A' + str(x)
  56.         dcws[f'A{x}'] = y
  57. print(hours_from_eos)
  58. for x,y in enumerate(hours_from_eos, start=2):
  59.         #cell = 'E' + str(x)
  60.         dcws[f'E{x}'] = y
  61. dcwb.move_sheet(dcwb[f'{str(kw)}'], -(len(dcwb._sheets) -1))
  62.  
  63. #going to the endlist folder
  64. os.chdir("C:\\Users\\CarolaNiemeier\\Dropbox\\Shared_PrimeNow\\Endlist\\Neu\\2019")
  65. endlist = load_workbook(f"Endlist_{monat1}_2019.xlsx", data_only=True)
  66. endlistws = endlist.active
  67.  
  68. ###############find the week and add the hours to a list
  69. endlist_hrs = {}
  70.  
  71. #creating a dict with dates as keys and empty lists as values
  72. for cell in endlistws['B']:
  73.         if cell.value == int(kw_num):
  74.                 logging.debug(f"cell value is {cell.value}")
  75.                 if endlistws[f'A{cell.row}'].value in endlist_hrs.keys():
  76.                         continue
  77.                 else:
  78.                         endlist_hrs[str(endlistws[f'A{cell.row}'].value)] = []
  79.  
  80.  
  81.  
  82. for cell in endlistws['B']:
  83.         logging.debug(f"iterating cols, cell value is {cell.value}")
  84.         if cell.value == int(kw_num):
  85.                 if str(endlistws[f'A{cell.row}'].value) in endlist_hrs.keys():
  86.                         ##vector = vector + int(dt.time.strftime(endlistws[f'J{cell.row}'].value, "%H"))
  87.                         endlist_hrs[endlistws[f'A{cell.row}'].value].append(int(dt.time.strftime(endlistws[f'J{cell.row}'].value, "%H")))
  88.                 else:
  89.                      pass
  90.                                                         #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)
  91.                                 #vector += int(dt.time.strftime(endlistws[f'J{cell.row}'].value, "%H"))
  92.  
  93.  
  94.  
  95. print_ready_hrs = {k:sum(v) for (k,v) in endlist_hrs.items()}
  96. ##
  97. ##for x,y in enumerate(endlist_hrs, start=2):
  98. ##        dcws[f'D{x}'] = y
  99. ##endlist.close()
  100. ##os.chdir("C:\\Users\\CarolaNiemeier\\Documents\\testfolder\\rbwdc")
  101. ##dcwb.save("dailychecktest.xlsx")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement