Skip to content

Commit

Permalink
🐛 dolar: handle network errors
Browse files Browse the repository at this point in the history
also increase execution frequency from 120s to 60s in polybar's config
  • Loading branch information
cristianmiranda committed Feb 5, 2024
1 parent d34745e commit d5cef27
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion home/.config/polybar/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ click-left = $HOME/bin/wm --go-to-by-class thunderbird > /dev/null

[module/dolarblue]
type = custom/script
interval = 120
interval = 60
format = <label>
label = "%output%"
label-padding = 0
Expand Down
20 changes: 12 additions & 8 deletions home/bin/dolar
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,21 @@ def usage
end

def fetch_usd_value(type)
response = Net::HTTP.get(URI("https://mercados.ambito.com/dolar/#{type}/variacion"))
output = JSON.parse(response)
begin
response = Net::HTTP.get(URI("https://mercados.ambito.com/dolar/#{type}/variacion"))
output = JSON.parse(response)

buy_price = output['compra']
sell_price = output['venta']
variation = output['variacion']
last_closing_value = output['valor_cierre_ant']
buy_price = output['compra']
sell_price = output['venta']
variation = output['variacion']
last_closing_value = output['valor_cierre_ant']

variation = variation.start_with?('-') ? "🔴 #{variation}" : "🟢 #{variation}"
variation = variation.start_with?('-') ? "🔴 #{variation}" : "🟢 #{variation}"

puts "💵 #{buy_price} / #{sell_price} // #{variation} (#{last_closing_value})"
puts "💵 #{buy_price} / #{sell_price} // #{variation} (#{last_closing_value})"
rescue SocketError, Errno::ENETUNREACH
puts "💸 - / -"
end
end

options = {}
Expand Down

0 comments on commit d5cef27

Please sign in to comment.