Stability | Experimental |
---|---|
Maintainer | Tom Lokhorst <tom@lokhorst.eu> |
This module exposes several functions and data types to send feeds to Twitter.
- data Config = Config {}
- type Tweet = String
- type GUID = String
- atom2twitter :: Config -> (Entry -> Tweet) -> IO ()
- rss2twitter :: Config -> (RSSItem -> Tweet) -> IO ()
- item2twitter :: Config -> (Either Entry RSSItem -> Tweet) -> IO ()
- feed2twitter :: Config -> (Feed -> [(GUID, Tweet)]) -> IO ()
- trunc4tweet :: String -> String
- trunc4url :: String -> String
Types
Configuration data for the feed2twitter
function.
Represents a single tweet. In principle this should be <= 140 characters, however, because Twitter uses a url-shortener, a tweet containing a url may exeed this limit.
A unique identifier for a Tweet. Values of this type are stored in the cache file to make sure no duplicate messages are sent to Twitter.
Convenient user functions
atom2twitter :: Config -> (Entry -> Tweet) -> IO ()Source
Sends an Atom feed to Twitter by using user-provided mapping function for individual entries.
This is a specialized version of item2twitter
.
rss2twitter :: Config -> (RSSItem -> Tweet) -> IO ()Source
Sends a RSS feed to Twitter by using user-provided mapping function for individual items.
This is a specialized version of item2twitter
.
item2twitter :: Config -> (Either Entry RSSItem -> Tweet) -> IO ()Source
Sends feed items to Twitter by using user-provided mapping function for individual items.
Defined in terms of feed2twitter
.
Main function
feed2twitter :: Config -> (Feed -> [(GUID, Tweet)]) -> IO ()Source
Function that does all the heavy lifting:
- Downloads the feed provided in the config value.
- Calls the provided user-function to map feed to a list of guids and tweets.
- Filters out already posted tweets using guid cache.
- Sends each tweet to Twitter and writes its guid to cache file.
- Truncate cache file to size provided in config value.
User-function is responsible for generating guids for tweets and the order of tweets.
Util functions
trunc4tweet :: String -> StringSource
Truncates a string to 140 characters for a tweet.
When input is longer than 140 characters, puts an ellipsis at the end.
trunc4url :: String -> StringSource
Truncates a string to 120 characters, leaving room for a space and a url. Due to Twitter using a url-shortener, urls are assumed to max 20 characters.
When input is shorter than 120 characters, returns it with a space, otherwise truncates and puts an ellipsis and space at the end.