0000: 7b 2d 23 20 4c 41 4e 47 55 41 47 45 20 44 65 72 {-# LANGUAGE Der
0010: 69 76 65 44 61 74 61 54 79 70 65 61 62 6c 65 20 iveDataTypeable
0020: 23 2d 7d 0a 2d 2d 48 61 73 6b 65 72 44 65 75 78 #-}.--HaskerDeux
0030: 0a 0a 69 6d 70 6f 72 74 20 53 79 73 74 65 6d 2e ..import System.
0040: 45 6e 76 69 72 6f 6e 6d 65 6e 74 0a 69 6d 70 6f Environment.impo
0050: 72 74 20 53 79 73 74 65 6d 2e 49 4f 0a 69 6d 70 rt System.IO.imp
0060: 6f 72 74 20 53 79 73 74 65 6d 2e 49 4f 2e 45 72 ort System.IO.Er
0070: 72 6f 72 0a 69 6d 70 6f 72 74 20 53 79 73 74 65 ror.import Syste
0080: 6d 2e 50 72 6f 63 65 73 73 0a 69 6d 70 6f 72 74 m.Process.import
0090: 20 44 61 74 61 2e 4c 69 73 74 0a 69 6d 70 6f 72 Data.List.impor
00a0: 74 20 44 61 74 61 2e 4c 69 73 74 2e 53 70 6c 69 t Data.List.Spli
00b0: 74 20 2d 2d 6e 65 65 64 20 74 6f 20 69 6e 73 74 t --need to inst
00c0: 61 6c 6c 0a 69 6d 70 6f 72 74 20 44 61 74 61 2e all.import Data.
00d0: 4d 61 70 0a 69 6d 70 6f 72 74 20 43 6f 6e 74 72 Map.import Contr
00e0: 6f 6c 2e 4d 6f 6e 61 64 0a 69 6d 70 6f 72 74 20 ol.Monad.import
00f0: 43 6f 6e 74 72 6f 6c 2e 41 70 70 6c 69 63 61 74 Control.Applicat
0100: 69 76 65 0a 69 6d 70 6f 72 74 20 44 61 74 61 2e ive.import Data.
0110: 4d 61 79 62 65 0a 69 6d 70 6f 72 74 20 54 65 78 Maybe.import Tex
0120: 74 2e 4a 53 4f 4e 20 2d 2d 6e 65 65 64 20 74 6f t.JSON --need to
0130: 20 69 6e 73 74 61 6c 6c 20 66 6f 72 20 4a 53 4f install for JSO
0140: 4e 0a 69 6d 70 6f 72 74 20 54 65 78 74 2e 4a 53 N.import Text.JS
0150: 4f 4e 2e 47 65 6e 65 72 69 63 20 2d 2d 6e 65 65 ON.Generic --nee
0160: 64 20 74 6f 20 69 6e 73 74 61 6c 6c 20 66 6f 72 d to install for
0170: 20 4a 53 4f 4e 0a 69 6d 70 6f 72 74 20 44 61 74 JSON.import Dat
0180: 61 2e 54 69 6d 65 0a 69 6d 70 6f 72 74 20 53 79 a.Time.import Sy
0190: 73 74 65 6d 2e 54 69 6d 65 0a 69 6d 70 6f 72 74 stem.Time.import
01a0: 20 53 79 73 74 65 6d 2e 4c 6f 63 61 6c 65 20 28 System.Locale (
01b0: 64 65 66 61 75 6c 74 54 69 6d 65 4c 6f 63 61 6c defaultTimeLocal
01c0: 65 29 0a 69 6d 70 6f 72 74 20 53 79 73 74 65 6d e).import System
01d0: 2e 44 69 72 65 63 74 6f 72 79 0a 69 6d 70 6f 72 .Directory.impor
01e0: 74 20 4e 65 74 77 6f 72 6b 2e 55 52 49 2e 45 6e t Network.URI.En
01f0: 63 6f 64 65 20 2d 2d 6e 65 65 64 20 74 6f 20 69 code --need to i
0200: 6e 73 74 61 6c 6c 0a 0a 2d 2d 4e 6f 74 65 20 74 nstall..--Note t
0210: 6f 20 73 65 6c 66 3a 20 74 6f 20 72 75 6e 20 79 o self: to run y
0220: 6f 75 20 74 79 70 65 20 60 72 75 6e 68 61 73 6b ou type `runhask
0230: 65 6c 6c 20 68 61 73 6b 65 72 64 65 75 78 2e 68 ell haskerdeux.h
0240: 73 20 74 65 73 74 20 22 6d 65 22 20 22 74 68 69 s test "me" "thi
0250: 73 22 20 22 74 68 61 74 22 60 2c 20 65 74 63 0a s" "that"`, etc.
0260: 64 69 73 70 61 74 63 68 20 3a 3a 20 53 74 72 69 dispatch :: Stri
0270: 6e 67 20 2d 3e 20 28 53 74 72 69 6e 67 2c 20 5b ng -> (String, [
0280: 53 74 72 69 6e 67 5d 29 20 2d 3e 20 49 4f 28 29 String]) -> IO()
0290: 0a 64 69 73 70 61 74 63 68 20 22 74 6f 64 6f 73 .dispatch "todos
02a0: 22 20 3d 20 74 6f 64 6f 73 0a 64 69 73 70 61 74 " = todos.dispat
02b0: 63 68 20 22 6e 65 77 22 20 3d 20 6e 65 77 0a 64 ch "new" = new.d
02c0: 69 73 70 61 74 63 68 20 22 63 72 6f 73 73 6f 66 ispatch "crossof
02d0: 66 22 20 3d 20 63 72 6f 73 73 6f 66 66 0a 64 69 f" = crossoff.di
02e0: 73 70 61 74 63 68 20 22 70 75 74 6f 66 66 22 20 spatch "putoff"
02f0: 3d 20 70 75 74 6f 66 66 0a 64 69 73 70 61 74 63 = putoff.dispatc
0300: 68 20 22 6d 6f 76 65 74 6f 22 20 3d 20 6d 6f 76 h "moveto" = mov
0310: 65 74 6f 0a 64 69 73 70 61 74 63 68 20 22 64 65 eto.dispatch "de
0320: 6c 65 74 65 22 20 3d 20 72 65 6d 6f 76 65 0a 0a lete" = remove..
0330: 0a 6d 61 69 6e 20 3d 20 64 6f 20 0a 09 28 64 61 .main = do ..(da
0340: 74 65 3a 63 6f 6d 6d 61 6e 64 3a 61 72 67 4c 69 te:command:argLi
0350: 73 74 29 20 3c 2d 20 67 65 74 41 72 67 73 0a 09 st) <- getArgs..
0360: 74 69 6d 65 20 3c 2d 20 67 65 74 43 6c 6f 63 6b time <- getClock
0370: 54 69 6d 65 20 3e 3e 3d 20 74 6f 43 61 6c 65 6e Time >>= toCalen
0380: 64 61 72 54 69 6d 65 20 2d 2d 68 74 74 70 73 3a darTime --https:
0390: 2f 2f 77 69 6b 69 2e 68 61 73 6b 65 6c 6c 2e 6f //wiki.haskell.o
03a0: 72 67 2f 55 6e 69 78 5f 74 6f 6f 6c 73 2f 44 61 rg/Unix_tools/Da
03b0: 74 65 0a 09 6c 65 74 20 74 6f 64 61 79 73 5f 64 te..let todays_d
03c0: 61 74 65 20 3d 20 66 6f 72 6d 61 74 43 61 6c 65 ate = formatCale
03d0: 6e 64 61 72 54 69 6d 65 20 64 65 66 61 75 6c 74 ndarTime default
03e0: 54 69 6d 65 4c 6f 63 61 6c 65 20 22 25 59 2d 25 TimeLocale "%Y-%
03f0: 6d 2d 25 64 22 20 74 69 6d 65 0a 09 6c 65 74 20 m-%d" time..let
0400: 74 6f 6d 6f 72 72 6f 77 73 5f 64 61 74 65 20 3d tomorrows_date =
0410: 20 73 68 6f 77 20 28 61 64 64 44 61 79 73 20 31 show (addDays 1
0420: 20 24 20 72 65 61 64 20 74 6f 64 61 79 73 5f 64 $ read todays_d
0430: 61 74 65 3a 3a 44 61 74 61 2e 54 69 6d 65 2e 44 ate::Data.Time.D
0440: 61 79 29 0a 09 6c 65 74 20 20 74 6f 64 6f 73 5f ay)..let todos_
0450: 64 61 74 65 20 7c 20 64 61 74 65 20 3d 3d 20 22 date | date == "
0460: 74 6f 64 61 79 22 20 3d 20 74 6f 64 61 79 73 5f today" = todays_
0470: 64 61 74 65 0a 09 20 20 20 20 20 20 20 20 20 20 date..
0480: 20 20 20 20 20 20 7c 20 64 61 74 65 20 3d 3d 20 | date ==
0490: 22 74 6f 6d 6f 72 72 6f 77 22 20 3d 20 74 6f 6d "tomorrow" = tom
04a0: 6f 72 72 6f 77 73 5f 64 61 74 65 0a 09 20 20 20 orrows_date..
04b0: 20 20 20 20 20 20 20 20 20 20 20 20 20 7c 20 6f | o
04c0: 74 68 65 72 77 69 73 65 20 3d 20 64 61 74 65 0a therwise = date.
04d0: 09 77 68 65 6e 20 28 28 63 6f 6d 6d 61 6e 64 20 .when ((command
04e0: 60 65 6c 65 6d 60 20 5b 22 74 6f 64 6f 73 22 5d `elem` ["todos"]
04f0: 20 26 26 20 44 61 74 61 2e 4c 69 73 74 2e 6e 75 && Data.List.nu
0500: 6c 6c 20 61 72 67 4c 69 73 74 29 20 7c 7c 20 28 ll argList) || (
0510: 63 6f 6d 6d 61 6e 64 20 60 65 6c 65 6d 60 20 5b command `elem` [
0520: 22 6e 65 77 22 2c 20 22 63 72 6f 73 73 6f 66 66 "new", "crossoff
0530: 22 2c 20 22 70 75 74 6f 66 66 22 2c 20 22 64 65 ", "putoff", "de
0540: 6c 65 74 65 22 5d 20 26 26 20 6c 65 6e 67 74 68 lete"] && length
0550: 20 61 72 67 4c 69 73 74 20 3d 3d 20 31 29 20 7c argList == 1) |
0560: 7c 20 28 63 6f 6d 6d 61 6e 64 20 3d 3d 20 22 6d | (command == "m
0570: 6f 76 65 74 6f 22 20 26 26 20 6c 65 6e 67 74 68 oveto" && length
0580: 20 61 72 67 4c 69 73 74 20 3d 3d 20 32 29 29 20 argList == 2))
0590: 24 20 64 6f 0a 09 09 74 6f 6b 65 6e 20 3c 2d 20 $ do...token <-
05a0: 6c 6f 67 69 6e 0a 09 09 64 69 73 70 61 74 63 68 login...dispatch
05b0: 20 63 6f 6d 6d 61 6e 64 20 28 74 6f 6b 65 6e 2c command (token,
05c0: 20 74 6f 64 6f 73 5f 64 61 74 65 3a 61 72 67 4c todos_date:argL
05d0: 69 73 74 29 0a 0a 0a 72 65 61 64 6e 65 74 72 63 ist)...readnetrc
05e0: 20 3d 20 64 6f 0a 09 68 6f 6d 65 20 3c 2d 20 67 = do..home <- g
05f0: 65 74 48 6f 6d 65 44 69 72 65 63 74 6f 72 79 0a etHomeDirectory.
0600: 09 6e 65 74 72 63 20 3c 2d 20 6c 69 6e 65 73 20 .netrc <- lines
0610: 43 6f 6e 74 72 6f 6c 2e 41 70 70 6c 69 63 61 74 Control.Applicat
0620: 69 76 65 2e 3c 24 3e 20 72 65 61 64 46 69 6c 65 ive.<$> readFile
0630: 20 28 68 6f 6d 65 20 2b 2b 20 22 2f 2e 6e 65 74 (home ++ "/.net
0640: 72 63 22 29 0a 09 6c 65 74 20 6e 65 74 72 63 27 rc")..let netrc'
0650: 20 3d 20 64 72 6f 70 57 68 69 6c 65 20 28 6e 6f = dropWhile (no
0660: 74 20 2e 20 28 22 74 65 75 78 64 65 75 78 22 20 t . ("teuxdeux"
0670: 60 69 73 49 6e 66 69 78 4f 66 60 29 29 20 6e 65 `isInfixOf`)) ne
0680: 74 72 63 0a 09 6c 65 74 20 28 75 73 65 72 6e 61 trc..let (userna
0690: 6d 65 2c 20 70 61 73 73 77 6f 72 64 29 20 3d 20 me, password) =
06a0: 69 66 20 22 6c 6f 67 69 6e 22 20 60 69 73 49 6e if "login" `isIn
06b0: 66 69 78 4f 66 60 20 68 65 61 64 20 6e 65 74 72 fixOf` head netr
06c0: 63 27 0a 09 09 2d 2d 20 69 66 20 65 6e 74 72 79 c'...-- if entry
06d0: 20 69 73 20 6f 6e 20 6f 6e 65 20 6c 69 6e 65 09 is on one line.
06e0: 0a 09 09 74 68 65 6e 20 28 67 65 74 63 72 65 64 ...then (getcred
06f0: 20 22 6c 6f 67 69 6e 22 2c 20 67 65 74 63 72 65 "login", getcre
0700: 64 20 22 70 61 73 73 77 6f 72 64 22 29 20 0a 09 d "password") ..
0710: 09 2d 2d 20 69 66 20 65 6e 74 72 79 20 69 73 20 .-- if entry is
0720: 6f 6e 20 6d 75 6c 74 69 70 6c 65 20 6c 69 6e 65 on multiple line
0730: 73 0a 09 09 65 6c 73 65 20 28 6c 61 73 74 20 24 s...else (last $
0740: 20 77 6f 72 64 73 20 24 20 6e 65 74 72 63 27 20 words $ netrc'
0750: 21 21 20 31 2c 20 6c 61 73 74 20 24 20 77 6f 72 !! 1, last $ wor
0760: 64 73 20 24 20 6e 65 74 72 63 27 20 21 21 20 32 ds $ netrc' !! 2
0770: 29 0a 09 09 77 68 65 72 65 20 67 65 74 63 72 65 )...where getcre
0780: 64 20 63 20 3d 20 64 72 6f 70 57 68 69 6c 65 20 d c = dropWhile
0790: 28 6e 6f 74 20 2e 20 28 63 20 60 69 73 49 6e 66 (not . (c `isInf
07a0: 69 78 4f 66 60 29 29 20 28 77 6f 72 64 73 20 24 ixOf`)) (words $
07b0: 20 68 65 61 64 20 6e 65 74 72 63 27 29 20 21 21 head netrc') !!
07c0: 20 31 0a 09 72 65 74 75 72 6e 20 28 75 73 65 72 1..return (user
07d0: 6e 61 6d 65 2c 20 70 61 73 73 77 6f 72 64 29 0a name, password).
07e0: 0a 0a 63 75 72 6c 67 65 74 20 28 74 6f 6b 65 6e ..curlget (token
07f0: 2c 20 64 61 74 65 29 20 3d 20 64 6f 0a 09 6c 65 , date) = do..le
0800: 74 20 63 75 72 6c 68 65 61 64 65 72 20 3d 20 22 t curlheader = "
0810: 58 2d 43 53 52 46 2d 54 6f 6b 65 6e 3a 20 22 20 X-CSRF-Token: "
0820: 2b 2b 20 74 6f 6b 65 6e 0a 09 62 6f 64 79 20 3c ++ token..body <
0830: 2d 20 72 65 61 64 50 72 6f 63 65 73 73 20 22 63 - readProcess "c
0840: 75 72 6c 22 20 5b 22 2d 73 22 2c 20 22 2d 4c 22 url" ["-s", "-L"
0850: 2c 20 22 2d 63 22 2c 20 22 68 61 73 6b 65 72 64 , "-c", "haskerd
0860: 65 75 78 2e 63 6f 6f 6b 69 65 73 22 2c 20 22 2d eux.cookies", "-
0870: 62 22 2c 20 22 68 61 73 6b 65 72 64 65 75 78 2e b", "haskerdeux.
0880: 63 6f 6f 6b 69 65 73 22 2c 20 22 2d 48 22 2c 20 cookies", "-H",
0890: 63 75 72 6c 68 65 61 64 65 72 2c 20 22 68 74 74 curlheader, "htt
08a0: 70 73 3a 2f 2f 74 65 75 78 64 65 75 78 2e 63 6f ps://teuxdeux.co
08b0: 6d 2f 61 70 69 2f 76 31 2f 74 6f 64 6f 73 2f 63 m/api/v1/todos/c
08c0: 61 6c 65 6e 64 61 72 3f 62 65 67 69 6e 5f 64 61 alendar?begin_da
08d0: 74 65 3d 22 2b 2b 64 61 74 65 2b 2b 22 26 65 6e te="++date++"&en
08e0: 64 5f 64 61 74 65 3d 22 2b 2b 64 61 74 65 5d 20 d_date="++date]
08f0: 5b 5d 0a 09 6c 65 74 20 6f 6b 20 3d 20 6e 6f 74 []..let ok = not
0900: 20 28 22 49 6e 76 61 6c 69 64 20 43 53 52 46 20 ("Invalid CSRF
0910: 54 6f 6b 65 6e 22 20 60 69 73 49 6e 66 69 78 4f Token" `isInfixO
0920: 66 60 20 62 6f 64 79 29 0a 09 69 66 20 6f 6b 0a f` body)..if ok.
0930: 09 09 74 68 65 6e 20 64 6f 0a 09 09 09 6c 65 74 ..then do....let
0940: 20 74 64 73 20 3d 20 64 65 63 6f 64 65 4a 53 4f tds = decodeJSO
0950: 4e 20 62 6f 64 79 20 3a 3a 20 5b 54 65 75 78 64 N body :: [Teuxd
0960: 65 75 78 5d 0a 09 09 09 6c 65 74 20 74 64 73 66 eux]....let tdsf
0970: 20 3d 20 44 61 74 61 2e 4c 69 73 74 2e 66 69 6c = Data.List.fil
0980: 74 65 72 20 28 5c 74 64 20 2d 3e 20 63 75 72 72 ter (\td -> curr
0990: 65 6e 74 5f 64 61 74 65 20 74 64 20 3d 3d 20 64 ent_date td == d
09a0: 61 74 65 20 26 26 20 6e 6f 74 20 28 64 6f 6e 65 ate && not (done
09b0: 20 74 64 29 29 20 74 64 73 0a 09 09 09 72 65 74 td)) tds....ret
09c0: 75 72 6e 20 74 64 73 66 0a 09 09 65 6c 73 65 20 urn tdsf...else
09d0: 64 6f 0a 09 09 09 74 6f 6b 65 6e 20 3c 2d 20 72 do....token <- r
09e0: 65 6c 6f 67 69 6e 20 0a 09 09 09 63 75 72 6c 67 elogin ....curlg
09f0: 65 74 20 28 74 6f 6b 65 6e 2c 20 64 61 74 65 29 et (token, date)
0a00: 0a 09 0a 0a 63 75 72 6c 70 6f 73 74 20 28 74 6f ....curlpost (to
0a10: 6b 65 6e 2c 20 5b 64 61 74 65 2c 20 6b 65 79 2c ken, [date, key,
0a20: 20 76 61 6c 75 65 2c 20 61 70 69 75 72 6c 2c 20 value, apiurl,
0a30: 6f 6b 72 65 73 70 6f 6e 73 65 5d 29 20 6e 75 6d okresponse]) num
0a40: 62 65 72 20 3d 20 64 6f 0a 09 6c 65 74 20 63 75 ber = do..let cu
0a50: 72 6c 68 65 61 64 65 72 20 3d 20 22 58 2d 43 53 rlheader = "X-CS
0a60: 52 46 2d 54 6f 6b 65 6e 3a 20 22 20 2b 2b 20 74 RF-Token: " ++ t
0a70: 6f 6b 65 6e 0a 09 2d 2d 43 61 6e 20 62 65 20 6d oken..--Can be m
0a80: 75 63 68 20 69 6d 70 72 6f 76 65 64 2c 20 62 75 uch improved, bu
0a90: 74 20 77 69 6c 6c 20 64 6f 20 66 6f 72 20 6e 6f t will do for no
0aa0: 77 3a 0a 09 6a 73 6f 6e 20 3c 2d 20 69 66 20 69 w:..json <- if i
0ab0: 73 4a 75 73 74 20 6e 75 6d 62 65 72 0a 09 09 74 sJust number...t
0ac0: 68 65 6e 20 64 6f 0a 09 09 09 74 64 73 66 20 3c hen do....tdsf <
0ad0: 2d 20 63 75 72 6c 67 65 74 20 28 74 6f 6b 65 6e - curlget (token
0ae0: 2c 20 64 61 74 65 29 0a 09 09 09 6c 65 74 20 69 , date)....let i
0af0: 74 65 6d 69 64 20 3d 20 4d 61 69 6e 2e 69 64 20 temid = Main.id
0b00: 24 20 74 64 73 66 21 21 28 72 65 61 64 20 28 66 $ tdsf!!(read (f
0b10: 72 6f 6d 4a 75 73 74 20 6e 75 6d 62 65 72 29 3a romJust number):
0b20: 3a 49 6e 74 29 0a 09 09 09 6c 65 74 20 6d 6f 64 :Int)....let mod
0b30: 6a 73 6f 6e 20 3d 20 22 7b 20 5c 22 69 64 73 5c json = "{ \"ids\
0b40: 22 20 3a 20 5b 5c 22 22 2b 2b 73 68 6f 77 20 69 " : [\""++show i
0b50: 74 65 6d 69 64 2b 2b 22 5c 22 5d 2c 20 5c 22 22 temid++"\"], \""
0b60: 2b 2b 6b 65 79 2b 2b 22 5c 22 20 3a 20 5c 22 22 ++key++"\" : \""
0b70: 2b 2b 76 61 6c 75 65 2b 2b 22 5c 22 7d 22 0a 09 ++value++"\"}"..
0b80: 09 09 72 65 74 75 72 6e 20 6d 6f 64 6a 73 6f 6e ..return modjson
0b90: 0a 09 09 65 6c 73 65 20 64 6f 0a 09 09 09 2d 2d ...else do....--
0ba0: 43 61 6e 27 74 20 6a 75 73 74 20 73 74 72 61 69 Can't just strai
0bb0: 67 68 74 20 72 65 74 75 72 6e 20 74 68 65 73 65 ght return these
0bc0: 20 73 74 72 69 6e 67 73 2c 20 6e 65 65 64 20 74 strings, need t
0bd0: 6f 20 6c 65 74 20 74 68 65 6d 20 66 69 72 73 74 o let them first
0be0: 0a 09 09 09 6c 65 74 20 6e 65 77 6a 73 6f 6e 20 ....let newjson
0bf0: 3d 20 22 7b 20 5c 22 63 75 72 72 65 6e 74 5f 64 = "{ \"current_d
0c00: 61 74 65 5c 22 20 3a 20 5c 22 22 2b 2b 64 61 74 ate\" : \""++dat
0c10: 65 2b 2b 22 5c 22 2c 20 5c 22 22 2b 2b 6b 65 79 e++"\", \""++key
0c20: 2b 2b 22 5c 22 20 3a 20 5c 22 22 2b 2b 76 61 6c ++"\" : \""++val
0c30: 75 65 2b 2b 22 5c 22 7d 22 0a 09 09 09 72 65 74 ue++"\"}"....ret
0c40: 75 72 6e 20 6e 65 77 6a 73 6f 6e 0a 09 62 6f 64 urn newjson..bod
0c50: 79 20 3c 2d 20 72 65 61 64 50 72 6f 63 65 73 73 y <- readProcess
0c60: 20 22 63 75 72 6c 22 20 5b 22 2d 73 22 2c 20 22 "curl" ["-s", "
0c70: 2d 58 50 4f 53 54 22 2c 20 61 70 69 75 72 6c 2c -XPOST", apiurl,
0c80: 20 22 2d 4c 22 2c 20 22 2d 63 22 2c 20 22 68 61 "-L", "-c", "ha
0c90: 73 6b 65 72 64 65 75 78 2e 63 6f 6f 6b 69 65 73 skerdeux.cookies
0ca0: 22 2c 20 22 2d 62 22 2c 20 22 68 61 73 6b 65 72 ", "-b", "hasker
0cb0: 64 65 75 78 2e 63 6f 6f 6b 69 65 73 22 2c 20 22 deux.cookies", "
0cc0: 2d 48 22 2c 20 63 75 72 6c 68 65 61 64 65 72 2c -H", curlheader,
0cd0: 20 22 2d 48 22 2c 20 22 43 6f 6e 74 65 6e 74 2d "-H", "Content-
0ce0: 54 79 70 65 3a 20 61 70 70 6c 69 63 61 74 69 6f Type: applicatio
0cf0: 6e 2f 6a 73 6f 6e 22 2c 20 22 2d 64 22 2c 20 6a n/json", "-d", j
0d00: 73 6f 6e 5d 20 5b 5d 0a 09 6c 65 74 20 6f 6b 20 son] []..let ok
0d10: 3d 20 6e 6f 74 20 28 22 49 6e 76 61 6c 69 64 20 = not ("Invalid
0d20: 43 53 52 46 20 54 6f 6b 65 6e 22 20 60 69 73 49 CSRF Token" `isI
0d30: 6e 66 69 78 4f 66 60 20 62 6f 64 79 29 0a 09 69 nfixOf` body)..i
0d40: 66 20 6f 6b 0a 09 09 74 68 65 6e 0a 09 09 09 69 f ok...then....i
0d50: 66 20 22 64 6f 6e 65 5f 75 70 64 61 74 65 64 5f f "done_updated_
0d60: 61 74 22 20 60 69 73 49 6e 66 69 78 4f 66 60 20 at" `isInfixOf`
0d70: 62 6f 64 79 0a 09 09 09 09 74 68 65 6e 20 70 75 body.....then pu
0d80: 74 53 74 72 4c 6e 20 6f 6b 72 65 73 70 6f 6e 73 tStrLn okrespons
0d90: 65 0a 09 09 09 09 65 6c 73 65 20 70 75 74 53 74 e.....else putSt
0da0: 72 4c 6e 20 22 55 68 20 4f 68 21 20 44 69 64 6e rLn "Uh Oh! Didn
0db0: 27 74 20 77 6f 72 6b 21 22 0a 09 09 65 6c 73 65 't work!"...else
0dc0: 20 64 6f 0a 09 09 09 74 6f 6b 65 6e 20 3c 2d 20 do....token <-
0dd0: 72 65 6c 6f 67 69 6e 20 0a 09 09 09 63 75 72 6c relogin ....curl
0de0: 70 6f 73 74 20 28 74 6f 6b 65 6e 2c 20 5b 64 61 post (token, [da
0df0: 74 65 2c 20 6b 65 79 2c 20 76 61 6c 75 65 2c 20 te, key, value,
0e00: 61 70 69 75 72 6c 2c 20 6f 6b 72 65 73 70 6f 6e apiurl, okrespon
0e10: 73 65 5d 29 20 6e 75 6d 62 65 72 0a 0a 0a 63 75 se]) number...cu
0e20: 72 6c 64 65 6c 65 74 65 20 28 74 6f 6b 65 6e 2c rldelete (token,
0e30: 20 5b 64 61 74 65 2c 20 61 70 69 75 72 6c 2c 20 [date, apiurl,
0e40: 6f 6b 72 65 73 70 6f 6e 73 65 5d 29 20 6e 75 6d okresponse]) num
0e50: 62 65 72 20 3d 20 64 6f 0a 09 74 64 73 66 20 3c ber = do..tdsf <
0e60: 2d 20 63 75 72 6c 67 65 74 20 28 74 6f 6b 65 6e - curlget (token
0e70: 2c 20 64 61 74 65 29 0a 09 6c 65 74 20 69 74 65 , date)..let ite
0e80: 6d 69 64 20 3d 20 4d 61 69 6e 2e 69 64 20 24 20 mid = Main.id $
0e90: 74 64 73 66 21 21 28 72 65 61 64 20 6e 75 6d 62 tdsf!!(read numb
0ea0: 65 72 3a 3a 49 6e 74 29 0a 09 6c 65 74 20 63 75 er::Int)..let cu
0eb0: 72 6c 68 65 61 64 65 72 20 3d 20 22 58 2d 43 53 rlheader = "X-CS
0ec0: 52 46 2d 54 6f 6b 65 6e 3a 20 22 20 2b 2b 20 74 RF-Token: " ++ t
0ed0: 6f 6b 65 6e 0a 09 62 6f 64 79 20 3c 2d 20 72 65 oken..body <- re
0ee0: 61 64 50 72 6f 63 65 73 73 20 22 63 75 72 6c 22 adProcess "curl"
0ef0: 20 5b 22 2d 73 22 2c 20 22 2d 58 44 45 4c 45 54 ["-s", "-XDELET
0f00: 45 22 2c 20 61 70 69 75 72 6c 2b 2b 73 68 6f 77 E", apiurl++show
0f10: 20 69 74 65 6d 69 64 2c 20 22 2d 63 22 2c 20 22 itemid, "-c", "
0f20: 68 61 73 6b 65 72 64 65 75 78 2e 63 6f 6f 6b 69 haskerdeux.cooki
0f30: 65 73 22 2c 20 22 2d 62 22 2c 20 22 68 61 73 6b es", "-b", "hask
0f40: 65 72 64 65 75 78 2e 63 6f 6f 6b 69 65 73 22 2c erdeux.cookies",
0f50: 20 22 2d 48 22 2c 20 63 75 72 6c 68 65 61 64 65 "-H", curlheade
0f60: 72 5d 20 5b 5d 0a 09 6c 65 74 20 6f 6b 20 3d 20 r] []..let ok =
0f70: 6e 6f 74 20 28 22 49 6e 76 61 6c 69 64 20 43 53 not ("Invalid CS
0f80: 52 46 20 54 6f 6b 65 6e 22 20 60 69 73 49 6e 66 RF Token" `isInf
0f90: 69 78 4f 66 60 20 62 6f 64 79 29 0a 09 69 66 20 ixOf` body)..if
0fa0: 6f 6b 0a 09 09 74 68 65 6e 0a 09 09 09 69 66 20 ok...then....if
0fb0: 22 64 6f 6e 65 5f 75 70 64 61 74 65 64 5f 61 74 "done_updated_at
0fc0: 22 20 60 69 73 49 6e 66 69 78 4f 66 60 20 62 6f " `isInfixOf` bo
0fd0: 64 79 0a 09 09 09 09 74 68 65 6e 20 70 75 74 53 dy.....then putS
0fe0: 74 72 4c 6e 20 6f 6b 72 65 73 70 6f 6e 73 65 0a trLn okresponse.
0ff0: 09 09 09 09 65 6c 73 65 20 70 75 74 53 74 72 4c ....else putStrL
1000: 6e 20 22 55 68 20 4f 68 21 20 44 69 64 6e 27 74 n "Uh Oh! Didn't
1010: 20 77 6f 72 6b 21 22 0a 09 09 65 6c 73 65 20 64 work!"...else d
1020: 6f 0a 09 09 09 74 6f 6b 65 6e 20 3c 2d 20 72 65 o....token <- re
1030: 6c 6f 67 69 6e 20 0a 09 09 09 63 75 72 6c 64 65 login ....curlde
1040: 6c 65 74 65 20 28 74 6f 6b 65 6e 2c 20 5b 64 61 lete (token, [da
1050: 74 65 2c 20 61 70 69 75 72 6c 2c 20 6f 6b 72 65 te, apiurl, okre
1060: 73 70 6f 6e 73 65 5d 29 20 6e 75 6d 62 65 72 0a sponse]) number.
1070: 0a 0a 63 75 72 6c 70 75 74 20 28 74 6f 6b 65 6e ..curlput (token
1080: 2c 20 5b 64 61 74 65 2c 20 6a 73 6f 6e 2c 20 61 , [date, json, a
1090: 70 69 75 72 6c 2c 20 6f 6b 72 65 73 70 6f 6e 73 piurl, okrespons
10a0: 65 5d 29 20 6e 75 6d 62 65 72 20 3d 20 64 6f 0a e]) number = do.
10b0: 09 74 64 73 66 20 3c 2d 20 63 75 72 6c 67 65 74 .tdsf <- curlget
10c0: 20 28 74 6f 6b 65 6e 2c 20 64 61 74 65 29 0a 09 (token, date)..
10d0: 6c 65 74 20 69 74 65 6d 69 64 20 3d 20 4d 61 69 let itemid = Mai
10e0: 6e 2e 69 64 20 24 20 74 64 73 66 21 21 28 72 65 n.id $ tdsf!!(re
10f0: 61 64 20 6e 75 6d 62 65 72 3a 3a 49 6e 74 29 0a ad number::Int).
1100: 09 6c 65 74 20 63 75 72 6c 68 65 61 64 65 72 20 .let curlheader
1110: 3d 20 22 58 2d 43 53 52 46 2d 54 6f 6b 65 6e 3a = "X-CSRF-Token:
1120: 20 22 20 2b 2b 20 74 6f 6b 65 6e 0a 09 62 6f 64 " ++ token..bod
1130: 79 20 3c 2d 20 72 65 61 64 50 72 6f 63 65 73 73 y <- readProcess
1140: 20 22 63 75 72 6c 22 20 5b 22 2d 73 22 2c 20 22 "curl" ["-s", "
1150: 2d 58 50 55 54 22 2c 20 61 70 69 75 72 6c 2b 2b -XPUT", apiurl++
1160: 73 68 6f 77 20 69 74 65 6d 69 64 2c 20 22 2d 4c show itemid, "-L
1170: 22 2c 20 22 2d 63 22 2c 20 22 68 61 73 6b 65 72 ", "-c", "hasker
1180: 64 65 75 78 2e 63 6f 6f 6b 69 65 73 22 2c 20 22 deux.cookies", "
1190: 2d 62 22 2c 20 22 68 61 73 6b 65 72 64 65 75 78 -b", "haskerdeux
11a0: 2e 63 6f 6f 6b 69 65 73 22 2c 20 22 2d 48 22 2c .cookies", "-H",
11b0: 20 63 75 72 6c 68 65 61 64 65 72 2c 20 22 2d 48 curlheader, "-H
11c0: 22 2c 20 22 43 6f 6e 74 65 6e 74 2d 54 79 70 65 ", "Content-Type
11d0: 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e 2f 6a 73 : application/js
11e0: 6f 6e 22 2c 20 22 2d 64 22 2c 20 6a 73 6f 6e 5d on", "-d", json]
11f0: 20 5b 5d 0a 09 6c 65 74 20 6f 6b 20 3d 20 6e 6f []..let ok = no
1200: 74 20 28 22 49 6e 76 61 6c 69 64 20 43 53 52 46 t ("Invalid CSRF
1210: 20 54 6f 6b 65 6e 22 20 60 69 73 49 6e 66 69 78 Token" `isInfix
1220: 4f 66 60 20 62 6f 64 79 29 0a 09 69 66 20 6f 6b Of` body)..if ok
1230: 0a 09 09 74 68 65 6e 0a 09 09 09 69 66 20 22 64 ...then....if "d
1240: 6f 6e 65 5f 75 70 64 61 74 65 64 5f 61 74 22 20 one_updated_at"
1250: 60 69 73 49 6e 66 69 78 4f 66 60 20 62 6f 64 79 `isInfixOf` body
1260: 0a 09 09 09 09 74 68 65 6e 20 70 75 74 53 74 72 .....then putStr
1270: 4c 6e 20 6f 6b 72 65 73 70 6f 6e 73 65 0a 09 09 Ln okresponse...
1280: 09 09 65 6c 73 65 20 70 75 74 53 74 72 4c 6e 20 ..else putStrLn
1290: 22 55 68 20 4f 68 21 20 44 69 64 6e 27 74 20 77 "Uh Oh! Didn't w
12a0: 6f 72 6b 21 22 0a 09 09 65 6c 73 65 20 64 6f 0a ork!"...else do.
12b0: 09 09 09 74 6f 6b 65 6e 20 3c 2d 20 72 65 6c 6f ...token <- relo
12c0: 67 69 6e 20 0a 09 09 09 63 75 72 6c 70 75 74 20 gin ....curlput
12d0: 28 74 6f 6b 65 6e 2c 20 5b 64 61 74 65 2c 20 6a (token, [date, j
12e0: 73 6f 6e 2c 20 61 70 69 75 72 6c 2c 20 6f 6b 72 son, apiurl, okr
12f0: 65 73 70 6f 6e 73 65 5d 29 20 6e 75 6d 62 65 72 esponse]) number
1300: 0a 0a 0a 67 65 74 61 75 74 68 74 6f 6b 65 6e 20 ...getauthtoken
1310: 62 6f 64 79 20 3d 20 64 6f 0a 09 6c 65 74 20 62 body = do..let b
1320: 6f 64 79 6c 69 6e 65 73 20 3d 20 6c 69 6e 65 73 odylines = lines
1330: 20 62 6f 64 79 0a 09 6c 65 74 20 61 75 74 68 6c body..let authl
1340: 69 6e 65 20 3d 20 64 72 6f 70 57 68 69 6c 65 20 ine = dropWhile
1350: 28 6e 6f 74 20 2e 20 28 22 61 75 74 68 65 6e 74 (not . ("authent
1360: 69 63 69 74 79 5f 74 6f 6b 65 6e 22 20 60 69 73 icity_token" `is
1370: 49 6e 66 69 78 4f 66 60 29 29 20 62 6f 64 79 6c InfixOf`)) bodyl
1380: 69 6e 65 73 0a 09 6c 65 74 20 61 75 74 68 77 6f ines..let authwo
1390: 72 64 73 20 3d 20 77 6f 72 64 73 20 24 20 68 65 rds = words $ he
13a0: 61 64 20 61 75 74 68 6c 69 6e 65 0a 09 6c 65 74 ad authline..let
13b0: 20 61 75 74 68 74 6f 6b 65 6e 77 6f 72 64 20 3d authtokenword =
13c0: 20 73 74 72 69 70 50 72 65 66 69 78 20 22 76 61 stripPrefix "va
13d0: 6c 75 65 3d 5c 22 22 20 24 20 6c 61 73 74 20 61 lue=\"" $ last a
13e0: 75 74 68 77 6f 72 64 73 0a 09 6c 65 74 20 72 65 uthwords..let re
13f0: 76 61 75 74 68 74 6f 6b 65 6e 77 6f 72 64 20 3d vauthtokenword =
1400: 20 72 65 76 65 72 73 65 20 24 20 66 72 6f 6d 4a reverse $ fromJ
1410: 75 73 74 20 61 75 74 68 74 6f 6b 65 6e 77 6f 72 ust authtokenwor
1420: 64 0a 09 6c 65 74 20 61 75 74 68 74 6f 6b 65 6e d..let authtoken
1430: 20 3d 20 72 65 76 65 72 73 65 20 24 20 66 72 6f = reverse $ fro
1440: 6d 4a 75 73 74 20 24 20 73 74 72 69 70 50 72 65 mJust $ stripPre
1450: 66 69 78 20 22 3e 5c 22 22 20 72 65 76 61 75 74 fix ">\"" revaut
1460: 68 74 6f 6b 65 6e 77 6f 72 64 0a 09 72 65 74 75 htokenword..retu
1470: 72 6e 20 61 75 74 68 74 6f 6b 65 6e 0a 0a 0a 6c rn authtoken...l
1480: 6f 67 69 6e 20 20 3d 20 64 6f 0a 09 75 73 65 72 ogin = do..user
1490: 6e 61 6d 65 20 3c 2d 20 66 6d 61 70 20 66 73 74 name <- fmap fst
14a0: 20 72 65 61 64 6e 65 74 72 63 0a 09 70 61 73 73 readnetrc..pass
14b0: 77 6f 72 64 20 3c 2d 20 66 6d 61 70 20 73 6e 64 word <- fmap snd
14c0: 20 72 65 61 64 6e 65 74 72 63 0a 09 68 6f 6d 65 readnetrc..home
14d0: 20 3c 2d 20 67 65 74 48 6f 6d 65 44 69 72 65 63 <- getHomeDirec
14e0: 74 6f 72 79 0a 09 73 61 76 65 64 74 6f 6b 65 6e tory..savedtoken
14f0: 20 3c 2d 20 64 6f 65 73 46 69 6c 65 45 78 69 73 <- doesFileExis
1500: 74 20 28 68 6f 6d 65 20 2b 2b 20 22 2f 2e 68 61 t (home ++ "/.ha
1510: 73 6b 65 72 64 65 75 78 2d 74 6f 6b 65 6e 22 29 skerdeux-token")
1520: 0a 09 69 66 20 73 61 76 65 64 74 6f 6b 65 6e 0a ..if savedtoken.
1530: 09 09 74 68 65 6e 20 64 6f 0a 09 09 09 74 6f 6b ..then do....tok
1540: 65 6e 20 3c 2d 20 72 65 61 64 46 69 6c 65 20 28 en <- readFile (
1550: 68 6f 6d 65 20 2b 2b 20 22 2f 2e 68 61 73 6b 65 home ++ "/.haske
1560: 72 64 65 75 78 2d 74 6f 6b 65 6e 22 29 0a 09 09 rdeux-token")...
1570: 09 72 65 74 75 72 6e 20 74 6f 6b 65 6e 0a 09 09 .return token...
1580: 65 6c 73 65 20 64 6f 0a 09 09 09 62 6f 64 79 20 else do....body
1590: 3c 2d 20 72 65 61 64 50 72 6f 63 65 73 73 20 22 <- readProcess "
15a0: 63 75 72 6c 22 20 5b 22 2d 73 22 2c 20 22 2d 4c curl" ["-s", "-L
15b0: 22 2c 20 22 2d 63 22 2c 20 22 68 61 73 6b 65 72 ", "-c", "hasker
15c0: 64 65 75 78 2e 63 6f 6f 6b 69 65 73 22 2c 20 22 deux.cookies", "
15d0: 68 74 74 70 73 3a 2f 2f 74 65 75 78 64 65 75 78 https://teuxdeux
15e0: 2e 63 6f 6d 2f 6c 6f 67 69 6e 22 5d 20 5b 5d 0a .com/login"] [].
15f0: 09 09 09 74 6f 6b 65 6e 20 3c 2d 20 67 65 74 61 ...token <- geta
1600: 75 74 68 74 6f 6b 65 6e 20 62 6f 64 79 0a 09 09 uthtoken body...
1610: 09 77 72 69 74 65 46 69 6c 65 20 28 68 6f 6d 65 .writeFile (home
1620: 20 2b 2b 20 22 2f 2e 68 61 73 6b 65 72 64 65 75 ++ "/.haskerdeu
1630: 78 2d 74 6f 6b 65 6e 22 29 20 74 6f 6b 65 6e 0a x-token") token.
1640: 09 09 09 6c 65 74 20 63 75 72 6c 68 65 61 64 65 ...let curlheade
1650: 72 20 3d 20 22 58 2d 43 53 52 46 2d 54 6f 6b 65 r = "X-CSRF-Toke
1660: 6e 3a 20 22 20 2b 2b 20 74 6f 6b 65 6e 0a 09 09 n: " ++ token...
1670: 09 6c 65 74 20 63 75 72 6c 70 6f 73 74 66 69 65 .let curlpostfie
1680: 6c 64 73 20 3d 20 22 75 73 65 72 6e 61 6d 65 3d lds = "username=
1690: 22 20 2b 2b 20 75 73 65 72 6e 61 6d 65 20 2b 2b " ++ username ++
16a0: 20 22 26 70 61 73 73 77 6f 72 64 3d 22 20 2b 2b "&password=" ++
16b0: 20 70 61 73 73 77 6f 72 64 20 2b 2b 20 22 26 61 password ++ "&a
16c0: 75 74 68 65 6e 74 69 63 69 74 79 5f 74 6f 6b 65 uthenticity_toke
16d0: 6e 3d 22 20 2b 2b 20 74 6f 6b 65 6e 0a 09 09 09 n=" ++ token....
16e0: 62 6f 64 79 20 3c 2d 20 72 65 61 64 50 72 6f 63 body <- readProc
16f0: 65 73 73 20 22 63 75 72 6c 22 20 5b 22 2d 73 22 ess "curl" ["-s"
1700: 2c 20 22 2d 4c 22 2c 20 22 2d 63 22 2c 20 22 68 , "-L", "-c", "h
1710: 61 73 6b 65 72 64 65 75 78 2e 63 6f 6f 6b 69 65 askerdeux.cookie
1720: 73 22 2c 20 22 2d 62 22 2c 20 22 68 61 73 6b 65 s", "-b", "haske
1730: 72 64 65 75 78 2e 63 6f 6f 6b 69 65 73 22 2c 20 rdeux.cookies",
1740: 22 2d 48 22 2c 20 63 75 72 6c 68 65 61 64 65 72 "-H", curlheader
1750: 2c 20 22 2d 64 22 2c 20 63 75 72 6c 70 6f 73 74 , "-d", curlpost
1760: 66 69 65 6c 64 73 2c 20 22 68 74 74 70 73 3a 2f fields, "https:/
1770: 2f 74 65 75 78 64 65 75 78 2e 63 6f 6d 2f 6c 6f /teuxdeux.com/lo
1780: 67 69 6e 22 5d 20 5b 5d 0a 09 09 09 72 65 74 75 gin"] []....retu
1790: 72 6e 20 74 6f 6b 65 6e 0a 0a 0a 72 65 6c 6f 67 rn token...relog
17a0: 69 6e 20 3d 20 64 6f 0a 09 68 6f 6d 65 20 3c 2d in = do..home <-
17b0: 20 67 65 74 48 6f 6d 65 44 69 72 65 63 74 6f 72 getHomeDirector
17c0: 79 0a 09 72 65 6d 6f 76 65 46 69 6c 65 20 28 68 y..removeFile (h
17d0: 6f 6d 65 20 2b 2b 20 22 2f 2e 68 61 73 6b 65 72 ome ++ "/.hasker
17e0: 64 65 75 78 2d 74 6f 6b 65 6e 22 29 0a 09 74 6f deux-token")..to
17f0: 6b 65 6e 20 3c 2d 20 6c 6f 67 69 6e 0a 09 72 65 ken <- login..re
1800: 74 75 72 6e 20 74 6f 6b 65 6e 0a 09 0a 0a 74 6f turn token....to
1810: 64 6f 73 20 28 74 6f 6b 65 6e 2c 20 5b 74 6f 64 dos (token, [tod
1820: 6f 73 5f 64 61 74 65 5d 29 20 3d 20 64 6f 0a 09 os_date]) = do..
1830: 74 64 73 66 20 3c 2d 20 63 75 72 6c 67 65 74 20 tdsf <- curlget
1840: 28 74 6f 6b 65 6e 2c 20 74 6f 64 6f 73 5f 64 61 (token, todos_da
1850: 74 65 29 0a 09 70 75 74 53 74 72 20 24 20 75 6e te)..putStr $ un
1860: 6c 69 6e 65 73 20 24 20 7a 69 70 57 69 74 68 20 lines $ zipWith
1870: 28 5c 6e 20 74 64 20 2d 3e 20 73 68 6f 77 20 6e (\n td -> show n
1880: 20 2b 2b 20 22 20 2d 20 22 20 2b 2b 20 74 64 29 ++ " - " ++ td)
1890: 20 5b 30 2e 2e 5d 20 24 20 44 61 74 61 2e 4c 69 [0..] $ Data.Li
18a0: 73 74 2e 6d 61 70 20 74 65 78 74 20 74 64 73 66 st.map text tdsf
18b0: 20 2d 2d 6e 75 6d 62 65 72 69 6e 67 20 66 72 6f --numbering fro
18c0: 6d 20 4c 59 41 48 0a 0a 0a 6e 65 77 20 28 74 6f m LYAH...new (to
18d0: 6b 65 6e 2c 20 5b 74 6f 64 6f 73 5f 64 61 74 65 ken, [todos_date
18e0: 2c 20 74 6f 64 6f 5d 29 20 3d 20 64 6f 20 0a 09 , todo]) = do ..
18f0: 6c 65 74 20 65 6e 63 6f 64 65 64 74 6f 64 6f 20 let encodedtodo
1900: 3d 20 4e 65 74 77 6f 72 6b 2e 55 52 49 2e 45 6e = Network.URI.En
1910: 63 6f 64 65 2e 65 6e 63 6f 64 65 20 74 6f 64 6f code.encode todo
1920: 0a 09 63 75 72 6c 70 6f 73 74 20 28 74 6f 6b 65 ..curlpost (toke
1930: 6e 2c 20 5b 74 6f 64 6f 73 5f 64 61 74 65 2c 20 n, [todos_date,
1940: 22 74 65 78 74 22 2c 20 74 6f 64 6f 2c 20 22 68 "text", todo, "h
1950: 74 74 70 73 3a 2f 2f 74 65 75 78 64 65 75 78 2e ttps://teuxdeux.
1960: 63 6f 6d 2f 61 70 69 2f 76 31 2f 74 6f 64 6f 73 com/api/v1/todos
1970: 2f 22 2c 20 22 41 64 64 65 64 21 22 5d 29 20 4e /", "Added!"]) N
1980: 6f 74 68 69 6e 67 0a 0a 0a 63 72 6f 73 73 6f 66 othing...crossof
1990: 66 20 28 74 6f 6b 65 6e 2c 20 5b 74 6f 64 6f 73 f (token, [todos
19a0: 5f 64 61 74 65 2c 20 6e 75 6d 62 65 72 5d 29 20 _date, number])
19b0: 3d 0a 09 63 75 72 6c 70 75 74 20 28 74 6f 6b 65 =..curlput (toke
19c0: 6e 2c 20 5b 74 6f 64 6f 73 5f 64 61 74 65 2c 20 n, [todos_date,
19d0: 22 7b 20 5c 22 64 6f 6e 65 5c 22 3a 20 74 72 75 "{ \"done\": tru
19e0: 65 20 7d 22 2c 20 22 68 74 74 70 73 3a 2f 2f 74 e }", "https://t
19f0: 65 75 78 64 65 75 78 2e 63 6f 6d 2f 61 70 69 2f euxdeux.com/api/
1a00: 76 31 2f 74 6f 64 6f 73 2f 22 2c 20 22 43 72 6f v1/todos/", "Cro
1a10: 73 73 65 64 20 4f 66 66 21 22 5d 29 20 6e 75 6d ssed Off!"]) num
1a20: 62 65 72 0a 0a 0a 70 75 74 6f 66 66 20 28 74 6f ber...putoff (to
1a30: 6b 65 6e 2c 20 5b 74 6f 64 6f 73 5f 64 61 74 65 ken, [todos_date
1a40: 2c 20 6e 75 6d 62 65 72 5d 29 20 3d 20 64 6f 0a , number]) = do.
1a50: 09 6c 65 74 20 74 6f 6d 6f 72 72 6f 77 73 5f 64 .let tomorrows_d
1a60: 61 74 65 20 3d 20 73 68 6f 77 20 28 61 64 64 44 ate = show (addD
1a70: 61 79 73 20 31 20 24 20 72 65 61 64 20 74 6f 64 ays 1 $ read tod
1a80: 6f 73 5f 64 61 74 65 3a 3a 44 61 74 61 2e 54 69 os_date::Data.Ti
1a90: 6d 65 2e 44 61 79 29 0a 09 63 75 72 6c 70 6f 73 me.Day)..curlpos
1aa0: 74 20 28 74 6f 6b 65 6e 2c 20 5b 74 6f 64 6f 73 t (token, [todos
1ab0: 5f 64 61 74 65 2c 20 22 63 75 72 72 65 6e 74 5f _date, "current_
1ac0: 64 61 74 65 22 2c 20 74 6f 6d 6f 72 72 6f 77 73 date", tomorrows
1ad0: 5f 64 61 74 65 2c 20 22 68 74 74 70 73 3a 2f 2f _date, "https://
1ae0: 74 65 75 78 64 65 75 78 2e 63 6f 6d 2f 61 70 69 teuxdeux.com/api
1af0: 2f 76 31 2f 74 6f 64 6f 73 2f 72 65 70 6f 73 69 /v1/todos/reposi
1b00: 74 69 6f 6e 2f 22 2c 20 22 50 75 74 20 4f 66 66 tion/", "Put Off
1b10: 21 22 5d 29 20 28 4a 75 73 74 20 6e 75 6d 62 65 !"]) (Just numbe
1b20: 72 29 0a 0a 0a 6d 6f 76 65 74 6f 20 28 74 6f 6b r)...moveto (tok
1b30: 65 6e 2c 20 5b 74 6f 64 6f 73 5f 64 61 74 65 2c en, [todos_date,
1b40: 20 6e 75 6d 62 65 72 2c 20 6e 65 77 5f 64 61 74 number, new_dat
1b50: 65 5d 29 20 3d 0a 09 2d 2d 54 4f 44 4f 3a 20 4e e]) =..--TODO: N
1b60: 65 65 64 20 74 6f 20 66 69 67 75 72 65 20 6f 75 eed to figure ou
1b70: 74 20 6d 6f 76 69 6e 67 20 74 6f 20 62 6f 74 74 t moving to bott
1b80: 6f 6d 20 6f 66 20 61 20 6c 69 73 74 0a 09 63 75 om of a list..cu
1b90: 72 6c 70 6f 73 74 20 28 74 6f 6b 65 6e 2c 20 5b rlpost (token, [
1ba0: 74 6f 64 6f 73 5f 64 61 74 65 2c 20 22 63 75 72 todos_date, "cur
1bb0: 72 65 6e 74 5f 64 61 74 65 22 2c 20 6e 65 77 5f rent_date", new_
1bc0: 64 61 74 65 2c 20 22 68 74 74 70 73 3a 2f 2f 74 date, "https://t
1bd0: 65 75 78 64 65 75 78 2e 63 6f 6d 2f 61 70 69 2f euxdeux.com/api/
1be0: 76 31 2f 74 6f 64 6f 73 2f 72 65 70 6f 73 69 74 v1/todos/reposit
1bf0: 69 6f 6e 22 2c 20 22 4d 6f 76 65 64 21 22 5d 29 ion", "Moved!"])
1c00: 20 28 4a 75 73 74 20 6e 75 6d 62 65 72 29 0a 0a (Just number)..
1c10: 0a 72 65 6d 6f 76 65 20 28 74 6f 6b 65 6e 2c 20 .remove (token,
1c20: 5b 74 6f 64 6f 73 5f 64 61 74 65 2c 20 6e 75 6d [todos_date, num
1c30: 62 65 72 5d 29 20 3d 0a 09 63 75 72 6c 64 65 6c ber]) =..curldel
1c40: 65 74 65 20 28 74 6f 6b 65 6e 2c 20 5b 74 6f 64 ete (token, [tod
1c50: 6f 73 5f 64 61 74 65 2c 20 22 68 74 74 70 73 3a os_date, "https:
1c60: 2f 2f 74 65 75 78 64 65 75 78 2e 63 6f 6d 2f 61 //teuxdeux.com/a
1c70: 70 69 2f 76 31 2f 74 6f 64 6f 73 2f 22 2c 20 22 pi/v1/todos/", "
1c80: 44 65 6c 65 74 65 64 21 22 5d 29 20 6e 75 6d 62 Deleted!"]) numb
1c90: 65 72 0a 0a 0a 2d 2d 54 68 61 6e 6b 73 20 74 6f er...--Thanks to
1ca0: 20 68 74 74 70 3a 2f 2f 77 77 77 2e 61 6d 61 74 http://www.amat
1cb0: 65 75 72 74 6f 70 6f 6c 6f 67 69 73 74 2e 63 6f eurtopologist.co
1cc0: 6d 2f 62 6c 6f 67 2f 32 30 31 30 2f 31 31 2f 30 m/blog/2010/11/0
1cd0: 35 2f 61 2d 68 61 73 6b 65 6c 6c 2d 6e 65 77 62 5/a-haskell-newb
1ce0: 69 65 73 2d 67 75 69 64 65 2d 74 6f 2d 74 65 78 ies-guide-to-tex
1cf0: 74 2d 6a 73 6f 6e 2f 20 61 6e 64 20 68 74 74 70 t-json/ and http
1d00: 3a 2f 2f 68 70 61 73 74 65 2e 6f 72 67 2f 34 31 ://hpaste.org/41
1d10: 32 36 33 2f 70 61 72 73 69 6e 67 5f 6a 73 6f 6e 263/parsing_json
1d20: 5f 77 69 74 68 5f 74 65 78 74 6a 73 6f 6e 0a 64 _with_textjson.d
1d30: 61 74 61 20 54 65 75 78 64 65 75 78 20 3d 20 54 ata Teuxdeux = T
1d40: 65 75 78 64 65 75 78 20 7b 0a 20 20 20 20 69 64 euxdeux {. id
1d50: 20 3a 3a 20 49 6e 74 65 67 65 72 2c 0a 09 63 75 :: Integer,..cu
1d60: 72 72 65 6e 74 5f 64 61 74 65 20 3a 3a 20 53 74 rrent_date :: St
1d70: 72 69 6e 67 2c 20 0a 09 74 65 78 74 20 3a 3a 20 ring, ..text ::
1d80: 53 74 72 69 6e 67 2c 0a 09 64 6f 6e 65 20 3a 3a String,..done ::
1d90: 20 42 6f 6f 6c 0a 7d 20 64 65 72 69 76 69 6e 67 Bool.} deriving
1da0: 20 28 45 71 2c 20 53 68 6f 77 2c 20 44 61 74 61 (Eq, Show, Data
1db0: 2c 20 54 79 70 65 61 62 6c 65 29 20 0a 0a 2d 2d , Typeable) ..--
1dc0: 41 6e 6f 74 68 65 72 20 64 61 74 61 20 74 79 70 Another data typ
1dd0: 65 20 68 65 72 65 20 70 72 6f 62 61 62 6c 79 20 e here probably
1de0: 66 6f 72 20 6c 69 73 74 73 0a 0a for lists..