-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlectorarchivos.py
More file actions
85 lines (74 loc) · 2.55 KB
/
Copy pathlectorarchivos.py
File metadata and controls
85 lines (74 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from datetime import *
import csv
from importlib.resources import path
import os
import time
from tkinter import END
#Inicializando Variables
initial_count = 0
completados = 0
contenido = []
auxreader = []
ingreso = []
#mtzConsolidado1 = ["Host","Begin_date","End_date","Duration","Down","UP","UNREACHABLE","SCHEDULED DOWNTIME","UNDETERMINED"]
#Folder Path
path = r"C:\Users\OSP2021\Desktop\prueba"
#Change the directory
os.chdir(path)
#Realiza el conteo de cuantos archivos del tipo a exportar se encuentran en la carpeta.
for file in os.listdir():
if os.path.isfile(os.path.join(path, file)) and file.endswith(".csv"):
initial_count += 1
#endif
#endfor
#Read CSV File
def read_CSV_file(file_path):
with open(file_path, 'r', encoding="utf8") as f:
reader = csv.reader(f, delimiter=';')
for row in reader:
auxreader.append(row)
#print(row)
#print(len(auxreader))
auxcodigoDane = auxreader[1][0]
codigoDane = auxcodigoDane[0:12]
nombreSede = auxcodigoDane[13:]
#print(codigoDane)
#print(nombreSede)
for i in range(len(auxreader)):
if i > 15:
auxFecha = auxreader[i][11]
auxUP = auxreader[i][2]
auxDown = auxreader[i][5]
auxUNRE = auxreader[i][8]
ingreso.append([codigoDane, nombreSede, auxFecha, auxUP, auxDown, auxUNRE])
#endif
#endfor
#iterate through all file
for file in os.listdir():
#Check whether file is in text format or not
if file.endswith(".csv"):
file_path = f"{path}\{file}"
#call read text file funtion
read_CSV_file(file_path)
#completados += 1
#print(f"{completados} de {initial_count}, {file} Completado...")
#time.sleep(2)
#endif
#endfor
"""
with open('consolidado.csv', 'w') as csvfile:
fieldnames = mtzConsolidado1
writer = csv.DictWriter(csvfile, fieldnames=fieldnames, lineterminator='\n')
writer.writeheader()
for i in range(len(contenido)):
writer.writerow({'Host': contenido[i][0],
'Begin_date': contenido[i][1],
'End_date': contenido[i][2],
'Duration': contenido[i][3],
'Down': contenido[i][4],
'UP': contenido[i][5],
'UNREACHABLE': contenido[i][6],
'SCHEDULED DOWNTIME': contenido[i][7],
'UNDETERMINED': contenido[i][8]})
#endfor
"""