HaskerDeux

Check-in [bec4f0a542]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Be consistent with how isInfixOf is used
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/issue1 | trunk | master
Files: files | file ages | folders
SHA3-256: bec4f0a542ae966de3c9815a109910b35df5428511fa0c37e7fe873cfc60094a
User & Date: base@atomicules.co.uk 2016-12-04 15:43:56
Context
2016-12-04
15:49
Clean up and correct comments check-in: 97901a5951 user: base@atomicules.co.uk tags: origin/issue1, trunk, master
15:43
Be consistent with how isInfixOf is used check-in: bec4f0a542 user: base@atomicules.co.uk tags: origin/issue1, trunk, master
15:09
hlint changes

- Duplication between curldelete and curlput still exists, but I think is
legitimate.
- Also, I'm really not sure use of Control.Applicative makes
it any more readable, but I'll go with it.
- Would also be nice if I could get all the isInfixOf the same check-in: 6b4d755c96 user: base@atomicules.co.uk tags: origin/issue1, trunk, master

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to haskerdeux.hs.

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
		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 . isInfixOf "teuxdeux") 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 . isInfixOf c) (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 opts1 = [] 
................................................................................
	--just check body contains stuff?
	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 . isInfixOf "authenticity_token") bodylines
	let authwords = words $ head authline
	let authtokenword = stripPrefix "value=\"" $ last authwords
	let revauthtokenword = reverse $ fromJust authtokenword
	let authtoken = reverse $ fromJust $ stripPrefix ">\"" revauthtokenword
	--home <- getHomeDirectory
	--putStrLn authtoken
	--writeFile (home ++ "/.haskerdeux-token") authtoken







|





|







 







|







39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
...
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
		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, 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 opts1 = [] 
................................................................................
	--just check body contains stuff?
	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
	--home <- getHomeDirectory
	--putStrLn authtoken
	--writeFile (home ++ "/.haskerdeux-token") authtoken