feed2twitter-0.2.0: Send posts from a feed to Twitter

StabilityExperimental
MaintainerTom Lokhorst <tom@lokhorst.eu>

Web.Feed2Twitter

Contents

Description

This module exposes several functions and data types to send feeds to Twitter.

Synopsis

Types

data Config Source

Configuration data for the feed2twitter function.

Instances

type Tweet = StringSource

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.

type GUID = StringSource

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.