Change many
parent
0479efe41d
commit
f9cdb9ae0c
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.12 (REPORT_Export)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (REPORT_Export)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/REPORT_Export.iml" filepath="$PROJECT_DIR$/.idea/REPORT_Export.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
207
main.py
207
main.py
|
|
@ -11,6 +11,7 @@ import http.client, urllib
|
||||||
from openpyxl.styles import Alignment, Font
|
from openpyxl.styles import Alignment, Font
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
date = datetime.now() - timedelta(1)
|
date = datetime.now() - timedelta(1)
|
||||||
month = datetime.now().strftime("%m")
|
month = datetime.now().strftime("%m")
|
||||||
year = datetime.now().strftime("%Y")
|
year = datetime.now().strftime("%Y")
|
||||||
|
|
@ -18,27 +19,42 @@ start_date_00 = date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
start_date_23 = start_date_00.replace(hour=23, minute=59, second=59, microsecond=0)
|
start_date_23 = start_date_00.replace(hour=23, minute=59, second=59, microsecond=0)
|
||||||
start_date_str = start_date_00.strftime("01.%m")
|
start_date_str = start_date_00.strftime("01.%m")
|
||||||
last_date_str = start_date_00.strftime(f"{calendar.monthrange(int(year),int(month))[1]}.%m")
|
last_date_str = start_date_00.strftime(f"{calendar.monthrange(int(year),int(month))[1]}.%m")
|
||||||
|
print(date)
|
||||||
|
main_path = fr"/docker/app_data/data/karstenstoecker/files/Stines GmbH/1. Verwaltung/4. Verträge/2. Zulieferer - Dienstleister/MS - SPLA/Insight/Reports/{year}"
|
||||||
mydb = mysql.connector.connect(
|
mydb = mysql.connector.connect(
|
||||||
host="172.17.1.21",
|
host="172.17.1.21",
|
||||||
port="3306",
|
port="3306",
|
||||||
user="root",
|
user="root",
|
||||||
password="N53yBCswuawzBzS445VNAhWVMs3N59Gb9szEsrzXRBzarDqpdETpQeyt5v5CGe",
|
password="N53yBCswuawzBzS445VNAhWVMs3N59Gb9szEsrzXRBzarDqpdETpQeyt5v5CGe",
|
||||||
database="Stines-GmbH",
|
database="Kunden",
|
||||||
auth_plugin='mysql_native_password',
|
auth_plugin='mysql_native_password',
|
||||||
)
|
)
|
||||||
mydb.connect()
|
mydb.connect()
|
||||||
cursor = mydb.cursor()
|
cursor = mydb.cursor()
|
||||||
|
cursor.execute(f"""SELECT ANY_VALUE(c.companyname) AS companyname,
|
||||||
cursor.execute("SELECT Datenbank FROM Kunden GROUP by Datenbank")
|
ANY_VALUE(c.customer_ID) AS customer_ID,
|
||||||
|
ANY_VALUE(cs.services_ID)
|
||||||
|
FROM Kunden.company c
|
||||||
|
INNER JOIN Kunden.`customers.services` cs ON cs.customer_ID = c.customer_ID
|
||||||
|
WHERE cs.`services_ID` IN (100, 101)
|
||||||
|
GROUP BY c.customer_ID;
|
||||||
|
""")
|
||||||
kunden = cursor.fetchall()
|
kunden = cursor.fetchall()
|
||||||
|
|
||||||
main_path = fr"/docker/app_data/data/karstenstoecker/files/Stines GmbH/1. Verwaltung/4. Verträge/2. Zulieferer - Dienstleister/MS - SPLA/Insight/Reports/{year}"
|
|
||||||
for i in kunden:
|
for i in kunden:
|
||||||
kunde = i[0].replace("-"," ").replace("ae","ä")
|
kunde = i[0]
|
||||||
|
komplett_pfad = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
|
if os.path.exists(komplett_pfad):
|
||||||
|
os.remove(komplett_pfad)
|
||||||
|
print(f"Removed file: {komplett_pfad}")
|
||||||
|
else:
|
||||||
|
print(f"File not found: {komplett_pfad}")
|
||||||
if os.path.exists(fr"{main_path}/{i}/{start_date_str} - {last_date_str}/RAW"):
|
if os.path.exists(fr"{main_path}/{i}/{start_date_str} - {last_date_str}/RAW"):
|
||||||
next
|
next
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
os.mkdir(fr"{main_path}")
|
||||||
|
except:
|
||||||
|
next
|
||||||
try:
|
try:
|
||||||
os.mkdir(fr"{main_path}/{kunde}")
|
os.mkdir(fr"{main_path}/{kunde}")
|
||||||
except:
|
except:
|
||||||
|
|
@ -51,43 +67,50 @@ for i in kunden:
|
||||||
os.mkdir(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW")
|
os.mkdir(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW")
|
||||||
except:
|
except:
|
||||||
next
|
next
|
||||||
# RAW EXPORT
|
|
||||||
## AD - User Export START ##
|
## AD - User Export START ##
|
||||||
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Active-Directory-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Active-Directory-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
csv_writer = csv.writer(csvfile,delimiter=";")
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
cursor.execute(f'SELECT * FROM `{i[0]}`.`Active-Directory-User` where importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()}')
|
cursor.execute(f"""SELECT DISTINCT u.username, us.status, us.timestamp as Last_Status
|
||||||
|
FROM Kunden.`users.status` us
|
||||||
|
JOIN Kunden.users u ON u.user_ID = us.user_id
|
||||||
|
JOIN Kunden.`users.services` uss ON us.user_id = uss.user_id
|
||||||
|
JOIN Kunden.services s ON uss.service_ID = s.service_ID
|
||||||
|
JOIN Kunden.company c ON c.customer_ID = us.customer_ID
|
||||||
|
WHERE c.customer_ID = {i[1]}
|
||||||
|
""")
|
||||||
csv_writer.writerow([i[0] for i in cursor.description])
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
csv_writer.writerows(cursor.fetchall())
|
csv_writer.writerows(cursor.fetchall())
|
||||||
## AD - User Export ENDE ##
|
# ## AD - User Export ENDE ##
|
||||||
## SERVER - Export START ##
|
# ## SERVER - Export START ##
|
||||||
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
csv_writer = csv.writer(csvfile,delimiter=";")
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
# print(f"SELECT Kundennummer,Name,`Server-Name`,`IP-Adresse`,CreateDate,`Windows-Key`,CPU,RAM,Speicher,Prozessor FROM `Stines-GmbH`.`Kunden-Server` where Name='{i[0]}' AND `Windows-Key` IS NOT NULL")
|
#print(f"SELECT * FROM Kunden.server s WHERE s.customer_ID = 2 AND `Windows-Key` IS NOT NULL")
|
||||||
cursor.execute(f"SELECT Kundennummer,Name,`Server-Name`,`IP-Adresse`,CreateDate,`Windows-Key`,CPU,RAM,Speicher,Prozessor FROM `Stines-GmbH`.`Kunden-Server` where Name='{i[0]}' AND `Windows-Key` IS NOT NULL")
|
cursor.execute(f"""SELECT s.hostname,s.privat_ipaddress,s.public_ipaddress, s.macaddress, s.ram ,hc.name as CPUName, hc.typ as Servertyp, hc.ghz as GhZ, hc.core as Kerne, s.os as OS, ss.name as ServiceName, s.licensekey as Lizenzschlüssel, s.status as Serverstatus FROM Kunden.server s
|
||||||
|
JOIN Kunden.`hardware.cpu` hc ON hc.cpu_ID = s.CPU_ID
|
||||||
|
Join Kunden.services ss ON s.service_ID = ss.service_ID WHERE s.customer_ID = {i[1]} and `licensekey` IS NOT NULL""")
|
||||||
csv_writer.writerow([i[0] for i in cursor.description])
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
csv_writer.writerows(cursor.fetchall())
|
csv_writer.writerows(cursor.fetchall())
|
||||||
## SERVER - Export ENDE ##
|
# ## SERVER - Export ENDE ##
|
||||||
## RDS - User Export START ##
|
# ## RDS - User Export START ##
|
||||||
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
csv_writer = csv.writer(csvfile,delimiter=";")
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
try:
|
cursor.execute(f"select username as Username, reportingdate, lastaccess from Kunden.`services.reporting` sr where sr.customer_ID = {i[1]} and sr.service_ID = 101 and sr.reportingdate LIKE '%{date.strftime('%Y-%m-%d')}%';")
|
||||||
cursor.execute(f"SELECT id FROM `{i[0]}`.`Exchange-User` LIMIT 1")
|
#cursor.execute(f"select username as Username, reportingdate, lastaccess from Kunden.`services.reporting` sr where sr.customer_ID = {i[1]} and sr.service_ID = 101 and DATE(sr.reportingdate) = CURDATE();")
|
||||||
except:
|
|
||||||
next
|
|
||||||
table_exists = cursor.fetchone() is not None
|
|
||||||
if table_exists:
|
|
||||||
cursor.execute(f'SELECT db1.importdate as "time",db1.CreateTimeStamp,db1.SamAccountName,db1.DisplayName, db1.EmailAddress, db1.extensionAttribute1 AS "RDS Deaktviert am", db1.extensionAttribute2 AS "Exchange Deaktviert am", db1.Description,db1.Deleted,db1.LastLogonDate,db1.City FROM `{i[0]}`.`Active-Directory-User` db1 INNER JOIN `{i[0]}`.`Active-Directory-RDS-User` db2 ON db1.SamAccountName = db2.SamAccountName WHERE db1.importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND db2.SamAccountName NOT LIKE "%test%" AND db2.SamAccountName NOT LIKE "%admin%"')
|
|
||||||
else:
|
|
||||||
cursor.execute(f'SELECT db1.importdate as "time",db1.CreateTimeStamp,db1.SamAccountName,db1.DisplayName, db1.EmailAddress, db1.extensionAttribute1 AS "RDS Deaktviert am", db1.Description,db1.Deleted,db1.LastLogonDate,db1.City FROM `{i[0]}`.`Active-Directory-User` db1 INNER JOIN `{i[0]}`.`Active-Directory-RDS-User` db2 ON db1.SamAccountName = db2.SamAccountName WHERE db1.importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND db2.SamAccountName NOT LIKE "%test%" AND db2.SamAccountName NOT LIKE "%admin%"')
|
|
||||||
csv_writer.writerow([i[0] for i in cursor.description])
|
|
||||||
csv_writer.writerows(cursor.fetchall())
|
|
||||||
if table_exists:
|
|
||||||
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
|
||||||
csv_writer = csv.writer(csvfile,delimiter=";")
|
|
||||||
cursor.execute(f'SELECT importdate as "time",SamAccountName,WindowsEmailAddress,CustomAttribute2 as "Description",WhenCreated FROM `{i[0]}`.`Exchange-User` WHERE RecipientTypeDetails = "UserMailbox" AND importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND SamAccountName NOT LIKE "%test%" AND SamAccountName NOT LIKE "%admin%" AND SamAccountName NOT LIKE "%journal%" ')
|
|
||||||
csv_writer.writerow([i[0] for i in cursor.description])
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
csv_writer.writerows(cursor.fetchall())
|
csv_writer.writerows(cursor.fetchall())
|
||||||
## RDS - User Export ENDE ##
|
## RDS - User Export ENDE ##
|
||||||
|
## EX - User Export Start ##
|
||||||
|
if i[2] == 100:
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/EX-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
cursor.execute(f"""select u.username as Username, u.primarymail as EMailAdresse,sr.reportingdate as ReportDate, sr.lastaccess as LastAccess from Kunden.`services.reporting` sr
|
||||||
|
JOIN Kunden.users u ON u.username = sr.username
|
||||||
|
where sr.customer_ID = {i[1]} and sr.service_ID = 100 and sr.reportingdate LIKE '%{date.strftime('%Y-%m-%d')}%';""")
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
else:
|
||||||
|
next
|
||||||
|
## EX - User Export ENDE ##
|
||||||
## RAW EXPORT ENDE ##
|
## RAW EXPORT ENDE ##
|
||||||
## CREATE Excel Sheet from csv Export ##
|
## CREATE Excel Sheet from csv Export ##
|
||||||
## EXPORT to AD- User Excel-Sheet ##
|
## EXPORT to AD- User Excel-Sheet ##
|
||||||
|
|
@ -95,7 +118,7 @@ for i in kunden:
|
||||||
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
# Leere Felder mit "-" füllen
|
# Leere Felder mit "-" füllen
|
||||||
df = df.fillna("-")
|
df = df.fillna("-")
|
||||||
df["time"] = pd.to_datetime(df["time"], unit='s')
|
#df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
# Excel-Datei erstellen und Daten schreiben
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_User_Export Stand({last_date_str}).xlsx"
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_User_Export Stand({last_date_str}).xlsx"
|
||||||
if os.path.exists(excel_datei):
|
if os.path.exists(excel_datei):
|
||||||
|
|
@ -148,86 +171,11 @@ for i in kunden:
|
||||||
pass
|
pass
|
||||||
adjusted_width = (max_length + 2) * 1.2
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
worksheet.column_dimensions[column_letter].width = adjusted_width
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
if table_exists:
|
|
||||||
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
|
||||||
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
|
||||||
# Leere Felder mit "-" füllen
|
|
||||||
df = df.fillna("-")
|
|
||||||
df["time"] = pd.to_datetime(df["time"], unit='s')
|
|
||||||
# Excel-Datei erstellen und Daten schreiben
|
|
||||||
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Mailbox_Export Stand({last_date_str}).xlsx"
|
|
||||||
if os.path.exists(excel_datei):
|
|
||||||
mode = 'a'
|
|
||||||
else:
|
|
||||||
mode = 'w'
|
|
||||||
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
|
||||||
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
|
||||||
workbook = writer.book
|
|
||||||
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
|
||||||
worksheet.auto_filter.ref = "A1:E1"
|
|
||||||
# Spaltenbreite festlegen
|
|
||||||
for column in worksheet.columns:
|
|
||||||
max_length = 0
|
|
||||||
column_letter = column[0].column_letter
|
|
||||||
for cell in column:
|
|
||||||
try:
|
|
||||||
if len(str(cell.value)) > max_length:
|
|
||||||
max_length = len(cell.value)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
adjusted_width = (max_length + 2) * 1.2
|
|
||||||
worksheet.column_dimensions[column_letter].width = adjusted_width
|
|
||||||
|
|
||||||
## CREATE Worksheet first Page
|
|
||||||
try:
|
|
||||||
os.remove(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx")
|
|
||||||
except:
|
|
||||||
next
|
|
||||||
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
|
||||||
|
|
||||||
workbook = openpyxl.Workbook()
|
|
||||||
worksheet = workbook.active
|
|
||||||
worksheet.title = "Übersicht"
|
|
||||||
font = Font(size=20)
|
|
||||||
|
|
||||||
font_small = Font(size=16)
|
|
||||||
|
|
||||||
|
|
||||||
worksheet.merge_cells('C5:G6')
|
|
||||||
worksheet.merge_cells('C7:G7')
|
|
||||||
worksheet.merge_cells('C8:E8')
|
|
||||||
worksheet.merge_cells('C10:E10')
|
|
||||||
worksheet.merge_cells('C12:E12')
|
|
||||||
worksheet.merge_cells('C14:E14')
|
|
||||||
|
|
||||||
worksheet['C5'] = "Übersicht"
|
|
||||||
worksheet['C5'].font = font
|
|
||||||
|
|
||||||
worksheet['C7'] = f"{start_date_str} - {last_date_str}"
|
|
||||||
worksheet['C7'].font = font_small
|
|
||||||
|
|
||||||
worksheet['C10'] = "RDS-User"
|
|
||||||
worksheet['C10'].font = font_small
|
|
||||||
worksheet['G10'] = "=COUNTIF('RDS - User'!G2:G50;\"-\")"
|
|
||||||
|
|
||||||
if table_exists:
|
|
||||||
worksheet['C12'] = "Exchange-User"
|
|
||||||
worksheet['C12'].font = font_small
|
|
||||||
worksheet['G12'] = "=COUNTIF('Exchange - User'!D2:D50;\"<>\"&\"*Exchange - Deaktiviert*\")+1"
|
|
||||||
else:
|
|
||||||
next
|
|
||||||
|
|
||||||
worksheet['C14'] = "Server-Cores"
|
|
||||||
worksheet['C14'].font = font_small
|
|
||||||
worksheet['G14'] = "=COUNTIF('Server'!J2:J50)*8/2"
|
|
||||||
|
|
||||||
workbook.save(excel_datei)
|
|
||||||
|
|
||||||
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
# Leere Felder mit "-" füllen
|
# Leere Felder mit "-" füllen
|
||||||
df = df.fillna("-")
|
df = df.fillna("-")
|
||||||
df["time"] = pd.to_datetime(df["time"], unit='s')
|
#df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
# Excel-Datei erstellen und Daten schreiben
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
if os.path.exists(excel_datei):
|
if os.path.exists(excel_datei):
|
||||||
|
|
@ -251,13 +199,41 @@ for i in kunden:
|
||||||
pass
|
pass
|
||||||
adjusted_width = (max_length + 2) * 1.2
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
worksheet.column_dimensions[column_letter].width = adjusted_width
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
if i[2] == 100:
|
||||||
if table_exists:
|
## Export Mailbox if Service 100 exist on Customer ##
|
||||||
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/EX-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
# Leere Felder mit "-" füllen
|
# Leere Felder mit "-" füllen
|
||||||
df = df.fillna("-")
|
df = df.fillna("-")
|
||||||
df["time"] = pd.to_datetime(df["time"], unit='s')
|
#df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Mailbox_Export Stand({last_date_str}).xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
||||||
|
worksheet.auto_filter.ref = "A1:E1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/EX-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
#df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
# Excel-Datei erstellen und Daten schreiben
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
if os.path.exists(excel_datei):
|
if os.path.exists(excel_datei):
|
||||||
|
|
@ -281,6 +257,9 @@ for i in kunden:
|
||||||
pass
|
pass
|
||||||
adjusted_width = (max_length + 2) * 1.2
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
worksheet.column_dimensions[column_letter].width = adjusted_width
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
else:
|
||||||
|
next
|
||||||
|
## Export Server ##
|
||||||
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
# Leere Felder mit "-" füllen
|
# Leere Felder mit "-" füllen
|
||||||
|
|
@ -349,14 +328,12 @@ cursor.close()
|
||||||
mydb.close()
|
mydb.close()
|
||||||
os.system(f'chmod 777 -R "/docker/app_data/data/karstenstoecker/files/Stines GmbH/1. Verwaltung/4. Verträge/2. Zulieferer - Dienstleister/MS - SPLA/Insight/Reports/{year}"')
|
os.system(f'chmod 777 -R "/docker/app_data/data/karstenstoecker/files/Stines GmbH/1. Verwaltung/4. Verträge/2. Zulieferer - Dienstleister/MS - SPLA/Insight/Reports/{year}"')
|
||||||
os.system(f"/bin/bash -c 'docker exec -u www-data app-server /bin/bash -c 'php occ files:scan --path=karstenstoecker/files/Stines\ GmbH/1.\ Verwaltung/4.\ Verträge/2.\ Zulieferer\ -\ Dienstleister/MS\ -\ SPLA/Insight/Reports/''")
|
os.system(f"/bin/bash -c 'docker exec -u www-data app-server /bin/bash -c 'php occ files:scan --path=karstenstoecker/files/Stines\ GmbH/1.\ Verwaltung/4.\ Verträge/2.\ Zulieferer\ -\ Dienstleister/MS\ -\ SPLA/Insight/Reports/''")
|
||||||
|
# SEND Pushover ##
|
||||||
## SEND Pushover ##
|
|
||||||
conn = http.client.HTTPSConnection("api.pushover.net:443")
|
conn = http.client.HTTPSConnection("api.pushover.net:443")
|
||||||
conn.request("POST", "/1/messages.json",
|
conn.request("POST", "/1/messages.json",
|
||||||
urllib.parse.urlencode({
|
urllib.parse.urlencode({
|
||||||
"token": "avzcexyjeu7y71pcskwshyx8ytmq8i",
|
"token": "avzcexyjeu7y71pcskwshyx8ytmq8i",
|
||||||
"user": "uo2sf2pmrtjvt8auu786fviabimimr",
|
"user": "uo2sf2pmrtjvt8auu786fviabimimr",
|
||||||
"message": "Reporting was running!",
|
"message": "SPLA Reporting was running!",
|
||||||
}), { "Content-type": "application/x-www-form-urlencoded" })
|
}), { "Content-type": "application/x-www-form-urlencoded" })
|
||||||
conn.getresponse()
|
conn.getresponse()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,362 @@
|
||||||
|
import csv
|
||||||
|
import os
|
||||||
|
import mysql.connector
|
||||||
|
import pandas as pd
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
import openpyxl
|
||||||
|
import calendar
|
||||||
|
import http.client, urllib
|
||||||
|
# from reportlab.lib.pagesizes import letter
|
||||||
|
# from reportlab.pdfgen import canvas
|
||||||
|
from openpyxl.styles import Alignment, Font
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
date = datetime.now() - timedelta(1)
|
||||||
|
month = datetime.now().strftime("%m")
|
||||||
|
year = datetime.now().strftime("%Y")
|
||||||
|
start_date_00 = date.replace(hour=0, minute=0, second=0, microsecond=0)
|
||||||
|
start_date_23 = start_date_00.replace(hour=23, minute=59, second=59, microsecond=0)
|
||||||
|
start_date_str = start_date_00.strftime("01.%m")
|
||||||
|
last_date_str = start_date_00.strftime(f"{calendar.monthrange(int(year),int(month))[1]}.%m")
|
||||||
|
|
||||||
|
mydb = mysql.connector.connect(
|
||||||
|
host="172.17.1.21",
|
||||||
|
port="3306",
|
||||||
|
user="root",
|
||||||
|
password="N53yBCswuawzBzS445VNAhWVMs3N59Gb9szEsrzXRBzarDqpdETpQeyt5v5CGe",
|
||||||
|
database="Stines-GmbH",
|
||||||
|
auth_plugin='mysql_native_password',
|
||||||
|
)
|
||||||
|
mydb.connect()
|
||||||
|
cursor = mydb.cursor()
|
||||||
|
|
||||||
|
cursor.execute("SELECT Datenbank FROM Kunden GROUP by Datenbank")
|
||||||
|
kunden = cursor.fetchall()
|
||||||
|
|
||||||
|
main_path = fr"/docker/app_data/data/karstenstoecker/files/Stines GmbH/1. Verwaltung/4. Verträge/2. Zulieferer - Dienstleister/MS - SPLA/Insight/Reports/{year}"
|
||||||
|
for i in kunden:
|
||||||
|
kunde = i[0].replace("-"," ").replace("ae","ä")
|
||||||
|
if os.path.exists(fr"{main_path}/{i}/{start_date_str} - {last_date_str}/RAW"):
|
||||||
|
next
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
os.mkdir(fr"{main_path}/{kunde}")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
try:
|
||||||
|
os.mkdir(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
try:
|
||||||
|
os.mkdir(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
# RAW EXPORT
|
||||||
|
## AD - User Export START ##
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Active-Directory-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
cursor.execute(f'SELECT * FROM `{i[0]}`.`Active-Directory-User` where importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()}')
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
## AD - User Export ENDE ##
|
||||||
|
## SERVER - Export START ##
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
# print(f"SELECT Kundennummer,Name,`Server-Name`,`IP-Adresse`,CreateDate,`Windows-Key`,CPU,RAM,Speicher,Prozessor FROM `Stines-GmbH`.`Kunden-Server` where Name='{i[0]}' AND `Windows-Key` IS NOT NULL")
|
||||||
|
cursor.execute(f"SELECT Kundennummer,Name,`Server-Name`,`IP-Adresse`,CreateDate,`Windows-Key`,CPU,RAM,Speicher,Prozessor FROM `Stines-GmbH`.`Kunden-Server` where Name='{i[0]}' AND `Windows-Key` IS NOT NULL")
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
## SERVER - Export ENDE ##
|
||||||
|
## RDS - User Export START ##
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
try:
|
||||||
|
cursor.execute(f"SELECT id FROM `{i[0]}`.`Exchange-User` LIMIT 1")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
table_exists = cursor.fetchone() is not None
|
||||||
|
if table_exists:
|
||||||
|
cursor.execute(f'SELECT db1.importdate as "time",db1.CreateTimeStamp,db1.SamAccountName,db1.DisplayName, db1.EmailAddress, db1.extensionAttribute1 AS "RDS Deaktviert am", db1.extensionAttribute2 AS "Exchange Deaktviert am", db1.Description,db1.Deleted,db1.LastLogonDate,db1.City FROM `{i[0]}`.`Active-Directory-User` db1 INNER JOIN `{i[0]}`.`Active-Directory-RDS-User` db2 ON db1.SamAccountName = db2.SamAccountName WHERE db1.importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND db2.SamAccountName NOT LIKE "%test%" AND db2.SamAccountName NOT LIKE "%admin%"')
|
||||||
|
else:
|
||||||
|
cursor.execute(f'SELECT db1.importdate as "time",db1.CreateTimeStamp,db1.SamAccountName,db1.DisplayName, db1.EmailAddress, db1.extensionAttribute1 AS "RDS Deaktviert am", db1.Description,db1.Deleted,db1.LastLogonDate,db1.City FROM `{i[0]}`.`Active-Directory-User` db1 INNER JOIN `{i[0]}`.`Active-Directory-RDS-User` db2 ON db1.SamAccountName = db2.SamAccountName WHERE db1.importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND db2.SamAccountName NOT LIKE "%test%" AND db2.SamAccountName NOT LIKE "%admin%"')
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
if table_exists:
|
||||||
|
with open(fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv', 'w', newline='', encoding='utf-8') as csvfile:
|
||||||
|
csv_writer = csv.writer(csvfile,delimiter=";")
|
||||||
|
cursor.execute(f'SELECT importdate as "time",SamAccountName,WindowsEmailAddress,CustomAttribute2 as "Description",WhenCreated FROM `{i[0]}`.`Exchange-User` WHERE RecipientTypeDetails = "UserMailbox" AND importdate BETWEEN {start_date_00.timestamp()} and {start_date_23.timestamp()} AND SamAccountName NOT LIKE "%test%" AND SamAccountName NOT LIKE "%admin%" AND SamAccountName NOT LIKE "%journal%" ')
|
||||||
|
csv_writer.writerow([i[0] for i in cursor.description])
|
||||||
|
csv_writer.writerows(cursor.fetchall())
|
||||||
|
## RDS - User Export ENDE ##
|
||||||
|
## RAW EXPORT ENDE ##
|
||||||
|
## CREATE Excel Sheet from csv Export ##
|
||||||
|
## EXPORT to AD- User Excel-Sheet ##
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_User_Export Stand({last_date_str}).xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
||||||
|
worksheet.auto_filter.ref = "A1:J1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
## EXPORT to AD- User Excel-Sheet ##
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
# df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Server_Export Stand({last_date_str}).xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
||||||
|
worksheet.auto_filter.ref = "A1:J1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
if table_exists:
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Mailbox_Export Stand({last_date_str}).xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'{start_date_00.strftime("%d-%m")}')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'{start_date_00.strftime("%d-%m")}']
|
||||||
|
worksheet.auto_filter.ref = "A1:E1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
|
||||||
|
## CREATE Worksheet first Page
|
||||||
|
try:
|
||||||
|
os.remove(fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx")
|
||||||
|
except:
|
||||||
|
next
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
|
|
||||||
|
workbook = openpyxl.Workbook()
|
||||||
|
worksheet = workbook.active
|
||||||
|
worksheet.title = "Übersicht"
|
||||||
|
font = Font(size=20)
|
||||||
|
|
||||||
|
font_small = Font(size=16)
|
||||||
|
|
||||||
|
|
||||||
|
worksheet.merge_cells('C5:G6')
|
||||||
|
worksheet.merge_cells('C7:G7')
|
||||||
|
worksheet.merge_cells('C8:E8')
|
||||||
|
worksheet.merge_cells('C10:E10')
|
||||||
|
worksheet.merge_cells('C12:E12')
|
||||||
|
worksheet.merge_cells('C14:E14')
|
||||||
|
|
||||||
|
worksheet['C5'] = "Übersicht"
|
||||||
|
worksheet['C5'].font = font
|
||||||
|
|
||||||
|
worksheet['C7'] = f"{start_date_str} - {last_date_str}"
|
||||||
|
worksheet['C7'].font = font_small
|
||||||
|
|
||||||
|
worksheet['C10'] = "RDS-User"
|
||||||
|
worksheet['C10'].font = font_small
|
||||||
|
worksheet['G10'] = "=COUNTIF('RDS - User'!G2:G50;\"-\")"
|
||||||
|
|
||||||
|
if table_exists:
|
||||||
|
worksheet['C12'] = "Exchange-User"
|
||||||
|
worksheet['C12'].font = font_small
|
||||||
|
worksheet['G12'] = "=COUNTIF('Exchange - User'!D2:D50;\"<>\"&\"*Exchange - Deaktiviert*\")+1"
|
||||||
|
else:
|
||||||
|
next
|
||||||
|
|
||||||
|
worksheet['C14'] = "Server-Cores"
|
||||||
|
worksheet['C14'].font = font_small
|
||||||
|
worksheet['G14'] = "=COUNTIF('Server'!J2:J50)*8/2"
|
||||||
|
|
||||||
|
workbook.save(excel_datei)
|
||||||
|
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/RDS-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'RDS - User')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'RDS - User']
|
||||||
|
worksheet.auto_filter.ref = "A1:J1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
|
||||||
|
if table_exists:
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/Exchange-User - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'Exchange - User')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'Exchange - User']
|
||||||
|
worksheet.auto_filter.ref = "A1:E1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
csv_datei = fr'{main_path}/{kunde}/{start_date_str} - {last_date_str}/RAW/SERVER - {kunde} - {start_date_00.strftime("%Y-%m-%d")}.csv'
|
||||||
|
df = pd.read_csv(csv_datei, sep=";", encoding="utf-8")
|
||||||
|
# Leere Felder mit "-" füllen
|
||||||
|
df = df.fillna("-")
|
||||||
|
# df["time"] = pd.to_datetime(df["time"], unit='s')
|
||||||
|
# Excel-Datei erstellen und Daten schreiben
|
||||||
|
excel_datei = fr"{main_path}/{kunde}/{start_date_str} - {last_date_str}/{kunde}_Komplett.xlsx"
|
||||||
|
if os.path.exists(excel_datei):
|
||||||
|
mode = 'a'
|
||||||
|
else:
|
||||||
|
mode = 'w'
|
||||||
|
with pd.ExcelWriter(excel_datei, engine='openpyxl', mode=f'{mode}') as writer:
|
||||||
|
df.to_excel(writer, index=False, sheet_name=f'Server')
|
||||||
|
workbook = writer.book
|
||||||
|
worksheet = writer.sheets[f'Server']
|
||||||
|
worksheet.auto_filter.ref = "A1:J1"
|
||||||
|
# Spaltenbreite festlegen
|
||||||
|
for column in worksheet.columns:
|
||||||
|
max_length = 0
|
||||||
|
column_letter = column[0].column_letter
|
||||||
|
for cell in column:
|
||||||
|
try:
|
||||||
|
if len(str(cell.value)) > max_length:
|
||||||
|
max_length = len(cell.value)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
adjusted_width = (max_length + 2) * 1.2
|
||||||
|
worksheet.column_dimensions[column_letter].width = adjusted_width
|
||||||
|
# # os.mkdir("")
|
||||||
|
# #
|
||||||
|
# # print(table_exists)
|
||||||
|
# #
|
||||||
|
# # c = canvas.Canvas(fr"{i}/{start_date_str} - {last_date_str}/PDF_Export Stand({last_date_str}).pdf", pagesize=letter)
|
||||||
|
# # # Hier können Sie IhrenCode zum Hinzufügen von Daten zur PDF einfügen
|
||||||
|
# # c.setFont("Helvetica", 10)
|
||||||
|
# # c.drawString(50, 750, f"Create Date - {datetime.now().strftime("%d-%M-%Y")}")
|
||||||
|
# # c.drawImage("Firmen-Logo.png", x=450, y=730, width=150, height=40)
|
||||||
|
# # c.setFont("Helvetica", 12)
|
||||||
|
# # c.drawString(100, 680, "REPORT der RDP / Exchange User der Firma bla")
|
||||||
|
# #
|
||||||
|
# # k = 10
|
||||||
|
# # n = 650
|
||||||
|
# # x = 100
|
||||||
|
# # t = 0
|
||||||
|
# # if n < 50:
|
||||||
|
# # if t == 1:
|
||||||
|
# # x = 400
|
||||||
|
# # n = 650
|
||||||
|
# # print(x)
|
||||||
|
# # print("insede")
|
||||||
|
# # else:
|
||||||
|
# # x = 250
|
||||||
|
# # n = 650
|
||||||
|
# # t += 1
|
||||||
|
# # c.setFont("Helvetica", 8)
|
||||||
|
# # c.drawString(x, n, f"Zeitraum: {i}")
|
||||||
|
# # c.drawString(x, n - 10, f"Aktive RDS-User: {i}")
|
||||||
|
# # c.drawString(x, n - 20, f"Deaktivierte RDS-User: {i}")
|
||||||
|
# # if table_exists:
|
||||||
|
# # c.drawString(x, n - 30, f"Aktive EX-User: {i}")
|
||||||
|
# # c.drawString(x, n - 40, f"Deaktivierte EX-User: {i}")
|
||||||
|
# # n = n - 60
|
||||||
|
# # c.save()
|
||||||
|
# # subprocess.Popen(["start", "output.pdf"], shell=True)
|
||||||
|
cursor.close()
|
||||||
|
mydb.close()
|
||||||
|
os.system(f'chmod 777 -R "/docker/app_data/data/karstenstoecker/files/Stines GmbH/1. Verwaltung/4. Verträge/2. Zulieferer - Dienstleister/MS - SPLA/Insight/Reports/{year}"')
|
||||||
|
os.system(f"/bin/bash -c 'docker exec -u www-data app-server /bin/bash -c 'php occ files:scan --path=karstenstoecker/files/Stines\ GmbH/1.\ Verwaltung/4.\ Verträge/2.\ Zulieferer\ -\ Dienstleister/MS\ -\ SPLA/Insight/Reports/''")
|
||||||
|
|
||||||
|
## SEND Pushover ##
|
||||||
|
conn = http.client.HTTPSConnection("api.pushover.net:443")
|
||||||
|
conn.request("POST", "/1/messages.json",
|
||||||
|
urllib.parse.urlencode({
|
||||||
|
"token": "avzcexyjeu7y71pcskwshyx8ytmq8i",
|
||||||
|
"user": "uo2sf2pmrtjvt8auu786fviabimimr",
|
||||||
|
"message": "Reporting was running!",
|
||||||
|
}), { "Content-type": "application/x-www-form-urlencoded" })
|
||||||
|
conn.getresponse()
|
||||||
|
|
||||||
Loading…
Reference in New Issue