-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEj2.py
More file actions
119 lines (103 loc) · 4.53 KB
/
Copy pathEj2.py
File metadata and controls
119 lines (103 loc) · 4.53 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import csv
class GestorCSV:
@staticmethod
def generarCSV():
diccionario_olimpiadas = {}
with open("/home/dm2/PycharmProjects/UD2/Datos_Olimpiadas/athlete_events.csv") as file_athlete:
reader = csv.DictReader(file_athlete)
for linea in reader:
for juegos in linea:
if juegos == "Games":
if not diccionario_olimpiadas.__contains__(juegos):
diccionario_olimpiadas.update(
{linea[juegos]: [linea["Year"], linea["Season"], linea["City"]]})
with open("/home/dm2/PycharmProjects/UD2/olimpiadas.csv", "w+") as file_olimpiadas:
writer = csv.DictWriter(file_olimpiadas, fieldnames=["Games", "Year", "Season", "City"])
writer.writeheader()
for key in diccionario_olimpiadas:
year = diccionario_olimpiadas[key][0]
season = diccionario_olimpiadas[key][1]
city = diccionario_olimpiadas[key][2]
writer.writerow({"Games": key, "Year": year, "Season": season, "City": city})
@staticmethod
def buscarDeportista(deportista):
cont = 0
with open("/home/dm2/PycharmProjects/UD2/Datos_Olimpiadas/athlete_events.csv") as file_athlete:
reader = csv.DictReader(file_athlete)
for linea in reader:
if linea["Name"] == deportista:
if cont == 0:
print("Nombre: ", linea["Name"],
", Sexo :", linea["Sex"],
", Altura :", linea["Height"],
", Peso: ", linea["Weight"])
cont += 1
print(linea["Games"],
linea["Year"],
linea["Season"],
linea["City"],
linea["Sport"],
linea["Event"])
@staticmethod
def buscarDeporteOlimpiada(deporte, anio, temporada):
cont = 0
with open("/home/dm2/PycharmProjects/UD2/Datos_Olimpiadas/athlete_events.csv") as file_athlete:
reader = csv.DictReader(file_athlete)
for linea in reader:
if linea["Sport"] == deporte and linea["Year"] == anio and linea["Season"] == temporada:
if cont == 0:
print(linea["Games"],
linea["City"],
linea["Sport"])
cont += 1
print(linea["Name"],
linea["Event"],
linea["Medal"])
if cont == 0:
print("No se ha encontrado ningún deportista")
@staticmethod
def aniadirDeportista():
with open("/home/dm2/PycharmProjects/UD2/Datos_Olimpiadas/athlete_events.csv") as file_athlete:
fieldnames = ['ID',
'Name',
'Sex',
'Age',
'Height',
'Team',
'NOC',
'Games',
'Year',
'Season',
'City',
'Sport',
'Event',
'Medal']
writer = csv.DictWriter(file_athlete, fieldnames=fieldnames)
id = input("id")
name = input("nombre")
sexo = input("sexo")
edad = input("edad")
altura = input("altura")
equipo = input("equipo")
noc = input("NOC")
juegos = input("juegos")
anio = input("año")
temporada = input("temporada")
ciudad = input("ciudad")
deporte = input("deporte")
evento = input("evento")
medalla = input("Medalla")
writer.writerow({"ID": id,
"Name": name,
"Sex": sexo,
"Age": edad,
"Height": altura,
"Team": equipo,
"NOC": noc,
"Games": juegos,
"Year": anio,
"Season": temporada,
"City": ciudad,
"Sport": deporte,
"Event": evento,
"Medal": medalla})