This repository has been archived by the owner on Jun 16, 2024. It is now read-only.
forked from reciclanet/SCRIPTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_harddisk_csv.py
executable file
·65 lines (55 loc) · 2.39 KB
/
json_harddisk_csv.py
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
#!/usr/bin/env python3
# Copyright 2000-2019 Reciclanet Asociación Educativa-Reciclanet Hezkuntza Elkartea www.reciclanet.org
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import json
import csv
import os
path_to_json = "./jsons/"
try:
json_files = os.listdir(path_to_json)
except FileNotFoundError:
print("No existe el directorio " + path_to_json + " con los archivos JSON")
exit()
with open("discos_duros.csv", "a+") as computer:
csv_write_file = csv.writer(computer)
computer.seek(0)
csv_reader = csv.reader(computer)
for json_file in json_files:
with open(path_to_json + json_file, "r") as read_file:
data_file = json.load(read_file)
for index in data_file["components"]:
if index["@type"] == "HardDrive":
for row in csv_reader:
if row[2] == index["serialNumber"]:
print("El archivo/disco ya está procesado: porque coinciden los S/N")
break
else:
print("Añadiendo línea... S/N: " + index["serialNumber"] + ", Label: " + data_file["label"])
try:
hdd_manufacturer = index["manufacturer"]
except KeyError:
hdd_manufacturer = "-"
csv_write_file.writerow([
hdd_manufacturer,
index["model"],
index["serialNumber"],
"Sobrescritura",
str(index["size"] / 1000) + " GB",
"",
data_file["label"],
])
break
else:
continue