Last active
January 31, 2022 12:08
-
-
Save apraga/401babdb7bd81872fbf13e9f3240d121 to your computer and use it in GitHub Desktop.
Todotxt -> taswarrior for done.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List.Split | |
import Data.Time | |
import Data.Time.Clock.POSIX | |
import Data.Maybe | |
import Control.Monad | |
import qualified Data.Text as T | |
import qualified Data.Text.IO as TIO | |
import Data.UUID | |
import Data.UUID.V4 | |
data Task = Task { | |
description :: T.Text, | |
date :: T.Text, | |
project :: T.Text, | |
uuid :: T.Text | |
} | |
-- As the task is already done, the creation and end date are the same | |
showTask (Task descr d p u) = T.concat [ "[description:\"" , descr , "\" " | |
, "due:\"" , d , "\" " | |
, "end:\"" , d , "\" " | |
, "entry:\"" , d , "\" " | |
, "modified:\"" , d , "\" " | |
, "project:\"" , p , "\" " | |
, "status:\"completed\" " | |
, "uuid:\"" , u , "\"]"] | |
convert :: (T.Text, UUID) -> Task | |
convert (x, u) = Task (T.strip o) date' proj' (T.pack $ show u) | |
where | |
(others, proj) = T.breakOn "+" x | |
proj' = T.replace "+" "" . T.strip $ proj | |
(date, o) = T.breakOn " " others | |
date' = T.pack . init . show $ toSeconds date -- Remove "s" at the end | |
toSeconds x = utcTimeToPOSIXSeconds time | |
where | |
time = UTCTime (fromJust day) hour | |
day = parseTimeM True defaultTimeLocale "%Y-%m-%d" (T.unpack x) :: Maybe Day | |
hour = timeOfDayToTime (TimeOfDay 14 0 0) | |
main = do | |
x <- TIO.readFile "done.txt" | |
let x' = T.lines x | |
uuids <- replicateM (length x') nextRandom | |
let tasks = map convert $ zip x' uuids | |
let s = T.unlines . map showTask $ tasks | |
TIO.writeFile "completed2.data" s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment