Created
June 11, 2016 08:30
-
-
Save anonymous/4eb8fb1abc29ad220aa320b02ecc53f7 to your computer and use it in GitHub Desktop.
.scripts/realmeteo.py
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
#!/usr/bin/env python3 | |
import sys | |
import urllib3 | |
import datetime | |
from bs4 import BeautifulSoup | |
args = sys.argv[1:] | |
if args: | |
station = args[0] | |
else: | |
station = str(1) | |
url = 'http://realmeteo.ru/spb/' + station + '/current' | |
try: | |
read_url = urllib3.PoolManager().urlopen | |
html = read_url('GET', url).data.decode('utf-8') | |
soup = BeautifulSoup(html, 'lxml') | |
updated_str = soup.find('td', id="date_time").text.split('\n')[2].strip() | |
hours, minutes = (int(i) for i in updated_str.split(':')) | |
today = datetime.datetime.today() | |
start = datetime.datetime(today.year, today.month, today.day) | |
updated = start + datetime.timedelta(hours=hours, minutes=minutes) | |
time_passed = (datetime.datetime.now() - updated).seconds//60 | |
table = soup.find("table", id="realdata") | |
rows = table.find_all("tr") | |
t_real = rows[0].find_all('td')[1].text.strip() | |
t_feel = rows[0].find_all('td')[2].text.strip() | |
pressure = rows[2].find_all('td')[0].text.strip() | |
humidity = rows[2].find_all('td')[1].text.strip() | |
wind = ' '.join(rows[4].find_all('td')[0].text.strip().split()) | |
print('Температура: ' + t_real + '\n' + | |
'Ощущаемая: ' + t_feel + '\n' + | |
'Давление: ' + pressure + '\n' + | |
'Влажность: ' + humidity + '\n' + | |
'Ветер: ' + wind + '\n' + | |
'—————————————————————————————\n' + | |
'Обновлено ' + str(time_passed) + ' минут назад') | |
except: | |
print('Error!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment