Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Clean up and correct comments |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/issue1 | trunk | master |
Files: | files | file ages | folders |
SHA3-256: |
97901a5951ecaa7100c7a415deb68ae3 |
User & Date: | base@atomicules.co.uk 2016-12-04 15:49:36 |
Context
2016-12-04
| ||
15:56 | Enable response on delete, forgot about this check-in: a09dcdd1f3 user: base@atomicules.co.uk tags: master, origin/issue1, trunk | |
15:49 | Clean up and correct comments check-in: 97901a5951 user: base@atomicules.co.uk tags: master, origin/issue1, trunk | |
15:43 | Be consistent with how isInfixOf is used check-in: bec4f0a542 user: base@atomicules.co.uk tags: master, origin/issue1, trunk | |
Changes
Changes to haskerdeux.hs.
︙ | ︙ | |||
52 53 54 55 56 57 58 | where getcred c = dropWhile (not . (c `isInfixOf`)) (words $ head netrc') !! 1 return (username, password) curlget (token, todays_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="++todays_date++"&end_date="++todays_date] [] | < < | < < < | > < < < < < < < > < < < > < | 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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | where getcred c = dropWhile (not . (c `isInfixOf`)) (words $ head netrc') !! 1 return (username, password) curlget (token, todays_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="++todays_date++"&end_date="++todays_date] [] let tds = decodeJSON body :: [Teuxdeux] let tdsf = Data.List.filter (\td -> current_date td == todays_date && not (done td)) tds return tdsf curlpost (token, [todays_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, todays_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\" : \""++todays_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, [todays_date, apiurl, okresponse]) number = do tdsf <- curlget (token, todays_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] [] return() -- TODO: what does the response say? -- if respCurlCode resp == CurlOK && respStatus resp == 200 -- then putStrLn okresponse -- else putStrLn "Uh Oh! Didn't work!" curlput (token, [todays_date, json, apiurl, okresponse]) number = do tdsf <- curlget (token, todays_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!" getauthtoken body = do let bodylines = lines body let authline = dropWhile (not . ("authenticity_token" `isInfixOf`)) bodylines let authwords = words $ head authline let authtokenword = stripPrefix "value=\"" $ last authwords let revauthtokenword = reverse $ fromJust authtokenword let authtoken = reverse $ fromJust $ stripPrefix ">\"" revauthtokenword return authtoken login [username, password] = do --See if we have a token, then to clear we can just delete the file --TODO: handle that error home <- getHomeDirectory check <- doesFileExist (home ++ "/.haskerdeux-token") if check then readFile (home ++ "/.haskerdeux-token") else do body <- readProcess "curl" ["-s", "-L", "-c", "haskerdeux.cookies", "https://teuxdeux.com/login"] [] token <- getauthtoken body |
︙ | ︙ | |||
146 147 148 149 150 151 152 | 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 | < | 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | 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]) = curlput (token, [todays_date, "{ \"done\": true }", "https://teuxdeux.com/api/v1/todos/", "Crossed Off!"]) number |
︙ | ︙ |