local lapis = require("lapis") local config = require("lapis.config").get() local to_json = require("lapis.util").to_json local app = lapis.Application() local models = require("models") app:get("/", function(self) -- return "Welcome to Lapis " .. require("lapis.version") return config.greeting .. " from port " .. config.postgres.password end) app:match("/spl/:station", function(self) -- print( to_json(self.params)) -- artist=%a& -- track=%t& -- release=%T -- label=%L& -- year=%Y& -- country=%O& -- info_url=%U1& -- img_url=%U2& -- time=%h& -- artist=%a&track=%t&release=%Tlabel=%L&year=%Y&country=%O&info_url=%U1&img_url=%U2&time=%h& -- ----- -- -- setup -- -- ----- -- local artist_name = self.params.artist local track_name = self.params.track -- local track_length = self.params.length local track_info_url = self.params.info_url local track_img_url = self.params.img_url local release_name = self.params.release local release_year = self.params.year local release_country = self.params.country local label_name = self.params.label local airtime = self.params.time -- we have to split the `hr:min:sec` string from SPL local function Split(s, delimiter) local result = {} for match in (s..delimiter):gmatch("(.-)"..delimiter) do table.insert(result, match) end return result end local split_airtime = Split(airtime, ":") local airtime_hr, airtime_min, airtime_sec = split_airtime[1], split_airtime[2], split_airtime[3] local airtime_stamp = os.time{year=os.date("%Y"), month=os.date("%m"), day=os.date("%d"), hour=airtime_hr, min=airtime_min, sec=airtime_sec} -- ------- -- -- queries -- -- ------- -- local artist = models.Artists:find({ name = artist_name }) if not artist then print("new artist: " .. artist_name) artist = models.Artists:create({ name = artist_name }) else print("old artist.") end local track = models.Tracks:find({ name = track_name }) if not track then print("new track: " .. track_name) track = models.Tracks:create({ name = track_name, unique_name = track_name:lower() }) else print("old track.") end local station = models.Stations:find({ station = self.params.station }) if not station then print("unknown station: " .. self.params.station) else print("This is: " .. station["name"]) end -- airtime -- local airtime = models.Airtimes:create({ -- airtime = airtime_stamp, -- tracks = track, -- stations = station -- }) end) return app