Last edit: @kyork in #marvin-dev 1 year ago - Slack Archive

{lua} local query = args
-- Newark seems to be gone from the database
-- and it doesn't accept state names, it's now "Fremont, US"
-- this is extremely useless
-- so we just hardcode the OWM place ID
if query == "" then query = "Newark, California, US" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?id=5350734&q=" .. bot.uriencode(query) .. "&APPID=" .. fmap.api_keys.openweathermap)
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data,def)
  if data.coord == nil then return "(Place not found)" end
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return def end
 local ok, gj = pcall(function() return r2:json() end)
 if not ok then return def end
 if gj.status ~= "OK" then return def end
 if #gj.predictions == 0 then return def end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j, j.name)
print(json.dump(j))

History

Revision: 2919 by @kyork in #marvin-dev 1 year agoSlack Archive

{lua} local query = args
-- Newark seems to be gone from the database
-- and it doesn't accept state names, it's now "Fremont, US"
-- this is extremely useless
-- so we just hardcode the OWM place ID
if query == "" then query = "Newark, California, US" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?id=5350734&q=" .. bot.uriencode(query) .. "&APPID=" .. fmap.api_keys.openweathermap)
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data,def)
  if data.coord == nil then return "(Place not found)" end
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return def end
 local ok, gj = pcall(function() return r2:json() end)
 if not ok then return def end
 if gj.status ~= "OK" then return def end
 if #gj.predictions == 0 then return def end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j, j.name)
print(json.dump(j))

Revision: 2917 by @kyork in #marvin-dev 1 year agoSlack Archive

{lua} local query = args
-- Newark seems to be gone from the database
-- and it doesn't accept state names, it's now "Fremont, US"
-- this is extremely useless
-- so we just hardcode the OWM place ID
if query == "" then query = "Newark, California, US" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?id=5350734&q=" .. bot.uriencode(query) .. "&APPID=" .. fmap.api_keys.openweathermap)
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data,def)
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return def end
 local ok, gj = pcall(function() return r2:json() end)
 if not ok then return def end
 if gj.status ~= "OK" then return def end
 if #gj.predictions == 0 then return def end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j, j.name)
print(json.dump(j))

Revision: 2916 by @kyork in #marvin-dev 1 year agoSlack Archive

{lua} local query = args
-- Newark seems to be gone from the database
-- and it doesn't accept state names, it's now "Fremont, US"
-- this is extremely useless
-- so we just hardcode the OWM place ID
if query == "" then query = "Newark, CA" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?id=5350734&q={" .. bot.uriencode(query) .. "}&APPID=" .. fmap.api_keys.openweathermap)
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data,def)
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return def end
 local ok, gj = pcall(function() return r2:json() end)
 if not ok then return def end
 if gj.status ~= "OK" then return def end
 if #gj.predictions == 0 then return def end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j, j.name)
print(json.dump(j))

Revision: 2915 by @kyork in #marvin-dev 1 year agoSlack Archive

{lua} local query = args
-- Newark seems to be gone from the database
-- and it doesn't accept state names, it's now "Fremont, US"
-- this is extremely useless
-- so we just hardcode the OWM place ID
if query == "" then query = "Newark, CA" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?id=5350734&APPID=" .. fmap.api_keys.openweathermap)
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data,def)
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return def end
 local ok, gj = pcall(function() return r2:json() end)
 if not ok then return def end
 if gj.status ~= "OK" then return def end
 if #gj.predictions == 0 then return def end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j, j.name)
print(json.dump(j))

Revision: 2582 by @kyork in (via web) 1 year agoSlack Archive

{lua} local query = ""
-- Newark seems to be gone from the database
-- and it doesn't accept state names, it's now "Fremont, US"
-- this is extremely useless
-- so we just hardcode the OWM place ID
if query == "" then query = "Newark, CA" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?id=5350734&APPID=" .. fmap.api_keys.openweathermap)
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data,def)
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return def end
 local ok, gj = pcall(function() return r2:json() end)
 if not ok then return def end
 if gj.status ~= "OK" then return def end
 if #gj.predictions == 0 then return def end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j, j.name)
print(json.dump(j))

Revision: 788 by @kyork in #marvin-dev 2 years agoSlack Archive

{lua} local query = args
if query == "" then query = "Newark, CA" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?q={" .. bot.uriencode(query).. "}&APPID=" .. fmap.api_keys.openweathermap)
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data,def)
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return def end
 local ok, gj = pcall(function() return r2:json() end)
 if not ok then return def end
 if gj.status ~= "OK" then return def end
 if #gj.predictions == 0 then return def end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j, j.name)
print(json.dump(j))

Revision: 787 by @kyork in #marvin-dev 2 years agoSlack Archive

{lua} local query = args
if query == "" then query = "Newark, CA" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?q={" .. bot.uriencode(query).. "}&APPID=" .. fmap.api_keys.openweathermap)
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data)
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return query end
 local ok, gj = pcall(function() return r2:json() end)
 if not ok then return query end
 if gj.status ~= "OK" then return query end
 if #gj.predictions == 0 then return query end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j)
print(json.dump(j))

Revision: 784 by @kyork in #marvin-dev 2 years agoSlack Archive

{lua} local query = args
if query == "" then query = "Newark, CA" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?q={" .. bot.uriencode(query).. "}&APPID=e64a1c841d59ea94cfe01208b91ea7dc")
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data)
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return query end
 local ok, gj = pcall(function() return r2:json() end)
 if not ok then return query end
 if gj.status ~= "OK" then return query end
 if #gj.predictions == 0 then return query end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j)
print(json.dump(j))

Revision: 783 by @kyork in #marvin-dev 2 years agoSlack Archive

{lua} local query = args
if query == "" then query = "Ardenwood,Fremont" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?q={" .. bot.uriencode(query).. "}&APPID=e64a1c841d59ea94cfe01208b91ea7dc")
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data)
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return query end
 local ok, gj = pcall(function() return r2:json() end)
 if not ok then return query end
 if gj.status ~= "OK" then return query end
 if #gj.predictions == 0 then return query end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j)
print(json.dump(j))

Revision: 782 by @kyork in #marvin-dev 2 years agoSlack Archive

{lua} local query = args
if query == "" then query = "Ardenwood,Fremont" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?q={" .. bot.uriencode(query).. "}&APPID=e64a1c841d59ea94cfe01208b91ea7dc")
if err ~= nil then error(err) end
local j = resp:json()
function get_place_name(data)
  local r2, err = requests.get("https://maps.googleapis.com/maps/api/place/autocomplete/json?types=(regions)&radius=1000&location=" .. bot.uriencode(data.coord.lon .. "," .. data.coord.lat) .. "&input=" .. bot.uriencode(query) .. "&key=" .. fmap.api_keys.googleapi)
 if err ~= nil then return query end
 local ok, gj = pcall(r2:json())
 if not ok then return query end
 if gj.status ~= "OK" then return query end
 if #gj.predictions == 0 then return query end
 return gj.predictions[1].description
end
j.marvin_name = get_place_name(j)
print(json.dump(j))

Revision: 775 by @kyork in #marvin-dev 2 years agoSlack Archive

{lua} local query = args
if query == "" then query = "Ardenwood,Fremont" end
local resp, err = requests.get("http://api.openweathermap.org/data/2.5/weather?q={" .. bot.uriencode(query).. "}&APPID=e64a1c841d59ea94cfe01208b91ea7dc")
if err ~= nil then error(err) end
local j = resp:json()
print(json.dump(j))