Skip to content

Instantly share code, notes, and snippets.

@MichaelBlume
Last active January 3, 2016 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MichaelBlume/8426725 to your computer and use it in GitHub Desktop.
Save MichaelBlume/8426725 to your computer and use it in GitHub Desktop.
Transforms gchat logs into tumblr chat posts
#!/usr/bin/env runhaskell
module Main (main) where
-- When you copy a conversation out of your google chat logs, it looks like
-- this
--
-- Alice
-- hi
-- how are you
-- Bob Smith
-- pretty well
-- I made the most amazing sandwich
--
-- but if you were going to paste the same conversation into tumblr (and you're
-- alice) you'd want something like
--
-- Me: hi
-- Me: how are you
-- Bob: pretty well
-- Bob: I made the most amazing sandwich
--
-- This script manages the conversion! Call it like so
--
-- cat chat_log | ./Chat Alice Me "Bob Smith" Bob
import Data.Map as Map
import System.Environment as Env
type Names = Map.Map String String
translateLines :: Names -> String -> [String] -> [String]
translateLines names = f where
f _ [] = []
f currentName (l : ls) = case Map.lookup l names of
Just newName -> f newName ls
Nothing -> (currentName ++ ": " ++ l) : (f currentName ls)
translateChat :: Names -> String -> String
translateChat names = unlines . translateLines names defName . lines where
defName = error "top line must be a name"
packNames :: [String] -> Names
packNames [] = empty
packNames (k:v:ns) = insert k v $ packNames ns
main = interact . translateChat . packNames =<< Env.getArgs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment