Compare commits
2 commits
423831a401
...
d26f5d3ba6
Author | SHA1 | Date | |
---|---|---|---|
d26f5d3ba6 | |||
16cf06d437 |
4 changed files with 123 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import strutils
|
||||
import parsetoml
|
||||
|
||||
import tool
|
||||
|
@ -12,6 +13,8 @@ type
|
|||
prepend*: bool
|
||||
to_stdout*: bool
|
||||
screenshot_tool*: ScreenshotTool
|
||||
unsplash_key*: string
|
||||
bg_dir*: string
|
||||
|
||||
let config_dir* = getHomeDir() & ".config/wm_tools/"
|
||||
let config_file* = config_dir & "config.toml"
|
||||
|
@ -44,6 +47,10 @@ proc newConfig*(): Config =
|
|||
cfg.max_lines = toml["max_lines"].getInt
|
||||
if toml.hasKey("screenshot_tool"):
|
||||
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:
|
||||
echo "Error with Config File:"
|
||||
echo getCurrentExceptionMsg()
|
||||
|
|
6
src/model/wallpapurr.nim
Normal file
6
src/model/wallpapurr.nim
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
type
|
||||
WPArgs* = object
|
||||
query*: string
|
||||
last*: bool
|
||||
from_unsplash*: bool
|
|
@ -8,6 +8,7 @@ import model/volume
|
|||
import model/brightness
|
||||
import model/screenshot
|
||||
import model/tides
|
||||
import model/wallpapurr
|
||||
|
||||
proc parseArgs*() =
|
||||
let params = commandLineParams()
|
||||
|
@ -183,17 +184,23 @@ proc parseTideurrlArgs*(): TideList =
|
|||
quit(1)
|
||||
return t
|
||||
|
||||
proc parseWallpapurrArgs*(): string =
|
||||
var query = "devon coast"
|
||||
proc parseWallpapurrArgs*(): WPArgs =
|
||||
var args = WPArgs()
|
||||
let params = commandLineParams()
|
||||
var p = newParser:
|
||||
help("Args for wallpapurr")
|
||||
arg("wallpapurr",help="can only ever be 'wallpapurr' as you won't have gotten this far otherwise")
|
||||
option("-q","--query",help="query name")
|
||||
flag("-l","--last",help="last image")
|
||||
flag("-n","--unsplash",help="get from unsplash")
|
||||
try:
|
||||
var opts = p.parse(params)
|
||||
if opts.query != "":
|
||||
query = opts.query
|
||||
args.query = opts.query
|
||||
if opts.last:
|
||||
args.last = true
|
||||
if opts.unsplash:
|
||||
args.from_unsplash = true
|
||||
except ShortCircuit as err:
|
||||
if err.flag == "argparse_help":
|
||||
echo err.help
|
||||
|
@ -201,4 +208,4 @@ proc parseWallpapurrArgs*(): string =
|
|||
except UsageError:
|
||||
stderr.writeLine getCurrentExceptionMsg()
|
||||
quit(1)
|
||||
return query
|
||||
return args
|
||||
|
|
|
@ -1,12 +1,108 @@
|
|||
import os
|
||||
import osproc
|
||||
import strutils
|
||||
import sequtils
|
||||
import random
|
||||
|
||||
import ../common
|
||||
import ../parser
|
||||
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 =
|
||||
var data = newInfo("Wallpapurr")
|
||||
return data
|
||||
|
||||
proc go*() =
|
||||
var mytides = parseWallpapurrArgs()
|
||||
echo mytides
|
||||
proc queryPrompt(): string =
|
||||
let data = getDesign()
|
||||
let output = data.outputData()
|
||||
return output
|
||||
|
||||
proc go*() =
|
||||
var args = parseWallpapurrArgs()
|
||||
UNSPLASH_KEY = myConfig.unsplash_key
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue