use specific formatter for 'current' command
This commit is contained in:
parent
6a857021c7
commit
31921549a7
3 changed files with 25 additions and 3 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from weboob.capabilities.weather import ICapWeather
|
from weboob.capabilities.weather import ICapWeather
|
||||||
from weboob.tools.application.repl import ReplApplication
|
from weboob.tools.application.repl import ReplApplication
|
||||||
|
|
@ -35,6 +36,25 @@ class ForecastsFormatter(IFormatter):
|
||||||
result += ' %s' % item['text']
|
result += ' %s' % item['text']
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
class CurrentFormatter(IFormatter):
|
||||||
|
MANDATORY_FIELDS = ('id', 'date', 'temp')
|
||||||
|
|
||||||
|
def flush(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def format_dict(self, item):
|
||||||
|
if isinstance(item['date'], datetime):
|
||||||
|
date = item['date'].strftime('%y-%m-%d %H:%M:%S')
|
||||||
|
else:
|
||||||
|
date = item['date']
|
||||||
|
|
||||||
|
result = u'%s%s%s: %s' % (ReplApplication.BOLD, date, ReplApplication.NC, item['temp'])
|
||||||
|
if 'unit' in item and item['unit']:
|
||||||
|
result += u'°%s' % item['unit']
|
||||||
|
if 'text' in item and item['text']:
|
||||||
|
result += u' - %s' % item['text']
|
||||||
|
return result
|
||||||
|
|
||||||
class CitiesFormatter(IFormatter):
|
class CitiesFormatter(IFormatter):
|
||||||
MANDATORY_FIELDS = ('id', 'name')
|
MANDATORY_FIELDS = ('id', 'name')
|
||||||
count = 0
|
count = 0
|
||||||
|
|
@ -48,7 +68,7 @@ class CitiesFormatter(IFormatter):
|
||||||
backend = item['id'].split('@', 1)[1]
|
backend = item['id'].split('@', 1)[1]
|
||||||
result = u'%s* (%d) %s (%s)%s' % (ReplApplication.BOLD, self.count, item['name'], backend, ReplApplication.NC)
|
result = u'%s* (%d) %s (%s)%s' % (ReplApplication.BOLD, self.count, item['name'], backend, ReplApplication.NC)
|
||||||
else:
|
else:
|
||||||
result = u'%s* (%d) %s%s' % (ReplApplication.BOLD, item['id'], item['name'], ReplApplication.NC)
|
result = u'%s* (%s) %s%s' % (ReplApplication.BOLD, item['id'], item['name'], ReplApplication.NC)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
class WetBoobs(ReplApplication):
|
class WetBoobs(ReplApplication):
|
||||||
|
|
@ -57,9 +77,11 @@ class WetBoobs(ReplApplication):
|
||||||
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
COPYRIGHT = 'Copyright(C) 2010 Romain Bignon'
|
||||||
CAPS = ICapWeather
|
CAPS = ICapWeather
|
||||||
EXTRA_FORMATTERS = {'cities': CitiesFormatter,
|
EXTRA_FORMATTERS = {'cities': CitiesFormatter,
|
||||||
|
'current': CurrentFormatter,
|
||||||
'forecasts': ForecastsFormatter,
|
'forecasts': ForecastsFormatter,
|
||||||
}
|
}
|
||||||
COMMANDS_FORMATTERS = {'search': 'cities',
|
COMMANDS_FORMATTERS = {'search': 'cities',
|
||||||
|
'current': 'current',
|
||||||
'forecasts': 'forecasts',
|
'forecasts': 'forecasts',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ class WeatherPage(BasePage):
|
||||||
for img in div.getiterator("img"):
|
for img in div.getiterator("img"):
|
||||||
mtxt = img.attrib["title"]
|
mtxt = img.attrib["title"]
|
||||||
break
|
break
|
||||||
mdate = str(datetime.datetime.now())
|
mdate = datetime.datetime.now()
|
||||||
yield Current(mdate, temp, mtxt, "C")
|
yield Current(mdate, temp, mtxt, "C")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,8 +37,8 @@ class Current(CapBaseObject):
|
||||||
def __init__(self, date, temp, text, unit):
|
def __init__(self, date, temp, text, unit):
|
||||||
CapBaseObject.__init__(self, date)
|
CapBaseObject.__init__(self, date)
|
||||||
self.add_field('date', (basestring,datetime), date)
|
self.add_field('date', (basestring,datetime), date)
|
||||||
self.add_field('temp', (int,float), temp)
|
|
||||||
self.add_field('text', basestring, text)
|
self.add_field('text', basestring, text)
|
||||||
|
self.add_field('temp', (int,float), temp)
|
||||||
self.add_field('unit', basestring, unit)
|
self.add_field('unit', basestring, unit)
|
||||||
|
|
||||||
class City(CapBaseObject):
|
class City(CapBaseObject):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue