浏览代码

- Testlauf Timmermanns und Böttche
- erster Entwurf der neuen Tasks

Robert Bedner 4 年之前
父节点
当前提交
fa6c6147d1
共有 8 个文件被更改,包括 180 次插入6 次删除
  1. 38 0
      gctools/impromptu.mac
  2. 二进制
      gctools/impromptu.mcx
  3. 67 0
      gctools/impromptu.py
  4. 29 0
      gctools/pdf-test.py
  5. 8 0
      gctools/portal.bat
  6. 7 6
      gctools/portal.py
  7. 二进制
      gctools/publish-reports.mcx
  8. 31 0
      gctools/refresh.py

+ 38 - 0
gctools/impromptu.mac

@@ -0,0 +1,38 @@
+Dim objApp As Object
+Dim objRep as Object
+
+Dim imrFile as String
+Dim catalogFile as String
+Dim exportFile As String
+Dim exportFormat As String
+
+
+Sub Main ()
+   rem On Error Resume Next
+
+   rem imrFile = "C:\GAPS\Portal\System\IQD\Belege\Belege.imr"
+   rem catalogFile = "C:\GAPS\Portal\System\Catalogs\Finance.cat"
+   rem exportFile = "C:\GAPS\Portal\System\Export\Belege.csv"
+   rem exportFormat = "x_ascii.flt"
+   
+   imrFile = GetField(Command, 1, ",")
+   catalogFile = GetField(Command, 2, ",")
+   exportFile = GetField(Command, 3, ",")
+   exportFormat = GetField(Command, 4, ",")
+   
+   
+   Set objApp = CreateObject("CognosImpromptu.Application")
+   objApp.OpenCatalog catalogFile, "Ersteller"
+   Set objRep = objApp.OpenReport(imrFile)
+   objRep.RetrieveAll
+   If exportFormat = "ims" Then
+      objRep.ExportHotFile(exportFile)
+   Else
+      objRep.Export exportFile, exportFormat
+   End If
+   objRep.CloseReport
+   objApp.Quit
+   Set objRep = Nothing
+   Set objApp = Nothing
+
+End Sub

二进制
gctools/impromptu.mcx


+ 67 - 0
gctools/impromptu.py

