-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspaceX.py
More file actions
142 lines (107 loc) · 3.45 KB
/
Copy pathspaceX.py
File metadata and controls
142 lines (107 loc) · 3.45 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import os, sys, time
from connections import Connect
class SpaceX(object):
"""
Menu to choice the consult.
"""
NEXT_LAUNCH = 1
LATEST_LAUNCH = 2
UPCOMING_LAUNCHES = 3
PAST_LAUNCHES = 4
@classmethod
def run(cls):
"""
Shows the options for the user
:return: chosen option
"""
while(True):
print("O que você deseja visualizar?\n")
print("1) Próximo Lançamento") # next_launch
print("2) Último Lançamento") # latest launch
print("3) Próximos Lançamentos") # upcoming launches
print("4) Lançamentos Passados") # past launches
print("5) Sair\n")
try:
option = int(input("Insira uma opção: "))
except ValueError:
print("Você deve inserir somente números inteiros de preferencia de 1 a 5")
option = 0
if option < 1 or option > 5:
print("Essa opção não existe, por favor insira uma opção válida.\n")
cls.__clean(3)
elif option == 5:
cls.__close()
break
else:
cls.__show_result(option)
answer = input("Deseja sair da aplicação? (S/N): ")
if answer.lower().startswith("s"):
cls.__close()
break
cls.__clean(1)
@classmethod
def __show_result(cls, option):
"""
Run a specific option inserted
:param option: Option to visualize some datas
"""
print()
if option == SpaceX.NEXT_LAUNCH:
cls.__next_launch()
elif option == SpaceX.LATEST_LAUNCH:
cls.__latest_launch()
elif option == SpaceX.UPCOMING_LAUNCHES:
cls.__upcoming_launches()
elif option == SpaceX.PAST_LAUNCHES:
cls.__past_launches()
else:
print("Opção invalida")
@staticmethod
def __clean(seconds):
"""
Clean the prompt
"""
time.sleep(seconds)
if 'win' in sys.platform:
os.system("cls")
else:
os.system("clear")
@staticmethod
def __close():
"""
Close the program.
"""
print("Finalizando o programa...")
time.sleep(1)
@staticmethod
def __next_launch():
"""
Returns the next launch
"""
connection = Connect("https://api.spacexdata.com/v3/launches/next")
print(connection.result)
@staticmethod
def __upcoming_launches():
"""
Returns the closest upcoming launches
"""
connection = Connect("https://api.spacexdata.com/v3/launches/upcoming")
for result in connection.result:
print(result)
print("----------------------------------------------------------\n")
@staticmethod
def __latest_launch():
"""
Returns the latest launch
"""
connection = Connect("https://api.spacexdata.com/v3/launches/latest")
print(connection.result)
@staticmethod
def __past_launches():
"""
Returns the past launches
"""
connection = Connect("https://api.spacexdata.com/v3/launches/past")
for result in connection.result:
print(result)
print("----------------------------------------------------------\n")