~michalr/telegram-covid-bot

a40d42470a936e29816c598f914fa0a7a4e2959c — Michał Rudowicz 1 year, 4 days ago 9e4f2e4
Error message in case of a country missing from the data
2 files changed, 14 insertions(+), 5 deletions(-)

M .rubocop.yml
M bot.rb
M .rubocop.yml => .rubocop.yml +3 -0
@@ 21,3 21,6 @@ Style/HashTransformKeys:

Style/HashTransformValues:
  Enabled: true

Metrics/MethodLength:
  Max: 15

M bot.rb => bot.rb +11 -5
@@ 56,13 56,19 @@ end
def get_current_data(for_when)
  data_uri = URI('https://raw.githubusercontent.com/CSSEGISandData/'\
      'COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/'\
      "#{for_when.strftime('%m-%d-%Y')}.csv")
      "#{for_when.strftime('%m-%d-%Y')}.csv").freeze

  raw_csv = Net::HTTP.get(data_uri)
  raw_csv = Net::HTTP.get(data_uri).freeze

  csv_format_to_our_format(CSV.parse(raw_csv, headers: true)
    .select { |e| e['Country_Region'] == Config['CountryCode'] }
    .first)
  country_data = CSV.parse(raw_csv, headers: true)
                    .select { |e| e['Country_Region'] == Config['CountryCode'] }
                    .first.freeze

  if country_data.nil?
    puts "No data for country #{Config['CountryCode']}."
    exit 1
  end
  csv_format_to_our_format(country_data)
end

yesterday = Date.today - 1