internaut / zweischlagzeilen

A Twitter-Bot that mixes recent headlines of leading German newspapers.

Home Page:http://www.mkonrad.net/projects/zweischlagzeilen.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zweischlagzeilen Project -- ZwoSchlagzeilen Twitter-Bot

@ZwoSchlagzeilen ist ein Twitter-Bot, der Schlagzeilen großer deutscher Nachrichtenportale verquirlt und stündlich postet. Er generiert im besten Fall so etwas wie "Fast Richtige Schlagzeilen" (Titanic). Im Grunde genommen ist es die deutsche Variante für das amerikanische Vorbild @TwoHeadlines.

--

@ZwoSchlagzeilen is a Twitter-Bot that mixes recent headlines of leading German newspapers and posts one of them each hour. Sometimes it produces funny results. It is basically the German variant for the American archetype @TwoHeadlines.

How does it work?

The script works quite simple. Basically, it uses feedparser to fetch the headlines of several RSS newsfeeds of German newspaper websites. Then, it randomly selects one headline as "seed headline". An trigram language model is built from all but the seed headline. The seed headline is cut at a random point so that only up to the first half of it is used as seed input for generating a random sequence of words from the trigram model. This sequence of words is the randomly generated headline that is posted to the Twitter account using tweepy.

Requirements

The script has been tested with Python 3.8 to 3.10.

The following Python packages need to be installed -- all are available via PyPI:

"conf.py" is not in the repository. You will need to create a file "conf.py" with the following content:

TWITTER_CONSUMER_KEY = '...'
TWITTER_CONSUMER_SECRET = '...'
TWITTER_ACCESS_KEY = '...'
TWITTER_ACCESS_SECRET = '...'

# cut out the following substrings from headlines:
CUT_SUBSTRINGS = (
    u'*** BREAKING NEWS ***',
)

# location where to store previously fetched headlines
HEADLINES_COLLECTION = os.path.join('data', 'headlines.json')

# timeout in seconds when fetching a newsfeed
FEED_FETCH_TIMEOUT = 15

# how long to keep headlines
KEEP_DAYS = 28

# which ngram model to use
NGRAMS_N = 3

About

A Twitter-Bot that mixes recent headlines of leading German newspapers.

http://www.mkonrad.net/projects/zweischlagzeilen.html

License:MIT License


Languages

Language:Python 100.0%