diff options
| author | Pavel Makhov <pmakhov@touchtunes.com> | 2019-01-25 22:26:16 -0500 | 
|---|---|---|
| committer | Pavel Makhov <pmakhov@touchtunes.com> | 2019-01-25 22:26:16 -0500 | 
| commit | 15e6d0fcd96acd02250fc6a5bff6590c118cb8a1 (patch) | |
| tree | a51b68f53b0dc24c006a6609047e22e654dc20f4 | |
| parent | cdd3d9450bd5efc9f1be0392e62131e2d6c38ac2 (diff) | |
store api keys and client settings in secrets.lua
| -rw-r--r-- | secrets.lua | 10 | ||||
| -rw-r--r-- | translate-widget/translate.lua | 4 | ||||
| -rw-r--r-- | weather-widget/weather.lua | 9 | 
3 files changed, 13 insertions, 10 deletions
diff --git a/secrets.lua b/secrets.lua index 8ce0cb0..98051c7 100644 --- a/secrets.lua +++ b/secrets.lua @@ -1,15 +1,17 @@  ------------------------------------------------- --- Allows to store API keys in one place +-- Allows to store client specific settings in one place  --  -- @author Pavel Makhov --- @copyright 2018 Pavel Makhov +-- @copyright 2019 Pavel Makhov  --------------------------------------------  local secrets = {      -- 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 -    weather_widget_api_key = '<API_KEY>' +    weather_widget_api_key = 'API_KEY', +    weather_widget_city = 'Montreal,ca'  }  return secrets diff --git a/translate-widget/translate.lua b/translate-widget/translate.lua index fe242b4..2b64bf8 100644 --- a/translate-widget/translate.lua +++ b/translate-widget/translate.lua @@ -14,8 +14,8 @@ local naughty = require("naughty")  local wibox = require("wibox")  local gears = require("gears")  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 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  -- @param request_string - user input (dog enfr)  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)      if (code == 200 and resp_json ~= nil) then diff --git a/weather-widget/weather.lua b/weather-widget/weather.lua index 88d3658..973a776 100644 --- a/weather-widget/weather.lua +++ b/weather-widget/weather.lua @@ -10,9 +10,10 @@ local http = require("socket.http")  local json = require("json")  local naughty = require("naughty")  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 icon_widget = wibox.widget { @@ -93,11 +94,11 @@ function to_direction(degrees)      return directions[math.floor((degrees % 360) / 22.5) + 1]  end -local weather_timer = timer({ timeout = 60 }) +local weather_timer = gears.timer({ timeout = 60 })  local resp  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          resp = json.decode(resp_json)          icon_widget.image = path_to_icons .. icon_map[resp.weather[1].icon]  | 
