HaskerDeux

Check-in [9a429ebc79]
Login

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

Overview
Comment:Hlint changes

Had to hlint on another computer... cannot get it to install on NetBSD

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/issue1 | trunk | master
Files: files | file ages | folders
SHA3-256: 9a429ebc7950936b3ec6ed9fd09dddabadc1dcc508f61e7ba50b0672b729cda3
User & Date: atomicules 2020-05-15 11:56:32
Context
2020-08-11
07:24
Change order of commands

All because it bugged me typing:

haskerdeux today moveto 1 2020-08-25

I.e. it just didn't scan well. I suppose I could just have reworded that as
"move", but I thought it'd be "fun" to be able to do this:

haskerdeux today 1 moveto 2020-08-25

The only problem with this is that parsing the arguments was much easier when
the first one was a date and the second the command. Now we have the second
argument sometimes being the command and sometimes being a number:

haskerdeux today new "New thing todo" haskerdeux today 1 moveto 2020-08-25

Anyway, this solves it with a bit of parsing and re-arranging up front and then
passes things through as before. I removed the `when` clause as it was entirely
redudant (well, it offered a more graceful/silent failure if it couldn't parse
the command line args, but that's it) check-in: 3cee74c3f9 user: atomicules tags: master, origin/issue1, trunk

2020-05-15
11:56
Hlint changes

Had to hlint on another computer... cannot get it to install on NetBSD check-in: 9a429ebc79 user: atomicules tags: master, origin/issue1, trunk

08:29
Handle any case of short day: Mon, mon, MON, etc.

Just because it'll be easier for me to use lowercase. check-in: 386fcc875a user: atomicules tags: master, origin/issue1, trunk

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to haskerdeux.hs.

34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
	                | (Data.List.map toLower date) `elem` ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] = parseday ((Data.List.map toLower date), todays_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)


parseday (future_day, todays_date) = do
	let days_map = fromList
		[ ("mon", 0)







|

|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
	                | Data.List.map toLower date `elem` ["mon", "tue", "wed", "thu", "fri", "sat", "sun"] = parseday (Data.List.map toLower date, todays_date)
	                | otherwise = date
	when (((command == "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)


parseday (future_day, todays_date) = do
	let days_map = fromList
		[ ("mon", 0)
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
login  = do
	username <- fmap fst readnetrc
	password <- fmap snd readnetrc
	home <- getHomeDirectory
	savedtoken <- doesFileExist (home ++ "/.haskerdeux-token")
	let cookies = home ++ "/haskerdeux.cookies"
	if savedtoken
		then do
			token <- readFile (home ++ "/.haskerdeux-token")
			return token
		else do
			body <- readProcess "curl" ["-s", "-L", "-c", cookies, "https://teuxdeux.com/login"] []
			token <- getauthtoken body
			writeFile (home ++ "/.haskerdeux-token") token
			let curlheader = "X-CSRF-Token: " ++ token
			let curlpostfields = "username=" ++ username ++ "&password=" ++ password ++ "&authenticity_token=" ++ token
			body <- readProcess "curl" ["-s", "-L", "-c", cookies, "-b", cookies, "-H", curlheader, "-d", curlpostfields, "https://teuxdeux.com/login"] []
			return token


relogin = do
	home <- getHomeDirectory
	removeFile (home ++ "/.haskerdeux-token")
	token <- login
	return token
	

todos (token, [todos_date]) = do
	tdsf <- curlget (token, todos_date)
	putStr $ unlines $ zipWith (\n td -> show n ++ " - " ++ td) [0..] $ Data.List.map text tdsf --numbering from LYAH


new (token, [todos_date, todo]) = do 







|
|
<













|
<
|







169
170
171
172
173
174
175
176
177

178
179
180
181
182
183
184
185
186
187
188
189
190
191

192
193
194
195
196
197
198
199
login  = do
	username <- fmap fst readnetrc
	password <- fmap snd readnetrc
	home <- getHomeDirectory
	savedtoken <- doesFileExist (home ++ "/.haskerdeux-token")
	let cookies = home ++ "/haskerdeux.cookies"
	if savedtoken
		then
			readFile (home ++ "/.haskerdeux-token")

		else do
			body <- readProcess "curl" ["-s", "-L", "-c", cookies, "https://teuxdeux.com/login"] []
			token <- getauthtoken body
			writeFile (home ++ "/.haskerdeux-token") token
			let curlheader = "X-CSRF-Token: " ++ token
			let curlpostfields = "username=" ++ username ++ "&password=" ++ password ++ "&authenticity_token=" ++ token
			body <- readProcess "curl" ["-s", "-L", "-c", cookies, "-b", cookies, "-H", curlheader, "-d", curlpostfields, "https://teuxdeux.com/login"] []
			return token


relogin = do
	home <- getHomeDirectory
	removeFile (home ++ "/.haskerdeux-token")
	login



todos (token, [todos_date]) = do
	tdsf <- curlget (token, todos_date)
	putStr $ unlines $ zipWith (\n td -> show n ++ " - " ++ td) [0..] $ Data.List.map text tdsf --numbering from LYAH


new (token, [todos_date, todo]) = do 
242
243
244
245
246
247
248
249
    id :: Integer,
	current_date :: String, 
	text :: String,
	done :: Bool
} deriving (Eq, Show, Data, Typeable) 

--Another data type here probably for lists








<
240
241
242
243
244
245
246

    id :: Integer,
	current_date :: String, 
	text :: String,
	done :: Bool
} deriving (Eq, Show, Data, Typeable) 

--Another data type here probably for lists