Compare commits

..

No commits in common. "d26f5d3ba66ca7dbbe7a6af3ae99f99bfaef1b03" and "423831a4019ac38b25824e3f6363d487d0200257" have entirely different histories.

4 changed files with 6 additions and 122 deletions

View file

@ -1,5 +1,4 @@
import os import os
import strutils
import parsetoml import parsetoml
import tool import tool
@ -13,8 +12,6 @@ type
prepend*: bool prepend*: bool
to_stdout*: bool to_stdout*: bool
screenshot_tool*: ScreenshotTool screenshot_tool*: ScreenshotTool
unsplash_key*: string
bg_dir*: string
let config_dir* = getHomeDir() & ".config/wm_tools/" let config_dir* = getHomeDir() & ".config/wm_tools/"
let config_file* = config_dir & "config.toml" let config_file* = config_dir & "config.toml"
@ -47,10 +44,6 @@ proc newConfig*(): Config =
cfg.max_lines = toml["max_lines"].getInt cfg.max_lines = toml["max_lines"].getInt
if toml.hasKey("screenshot_tool"): if toml.hasKey("screenshot_tool"):
cfg.screenshot_tool = toml["screenshot_tool"].getStr.toScreenshotTool cfg.screenshot_tool = toml["screenshot_tool"].getStr.toScreenshotTool
if toml.hasKey("unsplash_key"):
cfg.unsplash_key = toml["unsplash_key"].getStr
if toml.hasKey("bg_dir"):
cfg.bg_dir = toml["bg_dir"].getStr.replace("$HOME",getHomeDir())
except: except:
echo "Error with Config File:" echo "Error with Config File:"
echo getCurrentExceptionMsg() echo getCurrentExceptionMsg()

View file

@ -1,6 +0,0 @@
type
WPArgs* = object
query*: string
last*: bool
from_unsplash*: bool

View file

@ -8,7 +8,6 @@ import model/volume
import model/brightness import model/brightness
import model/screenshot import model/screenshot
import model/tides import model/tides
import model/wallpapurr
proc parseArgs*() = proc parseArgs*() =
let params = commandLineParams() let params = commandLineParams()
@ -184,23 +183,17 @@ proc parseTideurrlArgs*(): TideList =
quit(1) quit(1)
return t return t
proc parseWallpapurrArgs*(): WPArgs = proc parseWallpapurrArgs*(): string =
var args = WPArgs() var query = "devon coast"
let params = commandLineParams() let params = commandLineParams()
var p = newParser: var p = newParser:
help("Args for wallpapurr") help("Args for wallpapurr")
arg("wallpapurr",help="can only ever be 'wallpapurr' as you won't have gotten this far otherwise") arg("wallpapurr",help="can only ever be 'wallpapurr' as you won't have gotten this far otherwise")
option("-q","--query",help="query name") option("-q","--query",help="query name")
flag("-l","--last",help="last image")
flag("-n","--unsplash",help="get from unsplash")
try: try:
var opts = p.parse(params) var opts = p.parse(params)
if opts.query != "": if opts.query != "":
args.query = opts.query query = opts.query
if opts.last:
args.last = true
if opts.unsplash:
args.from_unsplash = true
except ShortCircuit as err: except ShortCircuit as err:
if err.flag == "argparse_help": if err.flag == "argparse_help":
echo err.help echo err.help
@ -208,4 +201,4 @@ proc parseWallpapurrArgs*(): WPArgs =
except UsageError: except UsageError:
stderr.writeLine getCurrentExceptionMsg() stderr.writeLine getCurrentExceptionMsg()
quit(1) quit(1)
return args return query

View file

@ -1,108 +1,12 @@
import os
import osproc
import strutils
import sequtils
import random
import ../common import ../common
import ../parser import ../parser
import ../output import ../output
var UNSPLASH_KEY = ""
var BG_DIR = "/tmp/"
var LAST_FILE = ""
var LAST = ""
var GET_FROM_UNSPLASH = false
const UNSPLASH_URL = "https://api.unsplash.com/photos/random?query=$QUERY&orientation=landscape"
type
Note* = object
urgency*: Urgency
title*: string
content*: string
timeout*: int
Urgency* = enum
Normal = "normal"
Low = "low"
Urgent = "urgent"
Critical = "critical"
proc newNote*(): Note =
return Note(urgency: Normal, title: "Notification", content: "Hello, I am a notifications", timeout: 2000)
proc `$`*(n: Note): string =
let str = "notify-send -u $U $T $C -t $N"
.replace("$U", $n.urgency)
.replace("$T", n.title.escape)
.replace("$C", n.content.escape)
.replace("$N", $n.timeout)
return str
proc send(n: Note) =
discard execCmdEx($n)
proc getFromUnsplash(q: var string): string =
createDir(BG_DIR & "/unsplash")
echo "Getting from Unsplash"
q = q.replace(" ","%20")
let uri = UNSPLASH_URL.replace("$QUERY",q)
proc getFiles(dir: string): seq[string] =
var files: seq[string] = @[]
for file in walkDir(dir):
if file.path.endsWith(".jpg"): files.add(file.path)
elif file.kind == pcDir:
files = files.concat(getFiles(file.path))
return files
proc getLast() =
LAST = readFile(LAST_FILE).strip()
proc getImageFromDir(): string =
echo "Getting Random file from " & BG_DIR
var img_files = getFiles(BG_DIR).filter(proc(f: string): bool = f != LAST)
img_files.shuffle()
let img_file = img_files[0]
echo "Found : ", img_file
proc setLast() =
var n: Note = newNote()
n.title = "Setting Background to Last"
n.content = LAST
n.send()
let feh = "feh --bg-fill " & LAST.escape
echo feh
discard execCmdEx(feh)
proc getDesign(): Info = proc getDesign(): Info =
var data = newInfo("Wallpapurr") var data = newInfo("Wallpapurr")
return data return data
proc queryPrompt(): string =
let data = getDesign()
let output = data.outputData()
return output
proc go*() = proc go*() =
var args = parseWallpapurrArgs() var mytides = parseWallpapurrArgs()
UNSPLASH_KEY = myConfig.unsplash_key echo mytides
BG_DIR = myConfig.bg_dir
LAST_FILE = BG_DIR & "/last.txt"
getLast()
var img = ""
if args.query != "" or args.from_unsplash:
if args.query == "":
args.query = queryPrompt()
echo "Query: ", args.query
img = getFromUnsplash(args.query)
elif args.last:
setLast()
else:
img = getImageFromDir()
echo img