Skip to content

Commit

Permalink
Completed support for weather
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoBuster committed Jul 28, 2017
1 parent 6d70217 commit 0dda5fa
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/updates/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def process_callback(bot, cb, u):

elif not arguments:
u.increaseStat('stats_stations')
text = format.formatStation(station_name)
text = format.formatStation(station_name, station)
bot.api.call('editMessageText', {
'chat_id': cb.chat.id, 'message_id': cb.message.message_id,
'text': text, 'parse_mode': 'HTML', 'reply_markup':
Expand All @@ -427,7 +427,7 @@ def process_callback(bot, cb, u):
return

elif len(arguments) == 1 and arguments[0] == "wiki":
text = format.formatStation(station_name, withWikiSummary=True)
text = format.formatStation(station_name, station, withWikiSummary=True)
bot.api.call('editMessageText', {
'chat_id': cb.chat.id, 'message_id': cb.message.message_id,
'text': text, 'parse_mode': 'HTML', 'reply_markup':
Expand Down Expand Up @@ -672,7 +672,7 @@ def process_inline_callback(bot, cb, u):

if not arguments:
u.increaseStat('stats_stations')
text = format.formatStation(station_name)
text = format.formatStation(station_name, station)
bot.api.call('editMessageText', {
'inline_message_id': cb.inline_message_id,
'text': text, 'parse_mode': 'HTML', 'reply_markup':
Expand All @@ -689,7 +689,7 @@ def process_inline_callback(bot, cb, u):
return

elif len(arguments) == 1 and arguments[0] == "wiki":
text = format.formatStation(station_name, withWikiSummary=True)
text = format.formatStation(station_name, station, withWikiSummary=True)
bot.api.call('editMessageText', {
'inline_message_id': cb.inline_message_id,
'text': text, 'parse_mode': 'HTML', 'reply_markup':
Expand Down
2 changes: 1 addition & 1 deletion src/updates/deeplinking.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def process_deeplinking(bot, message, args):

u.increaseStat('stats_stations')

text = format.formatStation(station_name)
text = format.formatStation(station_name, station)
bot.api.call('sendMessage', {
'chat_id': message.chat.id, 'text': text, 'parse_mode': 'HTML', 'reply_markup':
json.dumps(
Expand Down
2 changes: 1 addition & 1 deletion src/updates/inline.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def not_found_answer():
"title": "🚉 Stazione di {station}".format(station=station['nomeLungo']),
"description": "👉 Informazioni sulla stazione di {station}".format(station=station['nomeLungo']),
"input_message_content": {
"message_text": format.formatStation(station['nomeLungo']),
"message_text": format.formatStation(station['nomeLungo'], station['id']),
"parse_mode": "HTML",
"disable_web_page_preview": True
},
Expand Down
2 changes: 1 addition & 1 deletion src/updates/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def minifyStation(__str):
elif len(results) == 1:
u.increaseStat('stats_stations')

text = format.formatStation(results[0]['nomeLungo'])
text = format.formatStation(results[0]['nomeLungo'], results[0]['id'])
bot.api.call('sendMessage', {
'chat_id': chat.id, 'text': text, 'parse_mode': 'HTML', 'reply_markup':
json.dumps(
Expand Down
13 changes: 9 additions & 4 deletions src/viaggiatreno/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,23 @@ def getWikipediaSummary(station: str):
return cleanHTML(result) + " (da Wikipedia, l'enciclopedia libera)"


def formatStation(station: str, withWikiSummary=False):
def formatStation(station: str, station_id: str, withWikiSummary=False):
if withWikiSummary:
text = (
"🚉 <b>Stazione di {name}</b>"
"\nℹ️ <i>{wikipedia}</i>"
"\n\noqm{weather}"
.format(name=station.title(),
wikipedia=getWikipediaSummary(station))
wikipedia=getWikipediaSummary(station),
weather=getWeather(station_id=station_id))
)
return text
else:
text = (
"🚉 <b>Stazione di {name}</b>"
"\n<i>Premi il tasto sotto per mostrare le informazioni da Wikipedia</i>"
.format(name=station.title())
"\n\n{weather}"
.format(name=station.title(), weather=getWeather(station_id=station_id))
)
return text

Expand Down Expand Up @@ -462,12 +465,14 @@ def formatTrainStop(raw: dict, stop_number: int):
"{arrival}"
"{departure}"
"\n🛤 <b>Binario</b>: {platform}"
"\n{weather}"
.format(
train=raw['compNumeroTreno'],
station=stop['stazione'], href=gDLHREF(gSCQ(stop), "più informazioni sulla stazione"),
arrival="\n🚥 <b>Arrivo</b>: {arrival}".format(arrival=arrival) if arrival else "",
departure="\n🚥 <b>Partenza</b>: {departure}".format(departure=departure) if departure else "",
platform=platform
platform=platform,
weather=getWeather(stop['id']),
)
)
return text
Expand Down

0 comments on commit 0dda5fa

Please sign in to comment.