This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime # Para sabermos o mês e ano atual | |
# As três primeiras letras de cada mês, usadas pra formar a URL. | |
# Botamos o primeiro elemento vazio porque os índices da lista começam a contar do 0. | |
# Assim, temos corretamente que months[1] = 'Jan', months[7] = 'Jul', etc. | |
months = ['', 'Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'] | |
# Nosso código do porto | |
code = '60245' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pra cada tr na lista... | |
for tr in tr_list: | |
# Se houver algum elemento no tr com bgcolor #C0C0C0 (legenda)... | |
if tr.find(lambda tag: tag.get('bgcolor') == '#C0C0C0') is not None: | |
print('Tag de título, ignorando') | |
continue # Quebrar o loop e ir pro próximo tr | |
print('nop') | |
# Se só houver um elemento td em tr... | |
if len(tr.find_all(lambda tag: tag.name == 'td')) == 1: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
last_seen_day = '' # Pra guardarmos o último dia visto | |
max_height = float('-INF') # Menor valor possível, pra futuras comparações | |
max_height_time = '' # Hora da maior altura | |
max_height_day = '' # Dia da maré com maior altura | |
min_height = float('INF') # Maior valor possível, pra futuras comparações | |
min_height_time = '' # Hora da menor altura | |
min_height_day = '' # Dia da maré com menor altura |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print('===============') | |
print('Maré alta:', max_height, 'm') | |
print('Dia:', max_height_day) | |
print('Hora:', max_height_time) | |
print('===============') | |
print('Maré baixa:', min_height, 'm') | |
print('Dia:', min_height_day) | |
print('Hora:', min_height_time) | |
print('===============') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests # Para carregarmos a página da web | |
import bs4 # Para retirarmos informações do HTML | |
from datetime import datetime # Para sabermos o mês e ano atual | |
# As três primeiras letras de cada mês, usadas pra formar a URL. | |
# Botamos o primeiro elemento vazio porque os índices da lista começam a contar do 0. | |
# Assim, temos corretamente que months[1] = 'Jan', months[7] = 'Jul', etc. | |
months = ['', 'Jan', 'Fev', 'Mar', 'Abr', 'Mai', 'Jun', 'Jul', 'Ago', 'Set', 'Out', 'Nov', 'Dez'] | |
# Nosso código do porto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bs4 | |
soup = bs4.BeautifulSoup(r.text, 'html.parser') # Criar uma "sopa" com o HTML que buscamos | |
# Aqui procuramos o elemento table, que contém os tr em que estamos interessados | |
# A função find acha só o primeiro elemento que corresponde ao indicado | |
table = soup.find(lambda tag: tag.name == 'table') | |
# O find_all, em contraste, retorna uma lista com todos os elementos que correspondem | |
# ao que pedimos e retorna uma lista com eles. Note que agora ao invés de procurarmos | |
# na sopa (página toda), procuramos só entre os elementos do table que achamos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s1 = '13579' | |
s2 = '24680' | |
s3 = ''.join([s1[i//2] if i % 2 == 0 else s2[i//2] for i in range(len(s1 + s2))]) | |
print(s3) # 1234567890 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
txt = r""" | |
import machine | |
import time | |
led = machine.Pin(2, machine.Pin.OUT) | |
while True: | |
led.value(0) | |
time.sleep(0.5) | |
led.value(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def ok(): | |
print('hello, world!') | |
ok() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s1 = 'abacate' | |
s2 = 'palmeiras' | |
def g(s1, s2): | |
d = [dict(zip([i for i in range(len(f))], [x for x in f])) for f in [s1, s2]] | |
for i in range(max([len(r) for r in d])): | |
for k in [False, True]: | |
yield d[k].get(i, '') | |
print(''.join([f for f in g(s1, s2)])) # apbaalcmaetieras |
OlderNewer