-import qualified TSN.Injuries as Injuries (
- Listing,
- Message ( listings ) )
-import qualified TSN.InjuriesDetail as InjuriesDetail (
- Listing ( player_listings ),
- Message ( listings ),
- PlayerListing )
-
-
-
--- | A list of options passed to 'readDocument' when we parse an XML
--- document. We don't validate because the DTDs from TSN are
--- wrong. As a result, we don't want to keep useless DTDs
--- areound. Thus we disable 'withSubstDTDEntities' which, when
--- combined with "withValidate no", prevents HXT from trying to read
--- the DTD at all.
---
-parse_opts :: SysConfigList
-parse_opts =
- [ withPreserveComment no,
- withRemoveWS yes,
- withSubstDTDEntities no,
- withValidate no ]
-
-
--- | We put the 'XmlTree' argument last so that it's easy to eta
--- reduce all of the import_foo functions that call this.
---
-import_generic :: (XmlPickler a, PersistEntity b)
- => b -- ^ Dummy Listing instance needed for 'migrate'
- -> (a -> [b]) -- ^ listings getter
- -> XmlTree
- -> IO ()
-import_generic dummy g xml =
- withSqliteConn "foo.sqlite3" $ runDbConn $ do
- runMigration defaultMigrationLogger $ do
- migrate dummy
- let root_element = unpickleDoc xpickle xml
- case root_element of
- Nothing -> let msg = "Could not unpickle document in import_generic."
- in liftIO $ report_error msg
- Just elt -> mapM_ (\l -> insert l) (g elt)
-
--- | Import TSN.Injuries from an 'XmlTree'.
-import_injuries :: XmlTree -> IO ()
-import_injuries =
- import_generic
- (undefined :: Injuries.Listing)
- Injuries.listings
-
--- | Import TSN.InjuriesDetail from an 'XmlTree'.
-import_injuries_detail :: XmlTree -> IO ()
-import_injuries_detail =
- import_generic
- (undefined :: InjuriesDetail.PlayerListing)
- ( (concatMap InjuriesDetail.player_listings) . InjuriesDetail.listings)
-
-import_file :: FilePath -> IO ()
-import_file path = do
- report_info $ "Attempting to import " ++ path ++ "."
- results <- runX $ readA >>> (doctypeA &&& returnA) >>> (arr import_with_dtd)
+import TSN.DbImport
+import qualified TSN.Injuries as Injuries ( Listing )
+import qualified TSN.InjuriesDetail as InjuriesDetail ( PlayerListing )
+import qualified TSN.News as News ( Message )
+import Xml ( parse_opts )
+
+
+
+import_file :: Configuration -> FilePath -> IO ()
+import_file cfg path = do
+ results <- catchIOError
+ parse_and_import
+ (\e -> do
+ report_error (show e)
+ report_error $ "Failed to import file " ++ path ++ "."
+ -- Return a nonempty list so we don't claim incorrectly that
+ -- we couldn't parse the DTD.
+ return [ Nothing ] )
+