importfeed: Filename template can now contain an itempubdate variable. Needs feed 0.3.9.2.

This commit is contained in:
Joey Hess 2014-04-07 16:55:04 -04:00
parent 5b503e4458
commit 836f2cc816
7 changed files with 24 additions and 4 deletions

View file

@ -15,6 +15,8 @@ import Text.Feed.Types
import qualified Data.Set as S
import qualified Data.Map as M
import Data.Time.Clock
import Data.Time.Format
import System.Locale
import Common.Annex
import qualified Annex
@ -212,6 +214,7 @@ feedFile tmpl i extension = Utility.Format.format tmpl $ M.fromList
, fieldMaybe "itemdescription" $ getItemDescription $ item i
, fieldMaybe "itemrights" $ getItemRights $ item i
, fieldMaybe "itemid" $ snd <$> getItemId (item i)
, fieldMaybe "itempubdate" $ pubdate $ item i
, ("extension", sanitizeFilePath extension)
]
where
@ -221,6 +224,12 @@ feedFile tmpl i extension = Utility.Format.format tmpl $ M.fromList
fieldMaybe k Nothing = (k, "none")
fieldMaybe k (Just v) = field k v
pubdate itm = case getItemPublishDate itm :: Maybe (Maybe UTCTime) of
Just (Just d) -> Just $
formatTime defaultTimeLocale "%F" d
-- if date cannot be parsed, use the raw string
_ -> replace "/" "-" <$> getItemPublishDateString itm
{- Called when there is a problem with a feed.
- Throws an error if the feed is broken, otherwise shows a warning. -}
feedProblem :: URLString -> String -> Annex ()

7
debian/changelog vendored
View file

@ -1,3 +1,10 @@
git-annex (5.20140406) UNRELEASED; urgency=medium
* importfeed: Filename template can now contain an itempubdate variable.
Needs feed 0.3.9.2.
-- Joey Hess <joeyh@debian.org> Mon, 07 Apr 2014 16:22:02 -0400
git-annex (5.20140405) unstable; urgency=medium
* git-annex-shell: Added notifychanges command.

2
debian/control vendored
View file

@ -55,7 +55,7 @@ Build-Depends:
libghc-xml-types-dev,
libghc-async-dev,
libghc-http-dev,
libghc-feed-dev,
libghc-feed-dev (>= 0.3.9.2),
libghc-regex-tdfa-dev [!mipsel !s390],
libghc-regex-compat-dev [mipsel s390],
libghc-tasty-dev (>= 0.7) [!mipsel !sparc],

View file

@ -268,7 +268,7 @@ subdirectories).
Use `--template` to control where the files are stored.
The default template is '${feedtitle}/${itemtitle}${extension}'
(Other available variables: feedauthor, itemauthor, itemsummary, itemdescription, itemrights, itemid)
(Other available variables: feedauthor, itemauthor, itemsummary, itemdescription, itemrights, itemid, itempubdate)
The `--relaxed` and `--fast` options behave the same as they do in addurl.

View file

@ -23,7 +23,8 @@ there's a --template option. The default is
`--template='${feedtitle}/${itemtitle}${extension}'`
Other available template variables:
feedauthor, itemauthor, itemsummary, itemdescription, itemrights, itemid
feedauthor, itemauthor, itemsummary, itemdescription, itemrights, itemid,
itempubdate
## catching up

View file

@ -13,3 +13,6 @@ or
that "works" but is ugly :)
Would love to be able to put a YYYYMMDD at the beginning and then the title.
> [[done]]; itempubdate will use form YYYY-MM-DD (or the raw date string
> if the feed does not use a parsable form). --[[Joey]]

View file

@ -210,7 +210,7 @@ Executable git-annex
CPP-Options: -DWITH_DNS
if flag(Feed)
Build-Depends: feed
Build-Depends: feed (>= 0.3.9.2)
CPP-Options: -DWITH_FEED
if flag(Quvi)