Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import gzip
- from glob import glob
- from ftplib import FTP_TLS
- from zipfile import ZipFile
- import xml.etree.ElementTree as ElementTree
- import html
- import pandas as pd
- import numpy as np
- from slugify import slugify
- # Konfiguration
- ftp_host = "ip"
- ftp_user = "user"
- ftp_password = "pass"
- filepath_root_remote = "/public_html/export"
- filepath_root_local = "P:/Pfad/Onlineshop/Sitemap"
- file_list_name = "P:/Pfad/Onlineshop/Sitemap/Python-Dateiimport.csv"
- # Verbindung mit FTP-Server aufbauen
- ftp = FTP_TLS(ftp_host)
- ftp.auth()
- ftp.login(user=ftp_user, passwd=ftp_password)
- ftp.prot_p()
- # Liste der herunterzuladenen Dateien durchlaufen
- file_list = pd.read_csv(file_list_name, sep=";")
- for i, row in file_list.iterrows():
- filename_zip = "%s_xml.zip" % row["Modellid"]
- filename_xml_src = "%s.xml" % row["Modellid"]
- filename_xml_dest = "%s_%s.xml" % (row["Herstellerid"], row["Modellid"])
- filepath_remote = filepath_root_remote + "/%s/XML/%s" % (row["Herstellerid"], filename_zip)
- filepath_local = "%s/%s_%s" % (filepath_root_local, row["Herstellerid"], filename_zip)
- # Zip Datei herunterladen
- with open(filepath_local, "wb") as file_local:
- ftp.retrbinary("RETR %s" % filepath_remote, file_local.write)
- # XML Datei entpacken
- zip_ref = ZipFile(filepath_local, "r")
- zip_ref.extract(filename_xml_src, path=filepath_root_local)
- zip_ref.close()
- # XML Datei umbenennen
- os.rename(os.path.join(filepath_root_local, filename_xml_src),
- os.path.join(filepath_root_local, filename_xml_dest))
- # Zip Datei löschen
- os.remove(filepath_local)
- # FTP Verbindung schliessen
- ftp.quit()
Add Comment
Please, Sign In to add comment