Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Comment: | Add `nextweek` command to move todos to "next" Monday
I.e. whatever day of the week the todo is on it'll be moved to the next Monday. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/issue1 | trunk | master |
Files: | files | file ages | folders |
SHA3-256: |
ca6b54431eb8be6182ec274cf0372bba |
User & Date: | atomicules 2020-05-14 06:16:09 |
2020-05-14
| ||
20:47 |
Support using "Mon", "Tue", etc aswell as "today", "tomorrow"
Works well, but not having hlint means my code is messy. Could do with a | |
06:16 |
Add `nextweek` command to move todos to "next" Monday
I.e. whatever day of the week the todo is on it'll be moved to the next Monday. | |
2020-03-14
| ||
15:15 |
Follow-up to previous commit - remove all trailing slashes from apiurls
And add to the put and delete where needed. This is better and more consistent. Also works. Odd that things magically broke | |
Changes to haskerdeux.hs.
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | --Note to self: to run you type `runhaskell haskerdeux.hs test "me" "this" "that"`, etc dispatch :: String -> (String, [String]) -> IO() dispatch "todos" = todos dispatch "new" = new dispatch "crossoff" = crossoff dispatch "putoff" = putoff dispatch "moveto" = moveto dispatch "delete" = remove main = do (date:command:argList) <- getArgs time <- getClockTime >>= toCalendarTime --https://wiki.haskell.org/Unix_tools/Date let todays_date = formatCalendarTime defaultTimeLocale "%Y-%m-%d" time let tomorrows_date = show (addDays 1 $ read todays_date::Data.Time.Day) let todos_date | date == "today" = todays_date | date == "tomorrow" = tomorrows_date | otherwise = date | > | | 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 | --Note to self: to run you type `runhaskell haskerdeux.hs test "me" "this" "that"`, etc dispatch :: String -> (String, [String]) -> IO() dispatch "todos" = todos dispatch "new" = new dispatch "crossoff" = crossoff dispatch "putoff" = putoff dispatch "nextweek" = nextweek dispatch "moveto" = moveto dispatch "delete" = remove main = do (date:command:argList) <- getArgs time <- getClockTime >>= toCalendarTime --https://wiki.haskell.org/Unix_tools/Date let todays_date = formatCalendarTime defaultTimeLocale "%Y-%m-%d" time let tomorrows_date = show (addDays 1 $ read todays_date::Data.Time.Day) let todos_date | date == "today" = todays_date | date == "tomorrow" = tomorrows_date | otherwise = date when ((command `elem` ["todos"] && Data.List.null argList) || (command `elem` ["new", "crossoff", "putoff", "delete", "nextweek"] && length argList == 1) || (command == "moveto" && length argList == 2)) $ do token <- login dispatch command (token, todos_date:argList) readnetrc = do home <- getHomeDirectory netrc <- lines Control.Applicative.<$> readFile (home ++ "/.netrc") |
︙ | ︙ | |||
65 66 67 68 69 70 71 | then do let tds = decodeJSON body :: [Teuxdeux] let tdsf = Data.List.filter (\td -> current_date td == date && not (done td)) tds return tdsf else do token <- relogin curlget (token, date) | | | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | then do let tds = decodeJSON body :: [Teuxdeux] let tdsf = Data.List.filter (\td -> current_date td == date && not (done td)) tds return tdsf else do token <- relogin curlget (token, date) curlpost (token, [date, key, value, apiurl, okresponse]) number = do home <- getHomeDirectory let cookies = home ++ "/haskerdeux.cookies" let curlheader = "X-CSRF-Token: " ++ token --Can be much improved, but will do for now: json <- if isJust number |
︙ | ︙ | |||
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 | curlpost (token, [todos_date, "current_date", new_date, "https://teuxdeux.com/api/v1/todos/reposition", "Moved!"]) (Just number) remove (token, [todos_date, number]) = curldelete (token, [todos_date, "https://teuxdeux.com/api/v1/todos", "Deleted!"]) number --Thanks to http://www.amateurtopologist.com/blog/2010/11/05/a-haskell-newbies-guide-to-text-json/ and http://hpaste.org/41263/parsing_json_with_textjson data Teuxdeux = Teuxdeux { id :: Integer, current_date :: String, text :: String, done :: Bool } deriving (Eq, Show, Data, Typeable) --Another data type here probably for lists | > > > > > > > > > > > > > > > > | 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | curlpost (token, [todos_date, "current_date", new_date, "https://teuxdeux.com/api/v1/todos/reposition", "Moved!"]) (Just number) remove (token, [todos_date, number]) = curldelete (token, [todos_date, "https://teuxdeux.com/api/v1/todos", "Deleted!"]) number nextweek (token, [todos_date, number]) = do let days_map = fromList [ ("Monday", 7) , ("Tuesday", 6) , ("Wednesday", 5) , ("Thursday", 4) , ("Friday", 3) , ("Saturday", 2) , ("Sunday", 1)] let time_from_string = readTime defaultTimeLocale "%Y-%m-%d" todos_date::Data.Time.Day let todos_day = formatTime defaultTimeLocale "%A" time_from_string let days_to_add = Data.Map.lookup todos_day days_map let moveto_date = show (addDays (fromJust days_to_add) $ read todos_date::Data.Time.Day) moveto (token, [todos_date, number, moveto_date]) --Thanks to http://www.amateurtopologist.com/blog/2010/11/05/a-haskell-newbies-guide-to-text-json/ and http://hpaste.org/41263/parsing_json_with_textjson data Teuxdeux = Teuxdeux { id :: Integer, current_date :: String, text :: String, done :: Bool } deriving (Eq, Show, Data, Typeable) --Another data type here probably for lists |