Created
April 27, 2013 14:47
-
-
Save tobiassjosten/5473378 to your computer and use it in GitHub Desktop.
This file contains 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
-- http://sumedh.info/articles/importing-comments-disqus-xml-database.php | |
import Control.Monad | |
import Database.HDBC | |
import Database.HDBC.MySQL | |
main = | |
do conn <- connectMySQL defaultMySQLConnectInfo { | |
mysqlHost = "localhost", | |
mysqlDatabase = "tobiassjosten", | |
mysqlUser = "tobiassjosten", | |
mysqlPassword = "tobiassjosten", | |
mysqlUnixSocket = "/var/run/mysqld/mysqld.sock" | |
} | |
getArticles conn | |
articleQuery = "SELECT id,title,slug,created_at FROM article" | |
commentQuery id = "SELECT id,name,email,website,created_at,body FROM comment WHERE article_id = " ++ id | |
getArticles conn = | |
do articles <- quickQuery' conn articleQuery [] | |
forM_ articles $ \article -> do comments <- getComments conn article | |
putStrLn $ putArticle article comments | |
getComments conn article = quickQuery' conn (commentQuery $ fromSql $ head article) [] | |
putArticle :: [SqlValue] -> [[SqlValue]] -> String | |
putArticle article comments | |
| length comments == 0 = "" | |
| otherwise = "<item>" ++ articleMarkup article ++ commentsMarkup comments ++ "</item>" | |
articleMarkup :: [SqlValue] -> String | |
articleMarkup article = fromSql $ head article | |
commentsMarkup :: [[SqlValue]] -> String | |
commentsMarkup comments = foldr ((++) . commentMarkup) [] comments | |
commentMarkup :: [SqlValue] -> String | |
commentMarkup comment = "|" ++ (fromSql $ head comment) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment