store api keys and client settings in secrets.lua

This commit is contained in:
Pavel Makhov 2019-01-25 22:26:16 -05:00
parent cdd3d9450b
commit 15e6d0fcd9
3 changed files with 13 additions and 10 deletions

View File

@ -1,15 +1,17 @@
------------------------------------------------- -------------------------------------------------
-- Allows to store API keys in one place -- Allows to store client specific settings in one place
-- --
-- @author Pavel Makhov -- @author Pavel Makhov
-- @copyright 2018 Pavel Makhov -- @copyright 2019 Pavel Makhov
-------------------------------------------- --------------------------------------------
local secrets = { local secrets = {
-- Yandex.Translate API key - https://tech.yandex.com/translate/ -- Yandex.Translate API key - https://tech.yandex.com/translate/
translate_widget_api_key = '<API_KEY>', translate_widget_api_key = 'API_KEY',
-- OpenWeatherMap API key - https://openweathermap.org/appid -- OpenWeatherMap API key - https://openweathermap.org/appid
weather_widget_api_key = '<API_KEY>' weather_widget_api_key = 'API_KEY',
weather_widget_city = 'Montreal,ca'
} }
return secrets return secrets

View File

@ -14,8 +14,8 @@ local naughty = require("naughty")
local wibox = require("wibox") local wibox = require("wibox")
local gears = require("gears") local gears = require("gears")
local gfs = require("gears.filesystem") local gfs = require("gears.filesystem")
local secrets = require("awesome-wm-widgets.secrets")
local API_KEY = '<your api key>'
local BASE_URL = 'https://translate.yandex.net/api/v1.5/tr.json/translate' local BASE_URL = 'https://translate.yandex.net/api/v1.5/tr.json/translate'
local ICON = '/usr/share/icons/Papirus-Dark/48x48/apps/gnome-translate.svg' local ICON = '/usr/share/icons/Papirus-Dark/48x48/apps/gnome-translate.svg'
@ -88,7 +88,7 @@ w:setup {
--- Main function - takes the user input and shows the widget with translation --- Main function - takes the user input and shows the widget with translation
-- @param request_string - user input (dog enfr) -- @param request_string - user input (dog enfr)
local function translate(to_translate, lang) local function translate(to_translate, lang)
local urll = BASE_URL .. '?lang=' .. lang .. '&text=' .. urlencode(to_translate) .. '&key=' .. API_KEY local urll = BASE_URL .. '?lang=' .. lang .. '&text=' .. urlencode(to_translate) .. '&key=' .. secrets.translate_widget_api_key
local resp_json, code = https.request(urll) local resp_json, code = https.request(urll)
if (code == 200 and resp_json ~= nil) then if (code == 200 and resp_json ~= nil) then

View File

@ -10,9 +10,10 @@ local http = require("socket.http")
local json = require("json") local json = require("json")
local naughty = require("naughty") local naughty = require("naughty")
local wibox = require("wibox") local wibox = require("wibox")
local gears = require("gears")
local secrets = require("awesome-wm-widgets.secrets")
local city = os.getenv("AWW_WEATHER_CITY") or "Montreal,ca"
local open_map_key = os.getenv("AWW_WEATHER_API_KEY") or 'c3d7320b359da4e48c2d682a04076576'
local path_to_icons = "/usr/share/icons/Arc/status/symbolic/" local path_to_icons = "/usr/share/icons/Arc/status/symbolic/"
local icon_widget = wibox.widget { local icon_widget = wibox.widget {
@ -93,11 +94,11 @@ function to_direction(degrees)
return directions[math.floor((degrees % 360) / 22.5) + 1] return directions[math.floor((degrees % 360) / 22.5) + 1]
end end
local weather_timer = timer({ timeout = 60 }) local weather_timer = gears.timer({ timeout = 60 })
local resp local resp
weather_timer:connect_signal("timeout", function () weather_timer:connect_signal("timeout", function ()
local resp_json = http.request("https://api.openweathermap.org/data/2.5/weather?q=" .. city .."&appid=" .. open_map_key) local resp_json = http.request("https://api.openweathermap.org/data/2.5/weather?q=" .. secrets.weather_widget_city .."&appid=" .. secrets.weather_widget_api_key)
if (resp_json ~= nil) then if (resp_json ~= nil) then
resp = json.decode(resp_json) resp = json.decode(resp_json)
icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon] icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]