87 lines
2.2 KiB
Lua
87 lines
2.2 KiB
Lua
local lapis = require("lapis")
|
|
local config = require("lapis.config").get()
|
|
local to_json = require("lapis.util").to_json
|
|
local models = require("models")
|
|
|
|
-- print("models has type: " .. type(models))
|
|
-- print(to_json(models))
|
|
|
|
local app = lapis.Application()
|
|
|
|
app:get("/", function()
|
|
-- return "Welcome to Lapis " .. require("lapis.version")
|
|
return config.greeting .. " from port " .. config.postgres.password
|
|
|
|
end)
|
|
|
|
app:match("/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:select("where name = ?", artist_name)
|
|
|
|
-- if not artist then
|
|
-- print("new artist!")
|
|
-- artist = models.Artists:create({
|
|
-- name = artist_name
|
|
-- })
|
|
-- else
|
|
-- print("old artist.")
|
|
-- end
|
|
|
|
-- local track = models.Tracks:select("where name = ?", track_name)
|
|
|
|
-- if track == nil then
|
|
-- track = models.Tracks:create({
|
|
-- name = track_name
|
|
-- })
|
|
-- end
|
|
|
|
end)
|
|
|
|
return app
|