9
9
import json
10
10
from datetime import date , datetime
11
11
import requests
12
+ import random
12
13
13
14
global textos
14
15
global capitais
15
16
global estados
17
+ global cotacao
18
+ global proverbios
16
19
17
20
18
21
def buscar_noticias ():
@@ -35,12 +38,6 @@ def buscar_noticias():
35
38
textos .append (i .text )
36
39
37
40
38
- def chamar_atualizar ():
39
- import random
40
- print (textos [random .choice (range (len (textos )))])
41
- tela_noticias .label_noticias .setText (textos [random .choice (range (len (textos )))])
42
-
43
-
44
41
def montar_listas_capitais ():
45
42
global capitais
46
43
global estados
@@ -54,6 +51,36 @@ def montar_listas_capitais():
54
51
print (estados )
55
52
56
53
54
+ def buscar_cotacao ():
55
+ global cotacao
56
+ cotacoes = requests .get ('https://economia.awesomeapi.com.br/last/USD-BRL,EUR-BRL,BTC-BRL' )
57
+ cotacoes = cotacoes .json ()
58
+
59
+ dolar = str (cotacoes ['USDBRL' ]['bid' ])
60
+ dolar = dolar .replace ('.' , ',' )
61
+ print ('Dolar Americano' )
62
+ print (f'R$ { dolar } ' )
63
+
64
+ euro = str (cotacoes ['EURBRL' ]['bid' ])
65
+ euro = euro .replace ('.' , ',' )
66
+ print ('Euro' )
67
+ print (f'R$ { euro } ' )
68
+
69
+ btc = str (cotacoes ['BTCBRL' ]['bid' ])
70
+ print ('Bitcoin' )
71
+ print (f'{ btc } mil reais' )
72
+
73
+ cotacao = f'Dólar Americano: R$ { dolar } - Euro: R$ { euro } - Bitcoin { btc } mil reais'
74
+ print (cotacao )
75
+
76
+
77
+ def montar_proverbios ():
78
+ global proverbios
79
+ with open ('arquivos/proverbios.txt' , 'r' , encoding = "utf8" ) as arquivo :
80
+ proverbios = arquivo .readlines ()
81
+ print (random .choice (proverbios ))
82
+
83
+
57
84
def previsao_capital ():
58
85
consulta = tela_noticias .comboBox .currentText ()
59
86
print (consulta )
@@ -108,18 +135,33 @@ def previsao_capital():
108
135
f'{ data_hora .hour } :{ data_hora .minute } ' ))
109
136
110
137
138
+ def chamar_atualizar ():
139
+ print (textos [random .choice (range (len (textos )))])
140
+ print (cotacao )
141
+ tela_noticias .label_noticias .setText (textos [random .choice (range (len (textos )))])
142
+ tela_noticias .label_cotacao .setText (cotacao )
143
+ tela_noticias .label_proverbio .setText (proverbios [random .choice (range (len (proverbios )))])
144
+
145
+
146
+ def botao_voltar ():
147
+ import main
148
+ main .tela_main .show ()
149
+ app .exec ()
111
150
112
151
113
152
app = QtWidgets .QApplication ([])
114
153
tela_noticias = uic .loadUi ('tela_noticias.ui' )
115
154
tela_noticias .setWindowTitle ('Notícias' )
116
155
tela_noticias .setWindowIcon (QtGui .QIcon ('imagens/informativo_icon.png' ))
117
156
118
- tela_noticias .btn_atualizar .clicked .connect (chamar_atualizar )
119
157
tela_noticias .btn_tempo .clicked .connect (previsao_capital )
158
+ tela_noticias .btn_atualizar .clicked .connect (chamar_atualizar )
159
+ tela_noticias .btn_voltar .clicked .connect (botao_voltar )
120
160
121
161
buscar_noticias ()
122
162
montar_listas_capitais ()
163
+ buscar_cotacao ()
164
+ montar_proverbios ()
123
165
124
166
tela_noticias .show ()
125
167
app .exec ()
0 commit comments