-- ###################################################################################################################################
-- This configuration file was created by Matt Grotke (mgrotke@gmail.com) for the "mgconky Conky Theme" project: https://github.com/mgrotke/mgconky
-- This file is in the public domain.
-- ---------------------------------------------------------------------------------------------------------------------------------
-- TO RUN THIS CONKY CONFIG, YOU CAN TYPE THE FOLLOWING IN A TERMINAL:
--     conky -c ~/.conky/mgconky/conf
--
-- TO STOP CONKY, YOU CAN TYPE THE FOLLOWING IN A TERMINAL:
--    killall conky
--
-- TO HAVE THIS CONKY RUN EVERY TIME AT BOOT, GO INTO "STARTUP SOFTWARE" APP AND ADD THE FOLLOWING COMMAND WITH A DELAY OF 10 SECONDS:
--     conky -p 10 -c /home/<username>/.conky/mgconky/conf
--     NOTE:  It seems you must actually use the full path (/home/<username>) as the shortcut (~/) does not work.
--
-- !!!IMPORTANT!!! THE FOLLOWING ARE REQUIREMENTS FOR THIS SCRIPT TO WORK PROPERLY:
--     (1) DEPENDENCIES.
--         Install the following software, if not already installed:
--         "Conky"                 sudo apt-get install conky-all          (or use software manager)
--         "Jq"                    sudo apt-get install jq                 (or use software manager)
--         "Curl"                  sudo apt-get install curl               (or use software manager)
--         "Wget"                  sudo apt-get install wget               (or use software manager)
--     (2) FONTS.
--         Install the following custom fonts:
--         "Neuropolitical"        Place .ttf file in ~/.fonts/            https://www.dafont.com/font-comment.php?file=neuropolitical
--         "StyleBats"             Place .ttf file in ~/.fonts/            https://www.dafont.com/search.php?q=StyleBats
--     (3) SCRIPTS.
--         Set the following included script(s) as executable:
--         chmod +x ~/.conky/mgconky/weather/get_weather.sh
--         chmod +x ~/.conky/mgconky/weather/parse_weather.sh
--         chmod +x ~/.conky/mgconky/weather/parse_forecast.sh
--         chmod +x ~/.conky/mgconky/weather/parse_forecast.sh
--         chmod +x ~/.conky/mgconky/stocks/get_stocks.py                  (Requires python3, which is usually pre-installed on your OS)
--     (4) WEATHER.
--         Make a free account at https://openweathermap.org/
--         Write down your API key, which is found on the "API keys" tab after you log in.  (https://home.openweathermap.org/api_key
--         Find your city's location ID by entering your CITY NAME in the search box and select your city from the search results.
--         Your location ID will be the number in the URL (for example:  https://openweathermap.org/city/5128581)
--         In the config below, complete template0 through template3.
--     (5) STOCKS.
--         Unfortunately the days of using the Yahoo Finance API are over.  It has been shut down.  There are two APIs to choose from.
--         Alpha Vantage and Finnhub.  You will need an API key to use either.  Both offer FREE services, but with restrictions.
--         Alpha Vantage only allows 25 requests per day (!!!) for free.  Finnhub allows 60 requests per minute for free!
--         Both services are available here.  With Alpha Vantage, we must set the interval to 7200 seconds.  That means your stock prices
--         will only update every 2 hours.  It makes 1 request per stock, so only include 1 or 2 stocks if you are using free Alpha
--         Vantage.  If you go With FinnHub, you cannot get historical prices at all, unless you have a paid plan, but you CAN add many
--         stocks, and you can update your stocks much more frequently.  Complete template4 through template7 in the config below.
-- ###################################################################################################################################

conky.config = {

    -- Window and drawing properties
    alignment = "top_right",
    minimum_width = 225,
    maximum_width = 225,
    gap_x = 15,
    gap_y = 15,
    background = false,
    own_window = true,
    own_window_transparent = true,
    own_window_hints = "undecorated,below,sticky,skip_taskbar,skip_pager",
    own_window_type = "normal",
    double_buffer = true,
    draw_shades = false,
    draw_outline = false,
    draw_borders = false,
    draw_graph_borders = true,
    no_buffers = true,
    imlib_cache_size = 0,
    cpu_avg_samples = 2,
    update_interval = 1.5,
    total_run_times = 0,

    -- Define fonts
    use_xft = true,
    xftalpha = 0.9,
    override_utf8_locale = true, -- Force UTF8? Requires XFT (see above)... will display degree symbol, instead of Â°, etc.
    short_units = true,
    uppercase = false,

    -- Define Colors
    default_color = "#FFFFFF", -- white
    default_shade_color = "#000000", -- black
    default_outline_color = "#00FF00", -- green
    color0 = "#FFA500", -- Titles (orange)
    color1 = "#708090", -- Horizontal lines (slategrey)
    color2 = "#FFFFFF", -- Not used (white)
    color3 = "#00FF00", -- Values (lime)
    color4 = "#FFFF00", -- Important (yellow)
    color5 = "#00FF00", -- Bar graphs (lime)
    color6 = "#1E90FF", -- Good values (blue)
    color7 = "#FF0000", -- Bad values (red)

    -- Weather variables
    template0 = "YOUR_OPENWEATHERMAP_API_KEY_HERE", -- OpenWeatherMap API key (https://home.openweathermap.org/api_keys)
    template1 = "YOUR_OPENWEATHERMAP_CITY_ID_HERE", -- OpenWeatherMap City ID (the number in the URL of your city, for example:  https://openweathermap.org/city/5128581)
    template2 = "imperial", -- Temp unit ("default" for Kelvin, "metric" for Celsius, "imperial" for Fahrenheit)
    template3 = "", -- Locale (e.g., "es_ES.UTF-8") # Leave empty for default

    -- Stock variables
    template4 = "YOUR_FINNHUB_API_KEY_HERE", -- FinnHub API key (https://finnhub.io/)
    template5 = "YOUR_ALPHAVANTAGE_API_KEY_HERE", -- Alpha Vantage API key (https://www.alphavantage.co/)
    template6 = "goog,amzn,aapl,msft,meta,tsla,avgo,tsm,brk.a,pg,nvda", -- Stock symbols for FinnHub (comma separated, no spaces, i.e. goog,amzn,aapl)
    template7 = "nvda", -- Stock symbols for Alpha Vantage (keep to a minimum unless you have a paid API key)

    -- Load Lua script(s) -- If multiple files, separate each path with a space. They should all be loaded on a single lua_load command.
    -- lua_load = "~/.conky/mgconky/script1.lua ~/.conky/mgconky/script2.lua",
    lua_load = "~/.conky/mgconky/devices/get_device_info.lua",
}

conky.text = [[
#--------------------------
# Computer Info
#--------------------------
# ***** Linux Mint Logo and Version *****
${image ~/.conky/mgconky/mint_logo.png -s 35x35 -p 0,0}\
${voffset 0}${goto 50}${font Neuropolitical:pixelsize=12}${color0}${execi 100000 lsb_release -sd || cat /etc/*release}${color}${font Courier:size=9}
# ***** Computer Name *****
${voffset 0}${goto 50}${font Neuropolitical:size=10}${nodename}${font Courier:size=9}
# ***** Kernel Version *****
${voffset 8}Kernel: ${color3}${alignr}${sysname} ${kernel}${color}
# ***** Up Time *****
${voffset 2}Uptime: ${color3}${alignr}${uptime_short}${color}
# ***** Temperatures *****
${voffset 2}\
CPU:  ${color4}${hwmon 0 temp 1}°C${color}${goto 100}${alignr}\
GPU:  ${color4}${hwmon 1 temp 1}°C|${nvidia temp}°C${color}
# -------------------- NOTE ABOUT TEMPERATURES --------------------
# YOU WILL NEED TO FIDDLE WITH THE HWMON NUMBERS TO GET THE RIGHT
# TEMP FOR YOUR PC. YOU CAN BROWSE THE /sys/class/hwmon/ DIRECTORY
# TO SEE ALL THE OPTIONS.  THE TEMPS ARE IN MILLIDEGREES C IN
# THE FILES CALLED temp1_input, temp3_input ETC.
# NVIDIA CAN USE ${nvidia temp}.  THERE IS NO ALTERNATIVE FOR AMD.
# INSTALL lm-sensors, amdgpu-monitor, or radeontop AND QUERY THE
# TEMP THAT WAY.
# -----------------------------------------------------------------
# ***** CPU Make/Model *****
${voffset 6}${alignc}${color3}${lua_parse conky_get_cpu_info}
# ***** GPU Make/Model *****
${voffset 0}${alignc}${color3}${lua_parse conky_get_gpu_info}

#--------------------------
# Weather
#--------------------------
# ***** Download weather data and position icons *****
${execi 300 ~/.conky/mgconky/weather/get_weather.sh ${template0} ${template1} ${template2} ${template3}}\
${execi 300 cp -f ~/.conky/mgconky/weather/lime64/$(~/.conky/mgconky/weather/parse_weather.sh 'iconid').png ~/.cache/mgconky/weather0.png}${image ~/.cache/mgconky/weather0.png -p 40,178 -s 64x64}\
${execi 300 cp -f ~/.conky/mgconky/weather/lime32/$(~/.conky/mgconky/weather/parse_forecast.sh 'first' '.weather[0].id' '1').png ~/.cache/mgconky/weather1.png}${image ~/.cache/mgconky/weather1.png -p 20,262 -s 32x32}\
${execi 300 cp -f ~/.conky/mgconky/weather/lime32/$(~/.conky/mgconky/weather/parse_forecast.sh 'first' '.weather[0].id' '2').png ~/.cache/mgconky/weather2.png}${image ~/.cache/mgconky/weather2.png -p 96,262 -s 32x32}\
${execi 300 cp -f ~/.conky/mgconky/weather/lime32/$(~/.conky/mgconky/weather/parse_forecast.sh 'first' '.weather[0].id' '3').png ~/.cache/mgconky/weather3.png}${image ~/.cache/mgconky/weather3.png -p 175,262 -s 32x32}
# ***** Today's date *****
${voffset -15}${color0}${alignc}${font Neuropolitical:size=15}${execi 300 ~/.conky/mgconky/weather/parse_weather.sh 'location'}${font Courier:size=9}${color}
${voffset 0}${color0}${alignc}${font Neuropolitical:size=10}${execi 300 LANG=${template3} LC_TIME=${template3} date +'%^a, %e %^B'}${font Courier:size=9}${color}
# ***** Temperature right now *****
${voffset 7}${alignc -40}${color3}${font Courier:size=20:bold}${execi 300 ~/.conky/mgconky/weather/parse_weather.sh 'temperature'}${if_match "${template2}" == "metric"}°C${else}${if_match "${template2}" == "imperial"}°F${else}${if_match "${template2}" == "default"}K${endif}${endif}${endif}${font Courier:size=9}${color}
# ***** Today's high/low temps *****
${voffset 5}${alignc -40}${color3}${execi 300 ~/.conky/mgconky/weather/parse_forecast.sh 'min' '.main.temp_min' '0'}${color}\
/${color3}${execi 300 ~/.conky/mgconky/weather/parse_forecast.sh 'max' '.main.temp_max' '0'}\
${if_match "${template2}" == "metric"}°C${else}${if_match "${template2}" == "imperial"}°F${else}${if_match "${template2}" == "default"}K${endif}${endif}${endif}${color}
# ***** Description of weather right now *****
#${voffset 0}${alignc}${color3}${execi 300 ~/.conky/mgconky/weather/parse_weather.sh 'description'}${color}
# ***** Forecast day labels (MON, TUES, WED, etc) *****
${voffset 15}${color0}${font Neuropolitical:size=10}${alignc 77}${execi 300 LANG=${template3} LC_TIME=${template3} date -d +1day +%^a}${font Courier:size=9}${color}
${voffset -18}${color0}${font Neuropolitical:size=10}${alignc}${execi 300 LANG=${template3} LC_TIME=${template3} date -d +2day +%^a}${font Courier:size=9}${color}
${voffset -18}${color0}${font Neuropolitical:size=10}${alignc -77}${execi 300 LANG=${template3} LC_TIME=${template3} date -d +3day +%^a}${font Courier:size=9}${color}
# ***** Forecast high/low temps *****
${voffset 32}${alignc 77}${color3}${execi 300 ~/.conky/mgconky/weather/parse_forecast.sh 'min' '.main.temp_min' '1'}${color}/${color3}${execi 300 ~/.conky/mgconky/weather/parse_forecast.sh 'max' '.main.temp_max' '1'}${if_match "${template2}" == "metric"}°C${else}${if_match "${template2}" == "imperial"}°F${else}${if_match "${template2}" == "default"}K${endif}${endif}${endif}${color}
${voffset -13}${alignc}${color3}${execi 300 ~/.conky/mgconky/weather/parse_forecast.sh 'min' '.main.temp_min' '2'}${color}/${color3}${execi 300 ~/.conky/mgconky/weather/parse_forecast.sh 'max' '.main.temp_max' '2'}${if_match "${template2}" == "metric"}°C${else}${if_match "${template2}" == "imperial"}°F${else}${if_match "${template2}" == "default"}K${endif}${endif}${endif}${color}
${voffset -13}${alignc -77}${color3}${execi 300 ~/.conky/mgconky/weather/parse_forecast.sh 'min' '.main.temp_min' '3'}${color}/${color3}${execi 300 ~/.conky/mgconky/weather/parse_forecast.sh 'max' '.main.temp_max' '3'}${if_match "${template2}" == "metric"}°C${else}${if_match "${template2}" == "imperial"}°F${else}${if_match "${template2}" == "default"}K${endif}${endif}${endif}${color}

#--------------------------
# Stocks
#--------------------------
${voffset 6}${color0}${font Neuropolitical:size=8:bold}STOCKS ${color1}${hr 2}${color}${font Courier:size=9}
# ***** FinnHub API *****
${if_match "${template4}" != "YOUR_FINNHUB_API_KEY_HERE"}
${voffset -6}${execpi 60 $HOME/.conky/mgconky/stocks/get_stocks_finnhub.py --api_key ${template4} --symbols ${template6} --range_in_days 0 --price_dec_places 0 --percent_dec_places 1}
${endif}
# ***** Alpha Vantage API *****
${if_match "${template5}" != "YOUR_ALPHAVANTAGE_API_KEY_HERE"}
${voffset -12}${execpi 7200 $HOME/.conky/mgconky/stocks/get_stocks_alphavantage.py --api_key ${template5} --symbols ${template7} --range_in_days 30 --price_dec_places 0 --percent_dec_places 1}
${endif}
#
#--------------------------
# Memory
#--------------------------
${voffset 0}${color0}${font Neuropolitical:size=8:bold}MEMORY ${color1}${hr 2}${color}${font Courier:size=9}
# ***** System memory *****
${voffset 4}System:${alignr}${lua_parse conky_get_memory_usage sys}${color}
${voffset -2}${color5}${membar}${color}
# ***** Swap memory *****
${if_match "${lua conky_check_swap_status}" == "swapenabled"}\
${voffset 4}Swap:${alignr}${lua_parse conky_get_memory_usage swap}${color}
${voffset -2}${color5}${swapbar}${color}\
${endif}
#--------------------------
# Drives and Volumes
#--------------------------
${voffset 6}${lua_parse conky_get_drives_and_volumes}
#
#----------------------
# Top Processes
#----------------------
${voffset -6}${color0}${font Neuropolitical:size=8:bold}TOP PROCESSES ${color1}${hr 2}${color}${font Courier:size=9}
# ***** By memory usage *****
${voffset 6}By Memory Usage${goto 142}PID${alignr}RAM
${voffset 0}${font StyleBats:size=10}h${font Courier:size=9}${voffset -1}${color3}${offset 5}${top_mem name 1}${goto 140}${top_mem pid 1}${alignr}${top_mem mem_res 1}${color}
${voffset 0}${font StyleBats:size=10}h${font Courier:size=9}${voffset -1}${color3}${offset 5}${top_mem name 2}${goto 140}${top_mem pid 2}${alignr}${top_mem mem_res 2}${color}
${voffset 0}${font StyleBats:size=10}h${font Courier:size=9}${voffset -1}${color3}${offset 5}${top_mem name 3}${goto 140}${top_mem pid 3}${alignr}${top_mem mem_res 3}${color}
${voffset 0}${font StyleBats:size=10}h${font Courier:size=9}${voffset -1}${color3}${offset 5}${top_mem name 4}${goto 140}${top_mem pid 4}${alignr}${top_mem mem_res 4}${color}
${voffset 0}${font StyleBats:size=10}h${font Courier:size=9}${voffset -1}${color3}${offset 5}${top_mem name 5}${goto 140}${top_mem pid 5}${alignr}${top_mem mem_res 5}${color}
# ***** By CPU usage *****
${voffset 6}By CPU Usage${goto 142}PID${alignr}CPU
${voffset 0}${font StyleBats:size=10}h${font Courier:size=9}${voffset -1}${color3}${offset 5}${top name 1}${goto 140}${top pid 1}${alignr}${top cpu 1}%${color}
${voffset 0}${font StyleBats:size=10}h${font Courier:size=9}${voffset -1}${color3}${offset 5}${top name 2}${goto 140}${top pid 2}${alignr}${top cpu 2}%${color}
${voffset 0}${font StyleBats:size=10}h${font Courier:size=9}${voffset -1}${color3}${offset 5}${top name 3}${goto 140}${top pid 3}${alignr}${top cpu 3}%${color}
${voffset 0}${font StyleBats:size=10}h${font Courier:size=9}${voffset -1}${color3}${offset 5}${top name 4}${goto 140}${top pid 4}${alignr}${top cpu 4}%${color}
${voffset 0}${font StyleBats:size=10}h${font Courier:size=9}${voffset -1}${color3}${offset 5}${top name 5}${goto 140}${top pid 5}${alignr}${top cpu 5}%${color}

#--------------------
# Network -- Find name of ethernet device (e.g. "enp34s0") by typing "ip a" in terminal.
#--------------------
${voffset 6}${color0}${font Neuropolitical:size=8:bold}NETWORK ${color1}${hr 2}${color}${font Courier:size=9}
# ***** IP addresses *****
${voffset 6}Interface Device:${goto 140}${color3}${gw_iface}${color}
${voffset 0}Internal IP:${goto 140}${color3}${addr ${gw_iface}}${color}
${voffset 0}External IP:${goto 140}${color3}${execi 1800 wget -q -O - checkip.dyndns.org | sed -e 's/[^[:digit:]\|.]//g'}${color}
# ***** VPN status *****
${voffset 6}${alignc}${color4}VPN Status: ${lua_parse conky_get_vpn_status}
${voffset 6}DL: ${color3}${downspeed ${gw_iface}}/s${color}${goto 140}UL: ${color3}${upspeed ${gw_iface}}/s${color}
${voffset -2}${color5}${downspeedgraph ${gw_iface} 25,90 000000 ff0000}${color}${alignr}${color5}${upspeedgraph ${gw_iface} 25,90 000000 00ffff}${color}
${voffset -6}Total: ${color3}${totaldown ${gw_iface}}${color}${goto 140}Total: ${color3}${totalup ${gw_iface}}${color}

#--------------------
# Connections - netstat shows number of connections from your computer and application/PID making it. Kill spyware!
#--------------------
${voffset 6}${color0}${font Neuropolitical:size=8:bold}CONNECTIONS ${color1}${hr 2}${color}${font Courier:size=9}
#${voffset 6}Num. connections / PID / Process
#${voffset 2}${color3}${execi 30 netstat -ept | grep ESTAB | awk '{print $9}' | cut -d: -f1 | sort | uniq -c | sort -nr}${color}
${voffset 2}${lua_parse conky_get_connections}
]]

