-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "report" | ||
require_relative "../weather/allerta_meteo/client" | ||
|
||
module FortunaLuca | ||
module Reports | ||
class AllertaMeteo | ||
include Report | ||
|
||
def call | ||
return unless show? | ||
|
||
config.each do |chat_id| | ||
send_telegram_message(chat_id, message) if message | ||
end | ||
|
||
true | ||
end | ||
|
||
private | ||
|
||
def message | ||
return unless tomorrow_entry | ||
|
||
[ | ||
"⚠️ #{tomorrow_entry.title}", | ||
tomorrow_entry.summary, | ||
tomorrow_entry.links.first | ||
].join("\n") | ||
end | ||
|
||
def tomorrow_entry | ||
@tomorrow_entry ||= feed_entries.find do |entry| | ||
entry.title.match?(/^Allerta .* valida .* #{date.strftime("%d-%m-%Y")}/) | ||
end | ||
end | ||
|
||
def feed_entries | ||
FortunaLuca::Weather::AllertaMeteo::Client.new.call | ||
end | ||
|
||
# JSON Config format: ["chat_id"] | ||
def config | ||
@config ||= JSON.parse(env_or_blank("REPORTS_ALLERTA_METEO_CONFIG")) | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# frozen_string_literal: true | ||
|
||
require "httpclient" | ||
require "feedjira" | ||
|
||
module FortunaLuca | ||
module Weather | ||
module AllertaMeteo | ||
class Client | ||
URL = "https://allertameteo.regione.marche.it/compila-allerta-portlet/feed?feed=allerte-bollettini" | ||
|
||
# @return [Array<Feedjira::Parser::AtomEntry>] The feed entries | ||
def call | ||
data = HTTPClient.get(URL).body | ||
Feedjira.parse(data).entries | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
require_relative '../lib/fortuna_luca/reports/allerta_meteo' | ||
|
||
task :send_allerta_meteo_report do | ||
FortunaLuca::Reports::AllertaMeteo.new(Date.today.succ).call | ||
end |