Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: u8 -*-
- from account import *
- from vkrobot import *
- import xml.etree.ElementTree as ET
- import datetime
- import urllib
- rb = VKRobot(login, password, delay_time=1)
- def get_weather():
- u = 'http://informer.gismeteo.ru/xml/34116_1.xml'
- xml = utils.get_page(u)
- root = ET.fromstring(xml)
- town = root.find('REPORT/TOWN').get('sname')
- town = town.replace('+', ' ')
- town = urllib.unquote(town).decode('1251')
- dt = datetime.datetime.now()
- for forecast in root.findall('REPORT/TOWN/FORECAST'):
- # for k in forecast.keys():
- # print k, '=', forecast.get(k)
- h = forecast.get('hour')
- if dt.hour < int(h):
- break
- tod = [
- u'ночь',
- u'утро',
- u'день',
- u'вечер'
- ][int(forecast.get('tod'))]
- status = town + ' | ' + tod.title() + ' | '
- phenomena = forecast.find('PHENOMENA')
- # облачность
- status += [
- u'☀',
- u'⛅',
- u'☁',
- '',
- ][ int( phenomena.get('cloudiness') ) ]
- # тип осадков: 4 - дождь, 5 - ливень, 6,7 – снег, 8 - гроза, 9 - нет данных, 10 - без осадков
- status += {
- 4: u'💦',
- 5: u'☔',
- 6: u'❄',
- 7: u'❄',
- 8: u'⚡',
- 9: 'n/a',
- 10: ''
- }[ int( phenomena.get('precipitation') ) ]
- format_temperature = lambda t: re.sub(r'^(\d)', '+\\1', t)
- status += ' ' + format_temperature( forecast.find('TEMPERATURE').get('min') )
- status += '..' + format_temperature( forecast.find('TEMPERATURE').get('max') ) + u'°C'
- status += u' | 💧 ' + forecast.find('RELWET').get('min') + '-' + forecast.find('RELWET').get('max') + '%'
- status += u' | Ветер: ' + forecast.find('WIND').get('min') + '-' + forecast.find('WIND').get('max') + u' м/с '
- return status
- def count_messages():
- s = u'✉ Сообщения | 📥 Входящие: '
- r = rb.messages_get(count=0)
- s += str(r['count'])
- r = rb.messages_get(count=0, out=1)
- s += u' | 📤 Исходящие: '
- s += str(r['count'])
- return s
- def get_rate():
- L = []
- u = 'http://www.cbr.ru/scripts/XML_daily.asp'
- d = utils.get_page(u)
- r = ET.fromstring(d)
- for e in r.findall('Valute'):
- cod = e.find('CharCode').text
- if cod in ['USD', 'EUR', 'CNY']:
- L.append( cod + ' ' + e.find('Nominal').text + ':' + e.find('Value').text )
- return u'💵 Курс к RUB | ' + ' | '.join(L)
- # def get_quote():
- # j = utils.get_page('http://forismatic.com/api/1.0/', 'method=getQuote&format=json¶m=ms&lang=ru')
- # j = json.loads(j)
- # return j['quoteText'] + u' © ' + j['quoteAuthor']
- informers = [
- get_rate,
- get_weather,
- count_messages,
- ]
- i = 0
- while True:
- informer = informers[i]
- rb.status_set( informer() )
- rb.delay(95)
- i += 1
- if i == len(informers):
- i = 0
- print 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement