-
Notifications
You must be signed in to change notification settings - Fork 11
/
bott.py
92 lines (62 loc) · 3.25 KB
/
bott.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
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
import os
import time
import re
import json
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from collections import Counter as cnt
class newbot:
def __init__(self, nome_bot):
self.driver = webdriver.Firefox()
def climaTempo(self):
try:
site = 'https://www.climatempo.com.br'
self.driver.get(site)
self.driver.implicitly_wait(20)
i = 0
while True:
estado=11
cidades = [70,217]
#11 = Minas Gerais
#70 = Belo Horizonte, 217 = Contagem
self.driver.find_element_by_xpath('//*[@id="momento-localidade"]').click()
self.driver.find_element_by_xpath('/html/body/div[7]/select[1]/option[' + str(estado) + ']').click()
self.driver.find_element_by_xpath('/html/body/div[7]/select[2]/option[' + str(cidades[i]) + ']').click()
self.driver.find_element_by_xpath('//*[@id="btn-confirm-geo"]').click()
time.sleep(20)
localidade = self.driver.find_element_by_xpath('//*[@id="momento-localidade"]').text
temperatura = self.driver.find_element_by_xpath('//*[@id="momento-temperatura"]').text
condicao = self.driver.find_element_by_xpath('//*[@id="momento-condicao"]').text
sensacao = self.driver.find_element_by_xpath('//*[@id="momento-sensacao"]').text
humidade = self.driver.find_element_by_xpath('//*[@id="momento-humidade"]').text
pressao = self.driver.find_element_by_xpath('//*[@id="momento-pressao"]').text
velocVento = self.driver.find_element_by_xpath('//*[@id="momento-vento"]').text
ultimaAtualizacao = self.driver.find_element_by_xpath('//*[@id="momento-atualizacao"]').text
dat = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
print("Localidade: " + localidade)
print("Temperatura: " + temperatura)
print("Condição: " + condicao)
print("Sensação Termica: " + sensacao)
print("Humidade: " + humidade)
print("Pressão: " + pressao)
print("Velocidade do Vento: " + velocVento)
print("Ultima Atualização Clima Tempo: " + ultimaAtualizacao)
print("Data da Consulta: " + dat)
print('-----------------------------')
time.sleep(10)
dados = localidade + ';' + temperatura + ';' + condicao + ';' + sensacao + ';' + humidade + ';' + pressao + ';' + velocVento + ';' + ultimaAtualizacao + ';' + dat
self.salvaDados(dados)
i+=1
if(i>1):
i=0
except:
self.driver.close()
self.erro()
def erro(self):
self.climaTempo()
def salvaDados(self, dados):
datt = datetime.now().date().strftime("%Y-%m-%d")
arquivo = open('C:/Users/rafael.dourado/Desktop/ClimaTempo/Dados - ' + datt + '.txt', 'a')
arquivo.write(dados + '\n')
arquivo.close()