-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (51 loc) · 1.52 KB
/
main.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
#Script encargado de bajar imagenes de LoremPixel
from urllib.request import urlopen
import os
url = "http://lorempixel.com"
cathegories = ["abstract", "animals", "business","cats","city","food","nightlife","fashion","people","nature","sports","technics","transport"]
#Comprobar que los valores son correctos por medio de un While
while(True):
os.system("cls")
print("\n")
ancho = input("¿Ancho de la imagen?")
alto = input("¿Alto de la imagen?")
if ancho.isdigit() and alto.isdigit():
break
else:
print("Los valores deberán de ser digitos")
input("Continuar...")
#Comprobar categoria existente
while(True):
print("\n¿Categoría?\n")
for c in cathegories:
print(c)
print("\n")
categoria = input()
if categoria in cathegories:
break
else:
os.system("cls")
print("\nCategoría incorrecta, selecciona y escribe una de la lista")
#texto en la imagen
while(True):
text = input("¿Quieres un texto en la imagen [S/N]?")
if text == 's' or text == 'S':
texto = input("Escribe el texto: ")
break
elif text == 'n' or text == 'N':
print("¡No pasa nada :)!")
break
else:
os.system("cls")
print("\nOpcion no valida, intenta de nuevo.")
try:
url = "http://lorempixel.com/{}/{}/{}/{}".format(ancho, alto,categoria,texto)
except:
url = "http://lorempixel.com/{}/{}/{}".format(ancho, alto, categoria)
r = urlopen(url)
lectura = r.read()
imagen = open("{}.jpeg".format(categoria), "wb")
imagen.write(lectura)
imagen.close()
print("\nLa imagen ha sido guardada con éxito.")
input("Pulsa una tecla para salir...")