Compare commits
No commits in common. "d26f5d3ba66ca7dbbe7a6af3ae99f99bfaef1b03" and "423831a4019ac38b25824e3f6363d487d0200257" have entirely different histories.
d26f5d3ba6
...
423831a401
4 changed files with 6 additions and 122 deletions
|
@ -1,5 +1,4 @@
|
|||
import os
|
||||
import strutils
|
||||
import parsetoml
|
||||
|
||||
import tool
|
||||
|
@ -13,8 +12,6 @@ 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"
|
||||
|
@ -47,10 +44,6 @@ 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()
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
|
||||
type
|
||||
WPArgs* = object
|
||||
query*: string
|
||||
last*: bool
|
||||
from_unsplash*: bool
|
|
@ -8,7 +8,6 @@ import model/volume
|
|||
import model/brightness
|
||||
import model/screenshot
|
||||
import model/tides
|
||||
import model/wallpapurr
|
||||
|
||||
proc parseArgs*() =
|
||||
let params = commandLineParams()
|
||||
|
@ -184,23 +183,17 @@ proc parseTideurrlArgs*(): TideList =
|
|||
quit(1)
|
||||
return t
|
||||
|
||||
proc parseWallpapurrArgs*(): WPArgs =
|
||||
var args = WPArgs()
|
||||
proc parseWallpapurrArgs*(): string =
|
||||
var query = "devon coast"
|
||||
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 != "":
|
||||
args.query = opts.query
|
||||
if opts.last:
|
||||
args.last = true
|
||||
if opts.unsplash:
|
||||
args.from_unsplash = true
|
||||
query = opts.query
|
||||
except ShortCircuit as err:
|
||||
if err.flag == "argparse_help":
|
||||
echo err.help
|
||||
|
@ -208,4 +201,4 @@ proc parseWallpapurrArgs*(): WPArgs =
|
|||
except UsageError:
|
||||
stderr.writeLine getCurrentExceptionMsg()
|
||||
quit(1)
|
||||
return args
|
||||
return query
|
||||
|
|
|
@ -1,108 +1,12 @@
|
|||
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 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
|
||||
|
||||
|
||||
|
||||
var mytides = parseWallpapurrArgs()
|
||||
echo mytides
|
||||
|
||||
|
|
Loading…
Reference in a new issue