58 mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info |
58 mapM_ (run dbConn dbQueryAchievement) $ (parseStats fileName teams) info |
59 |
59 |
60 parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]] |
60 parseStats :: B.ByteString -> [(B.ByteString, B.ByteString)] -> [B.ByteString] -> [[SqlValue]] |
61 parseStats fileName teams = ps |
61 parseStats fileName teams = ps |
62 where |
62 where |
|
63 ps [] = [] |
63 ps ("DRAW" : bs) = ps bs |
64 ps ("DRAW" : bs) = ps bs |
64 ps ("WINNERS" : n : bs) = ps $ drop (readInt_ n) bs |
65 ps ("WINNERS" : n : bs) = ps $ drop (readInt_ n) bs |
65 ps ("ACHIEVEMENT" : typ : teamname : location : value : bs) = |
66 ps ("ACHIEVEMENT" : typ : teamname : location : value : bs) = |
66 [SqlByteString typ |
67 [SqlByteString typ |
67 , SqlByteString $ fromMaybe "" (lookup teamname teams) |
68 , SqlByteString $ fromMaybe "" (lookup teamname teams) |
68 , SqlInt32 (readInt_ value) |
69 , SqlInt32 (readInt_ value) |
69 , SqlByteString fileName |
70 , SqlByteString fileName |
70 , SqlByteString location |
71 , SqlByteString location |
71 ] : ps bs |
72 ] : ps bs |
|
73 ps (b:bs) = ps bs |
|
74 |
72 |
75 |
73 dbConnectionLoop mySQLConnectionInfo = |
76 dbConnectionLoop mySQLConnectionInfo = |
74 Control.Exception.handle (\(e :: IOException) -> hPutStrLn stderr $ show e) $ handleSqlError $ |
77 Control.Exception.handle (\(e :: IOException) -> hPutStrLn stderr $ show e) $ handleSqlError $ |
75 bracket |
78 bracket |
76 (connectMySQL mySQLConnectionInfo) |
79 (connectMySQL mySQLConnectionInfo) |