@@ -0,0 +1,67 @@
+import plac
+import subprocess
+import re
+from pathlib import Path
+from datetime import datetime
+import config
+
+cfg = config.config()
+imr_dir = cfg.portal_dir + '\\System\\IQD'
+catalog_dir = cfg.portal_dir + '\\System\\Catalogs'
+
+export_translation = {
+    'csv': 'x_ascii.flt',
+    'xls': 'x_excel.flt',
+    'sql': 'x_sql.flt',
+    'txt': 'x_text.flt',
+    'iqd': 'x_iqd.flt',
+    'ims': 'ims'
+}
+min_filesize = 2000   # 1 kB
+
+
+@plac.pos('imr_file', '', type=str)
+@plac.opt('export_format', '', type=str)
+@plac.opt('export_dir', '', type=str)
+@plac.opt('catalog', '', type=str)
+def export(imr_file, export_format='csv', export_dir=None, catalog=None):
+    imr_full_filename = imr_dir + '\\' + imr_file
+    export_filename = Path(imr_full_filename).name[:-3] + export_format
+    if export_dir is None:
+        export_dir = str(Path(imr_full_filename).parent)
+    export_full_filename = f'{export_dir}\\{export_filename}'
+    if catalog is None:
+        catalog = catalog_name(imr_file)
+    if catalog[-4:] != '.cat':
+        catalog = catalog + '.cat'
+    catalog_full_filename = f'{catalog_dir}\\{catalog}'
+    start = datetime.now().timestamp()
+    cmd = f'"{cfg.cognos_dir}\\runmac32.exe" "{cfg.tools_dir}\\impromptu.mac" "{imr_full_filename}","{catalog_full_filename}","{export_full_filename}","{export_translation[export_format]}"'
+    print(f"Exportiere '{imr_file}' als '{export_format}' nach '{export_dir}'...", end='')
+
+    p = subprocess.Popen(cmd)
+    p.wait()
+    if Path(export_full_filename).exists():
+        export_stat = Path(export_full_filename).stat()
+        if export_stat.st_mtime > start and export_stat.st_size > min_filesize:
+            print('erfolgreich.')
+            filesize_kb = round(export_stat.st_size / 1024)
+            stop = datetime.now().timestamp()
+            delta = round((stop - start))
+            print(str(filesize_kb) + ' KB in ' + str(delta // 60) + ':' + str(delta % 60).zfill(2) + ' min geschrieben.')
+            return
+    print('fehlgeschlagen.')
+
+
+def catalog_name(imr_file):
+    p = re.compile(r'catalogs\\([^\.]+)\.cat', re.IGNORECASE)
+    with open(imr_dir + '\\' + imr_file, 'r', errors='ignore') as f:
+        for line in f.readlines():
+            m = p.search(line)
+            if m:
+                return p.match(m.group()).groups()[0].lower()
+
+
+if __name__ == '__main__':
+    # plac.call(export)
+    export('Belege\\current_date_Prognose.imr', 'ims')

+ 29 - 0
gctools/pdf-test.py

@@ -0,0 +1,29 @@
+import pdfplumber
+import re
+import json
+from pathlib import Path
+from datetime import datetime, timedelta
+
+today = datetime.now()
+yesterday = today - timedelta(days=1)
+current_date = [today.strftime('%d.%m.%Y'), today.strftime('%d/%m/%Y'), yesterday.strftime('%d.%m.%Y'), yesterday.strftime('%d/%m/%Y')]
+errors = {
+    'empty': [],
+    'outdated': []
+}
+
+files = [f for f in Path('C:\\GAPS_BMW\\Portal\\Publish\\daten\\GAPS_BMW_neu').glob('*.pdf')]
+files_count = len(files)
+
+for i, f in enumerate(files):
+    print(f'({i}/{files_count}) {f.name}                 ', end='\r')
+    with pdfplumber.open(str(f)) as pdf:
+        text = pdf.pages[0].extract_text()
+        if re.search(r'\d+ von \d+$', text):
+            errors['empty'].append(f.name)
+        report_date = re.search(r'\d{2}[\./]\d{2}[\./]\d{4}', text.split('\n')[0])
+        if report_date is not None and report_date.group() not in current_date:
+            errors['outdated'].append([f.name, report_date.group()])
+
+print()
+print(json.dumps(errors, indent=2))

+ 8 - 0
gctools/portal.bat

@@ -0,0 +1,8 @@
+@call "%~dp0config.bat" 0 > nul
+if [%~1]==[] (
+  echo Aufruf: call portal.bat Beispiel.xml [Benutzer|*] [Cube]
+  goto :eof
+)
+
+..\python\python.exe portal.py %~n1
+..\Python\python.exe pdf-test.py

+ 7 - 6
gctools/portal.py

@@ -9,7 +9,7 @@ import config
 
 cfg = config.config()
 report_dir = cfg.portal_dir + '\\System\\Report'
-publish_dir = cfg.portal_dir + '\\daten'
+publish_dir = cfg.portal_dir + '\\Publish\\daten'
 
 
 @plac.pos('config_file', '', type=str)
@@ -21,17 +21,18 @@ def portal(config_file='GAPS_neu'):
         return
     prepare_report_temp(config_file)
     pub_dir = Path(f'{publish_dir}\\{config_file}')
+    rep_dir = f'{report_dir}\\{config_file}'
     if not pub_dir.exists():
         pub_dir.mkdir()
 
     with open(f'{cfg.log_dir}\\{config_file}.mac.log', 'w') as logfile:
-        export_files('jpg', pub_dir, logfile)
-        export_files('xls', pub_dir, logfile)
-        export_files('pdf', pub_dir, logfile)
+        export_files('jpg', rep_dir, pub_dir, logfile)
+        export_files('xls', rep_dir, pub_dir, logfile)
+        export_files('pdf', rep_dir, pub_dir, logfile)
 
 
-def export_files(export_format, pub_dir, logfile):
-    rep_dir = f'{report_dir}\\{export_format}'
+def export_files(export_format, rep_dir, pub_dir, logfile):
+    rep_dir = f'{rep_dir}\\{export_format}'
     cmd = f'"{cfg.cognos_dir}\\runmac32.exe" "{cfg.tools_dir}\\publish-reports.mac" "{rep_dir}","{export_format}","{pub_dir}"'
     print(f"Exportiere '{rep_dir}' nach '{pub_dir}'...")
     start = datetime.now().timestamp()

二进制
gctools/publish-reports.mcx


+ 31 - 0
gctools/refresh.py

@@ -0,0 +1,31 @@
+import plac
+import win32com.client
+from pathlib import Path
+
+
+@plac.pos('filename', '', type=Path)
+def refresh(filename):
+    excel = win32com.client.Dispatch('Excel.Application')
+    excel.DisplayAlerts = False
+
+    print(filename.resolve())
+    wb = excel.Workbooks.Open(filename.resolve())
+
+    try:
+        for source in wb.LinkSources(1):
+            print(' --> ' + source)
+            if Path(source).exists():
+                excel.Workbooks.Open(source)
+            else:
+                print('     !! does not exist !!')
+    except TypeError:
+        print(' --> ' + 'no LinkSources')
+
+    wb.RefreshAll()
+    wb.Save()
+    wb.Close(True)
+    excel.Application.Quit()
+
+
+if __name__ == '__main__':
+    plac.call(refresh)