5 Commits

Author SHA1 Message Date
fauno 07aca746a9 v0.5.3 2023-04-22 21:07:13 -03:00
fauno 8be1dbca5b fix: check if country is available 2023-04-22 21:05:32 -03:00
fauno 3e25cf532a v0.5.2 2023-04-20 11:40:30 -03:00
fauno 7cb89e1df8 fix: support postgres:// too 2023-04-20 11:40:19 -03:00
fauno 544b188994 feat: log parsing exceptions 2023-04-20 11:39:05 -03:00
3 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
name: "access_log"
version: "0.5.1"
version: "0.5.3"
authors:
- "f <f@sutty.nl>"
targets:
+7 -3
View File
@@ -1,3 +1,4 @@
require "log"
require "file_utils"
require "json"
require "socket"
@@ -9,7 +10,9 @@ require "./models/access_log"
require "./models/crawler"
require "./swd"
VERSION = "0.5.1"
VERSION = "0.5.3"
Log.setup_from_env
# Default socket location
socket = "/tmp/access_log.socket"
@@ -82,7 +85,7 @@ OptionParser.parse do |p|
end
# Parameterize values according to database URI
if database.starts_with? "postgresql://"
if database.starts_with?("postgresql://") || database.starts_with?("postgres://")
params = fields.map_with_index do |_, i|
"$#{i + 1}"
end
@@ -187,7 +190,8 @@ db = DB.open database do |db|
(swd ? s.try(&.total_co2) : nil)
# Ignore parsing errors
rescue JSON::ParseException
rescue e : JSON::ParseException
Log.warn &.emit("Parse exception", error: e.message)
rescue IO::Error
server.close
FileUtils.rm(socket) if File.exists? socket
+2 -2
View File
@@ -9,13 +9,13 @@ class SWD
# Return the marginal intensity for a country when provided an ISO
# code
def self.marginal_by_iso(iso : String) : Float64?
MARGINAL_INTENSITY_BY_ISO_CODE[iso]
MARGINAL_INTENSITY_BY_ISO_CODE[iso] if MARGINAL_INTENSITY_BY_ISO_CODE.has_key? iso
end
# Return the average intensity for a country when provided an ISO
# code
def self.average_by_iso(iso : String) : Float64?
AVERAGE_INTENSITY_BY_ISO_CODE[iso]
AVERAGE_INTENSITY_BY_ISO_CODE[iso] if AVERAGE_INTENSITY_BY_ISO_CODE.has_key? iso
end
def self.by_iso(iso : String, type : Symbol = :marginal) : Float64?