Dateien nach "/" hochladen
Python Software, um URLs in Listen einzupflegen. Es überprüft, ob ein Eintrag bereits existiert. Falls es nicht existiert, wird es hinzugefügt.
This commit is contained in:
62
add.py
Normal file
62
add.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import os
|
||||
import tkinter as tk
|
||||
from tkinter import filedialog
|
||||
|
||||
def main():
|
||||
# Erstelle das Hauptfenster und verstecke es
|
||||
root = tk.Tk()
|
||||
root.withdraw()
|
||||
|
||||
# Datei 1 auswählen
|
||||
print("Bitte wählen Sie die erste Datei (file1) aus:")
|
||||
file1_path = filedialog.askopenfilename(title="Wählen Sie file1 aus")
|
||||
|
||||
# Datei 2 auswählen
|
||||
print("Bitte wählen Sie die zweite Datei (file2) aus:")
|
||||
file2_path = filedialog.askopenfilename(title="Wählen Sie file2 aus")
|
||||
|
||||
if not file1_path or not file2_path:
|
||||
print("Dateien wurden nicht ausgewählt. Das Programm wird beendet.")
|
||||
return
|
||||
|
||||
# Lesen von file1
|
||||
with open(file1_path, 'r', encoding='utf-8') as f:
|
||||
file1_lines = f.readlines()
|
||||
|
||||
# Extrahieren der URLs aus file1 (Entfernen von '0.0.0.0 ')
|
||||
file1_urls = set()
|
||||
for line in file1_lines:
|
||||
line = line.strip()
|
||||
if line.startswith('0.0.0.0 '):
|
||||
url = line[len('0.0.0.0 '):].strip()
|
||||
file1_urls.add(url)
|
||||
else:
|
||||
file1_urls.add(line)
|
||||
|
||||
# Lesen der URLs aus file2
|
||||
with open(file2_path, 'r', encoding='utf-8') as f:
|
||||
file2_urls = set(line.strip() for line in f if line.strip())
|
||||
|
||||
# Neue URLs hinzufügen, die nicht in file1 sind
|
||||
new_lines = []
|
||||
for url in file2_urls:
|
||||
if url not in file1_urls:
|
||||
new_line = '0.0.0.0 ' + url + '\n'
|
||||
new_lines.append(new_line)
|
||||
|
||||
# Kombinieren der originalen und neuen Zeilen
|
||||
combined_lines = file1_lines + new_lines
|
||||
|
||||
# Speichern der Änderungen in einer neuen Datei
|
||||
file1_dir = os.path.dirname(file1_path)
|
||||
file1_name = os.path.basename(file1_path)
|
||||
new_file_name = os.path.splitext(file1_name)[0] + '_neu' + os.path.splitext(file1_name)[1]
|
||||
new_file_path = os.path.join(file1_dir, new_file_name)
|
||||
|
||||
with open(new_file_path, 'w', encoding='utf-8') as f:
|
||||
f.writelines(combined_lines)
|
||||
|
||||
print(f"Die Änderungen wurden erfolgreich in der Datei '{new_file_name}' gespeichert.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user