Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
| Comment: | Add a tomorrow command to fetch tomorrow's todos
Since there is no way to interact with todos from tomorrow don't number Really I should think about how to make this work nicely with todos on |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | origin/issue1 | trunk | master |
| Files: | files | file ages | folders |
| SHA3-256: |
674b1e8fbaaefcdb45a981cdd27fe85c |
| User & Date: | base@atomicules.co.uk 2017-01-29 14:33:04 |
|
2017-02-26
| ||
| 15:02 |
Enable commands for any date
Previously Haskerdeux worked around the assumption of "today" and This does change the syntax a little bit. Supplying a date argument is The command "today" is now called "todos" since it can list todos for | |
|
2017-01-29
| ||
| 14:33 |
Add a tomorrow command to fetch tomorrow's todos
Since there is no way to interact with todos from tomorrow don't number Really I should think about how to make this work nicely with todos on | |
|
2016-12-04
| ||
| 16:04 | Add note about used to use Network.Curl check-in: 5f083ddb12 user: base@atomicules.co.uk tags: master, origin/issue1, trunk | |
Changes to haskerdeux.hs.
| ︙ | ︙ | |||
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | import System.Locale (defaultTimeLocale) import System.Directory import Network.URI.Encode --need to install --Note to self: to run you type `runhaskell haskerdeux.hs test "me" "this" "that"`, etc dispatch :: String -> (String, [String]) -> IO() dispatch "today" = today dispatch "new" = new dispatch "crossoff" = crossoff dispatch "putoff" = putoff dispatch "moveto" = moveto dispatch "delete" = remove main = do time <- getClockTime >>= toCalendarTime --https://wiki.haskell.org/Unix_tools/Date let todays_date = formatCalendarTime defaultTimeLocale "%Y-%m-%d" time (command:argList) <- getArgs | > | | | | | | | | | | | | 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
import System.Locale (defaultTimeLocale)
import System.Directory
import Network.URI.Encode --need to install
--Note to self: to run you type `runhaskell haskerdeux.hs test "me" "this" "that"`, etc
dispatch :: String -> (String, [String]) -> IO()
dispatch "today" = today
dispatch "tomorrow" = tomorrow
dispatch "new" = new
dispatch "crossoff" = crossoff
dispatch "putoff" = putoff
dispatch "moveto" = moveto
dispatch "delete" = remove
main = do
time <- getClockTime >>= toCalendarTime --https://wiki.haskell.org/Unix_tools/Date
let todays_date = formatCalendarTime defaultTimeLocale "%Y-%m-%d" time
(command:argList) <- getArgs
when ((command `elem` ["today", "tomorrow"] && Data.List.null argList) || (command `elem` ["new", "crossoff", "putoff", "delete"] && length argList == 1) || (command == "moveto" && length argList == 2)) $ do
username <- fmap fst readnetrc
password <- fmap snd readnetrc
token <- login [username, password]
dispatch command (token, todays_date:argList)
readnetrc = do
home <- getHomeDirectory
netrc <- lines Control.Applicative.<$> readFile (home ++ "/.netrc")
let netrc' = dropWhile (not . ("teuxdeux" `isInfixOf`)) netrc
let (username, password) = if "login" `isInfixOf` head netrc'
-- if entry is on one line
then (getcred "login", getcred "password")
-- if entry is on multiple lines
else (last $ words $ netrc' !! 1, last $ words $ netrc' !! 2)
where getcred c = dropWhile (not . (c `isInfixOf`)) (words $ head netrc') !! 1
return (username, password)
curlget (token, date) = do
let curlheader = "X-CSRF-Token: " ++ token
body <- readProcess "curl" ["-s", "-L", "-c", "haskerdeux.cookies", "-b", "haskerdeux.cookies", "-H", curlheader, "https://teuxdeux.com/api/v1/todos/calendar?begin_date="++date++"&end_date="++date] []
let tds = decodeJSON body :: [Teuxdeux]
let tdsf = Data.List.filter (\td -> current_date td == date && not (done td)) tds
return tdsf
curlpost (token, [date, key, value, apiurl, okresponse]) number = do
let curlheader = "X-CSRF-Token: " ++ token
--Can be much improved, but will do for now:
json <- if isJust number
then do
tdsf <- curlget (token, date)
let itemid = Main.id $ tdsf!!(read (fromJust number)::Int)
let modjson = "{ \"ids\" : [\""++show itemid++"\"], \""++key++"\" : \""++value++"\"}"
return modjson
else do
--Can't just straight return these strings, need to let them first
let newjson = "{ \"current_date\" : \""++date++"\", \""++key++"\" : \""++value++"\"}"
return newjson
body <- readProcess "curl" ["-s", "-XPOST", apiurl, "-L", "-c", "haskerdeux.cookies", "-b", "haskerdeux.cookies", "-H", curlheader, "-H", "Content-Type: application/json", "-d", json] []
if "done_updated_at" `isInfixOf` body
then putStrLn okresponse
else putStrLn "Uh Oh! Didn't work!"
curldelete (token, [date, apiurl, okresponse]) number = do
tdsf <- curlget (token, date)
let itemid = Main.id $ tdsf!!(read number::Int)
let curlheader = "X-CSRF-Token: " ++ token
body <- readProcess "curl" ["-s", "-XDELETE", apiurl++show itemid, "-c", "haskerdeux.cookies", "-b", "haskerdeux.cookies", "-H", curlheader] []
if "done_updated_at" `isInfixOf` body
then putStrLn okresponse
else putStrLn "Uh Oh! Didn't work!"
curlput (token, [date, json, apiurl, okresponse]) number = do
tdsf <- curlget (token, date)
let itemid = Main.id $ tdsf!!(read number::Int)
let curlheader = "X-CSRF-Token: " ++ token
body <- readProcess "curl" ["-s", "-XPUT", apiurl++show itemid, "-L", "-c", "haskerdeux.cookies", "-b", "haskerdeux.cookies", "-H", curlheader, "-H", "Content-Type: application/json", "-d", json] []
if "done_updated_at" `isInfixOf` body
then putStrLn okresponse
else putStrLn "Uh Oh! Didn't work!"
|
| ︙ | ︙ | |||
129 130 131 132 133 134 135 136 137 138 139 140 141 142 | return token today (token, [todays_date]) = do tdsf <- curlget (token, todays_date) putStr $ unlines $ zipWith (\n td -> show n ++ " - " ++ td) [0..] $ Data.List.map text tdsf --numbering from LYAH new (token, [todays_date, todo]) = do let encodedtodo = Network.URI.Encode.encode todo curlpost (token, [todays_date, "text", todo, "https://teuxdeux.com/api/v1/todos/", "Added!"]) Nothing crossoff (token, [todays_date, number]) = | > > > > > > | 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
return token
today (token, [todays_date]) = do
tdsf <- curlget (token, todays_date)
putStr $ unlines $ zipWith (\n td -> show n ++ " - " ++ td) [0..] $ Data.List.map text tdsf --numbering from LYAH
tomorrow (token, [todays_date]) = do
let tomorrows_date = show (addDays 1 $ read todays_date::Data.Time.Day)
tdsf <- curlget (token, tomorrows_date)
putStr $ unlines $ Data.List.map ("- " ++) $ Data.List.map text tdsf
new (token, [todays_date, todo]) = do
let encodedtodo = Network.URI.Encode.encode todo
curlpost (token, [todays_date, "text", todo, "https://teuxdeux.com/api/v1/todos/", "Added!"]) Nothing
crossoff (token, [todays_date, number]) =
|
| ︙ | ︙ |