Step 1: Setup [Python]

First, import Flask, a web framework that provides you with a set of tools for building simple, lightweight web applications. You’ll need this library to respond to requests sent to our website.

from flask import Flask, render_template

Next, import Python’s Feedparser, which will let you access reddit’s RSS feed. If you don’t have it, you need to install the pip package.

import feedparser

Finally, import indico’s Text Tags API.

from indicoio import text_tags

Once you’ve imported everything, just set up your app to work with Flask.

app = Flask(_name_)
app.debug = True

Step 2: Categorization and Setting Thresholds [Python]

This step allows you to determine the flexibility of your application. Before you begin setting your threshold though, you need to define the feed you’ll be accessing. We’ll be using reddit in this particular case, but you can substitute it with any RSS feed of your choice.

feed = "http://www.reddit.com/.rss"

Now you’ll need to define a series of functions for processing the results from the RSS feed. We’ve broken it up this way so that it’s easier to make sense of what’s going on.

Use the likely_tag function to set the threshold to your personal tastes — if you want to have a broader definition of a category, for instance everything that is even tangentially related to technology, you can change your threshold from 0.1 to 0.05. If you want it to be more specific, set your threshold higher to something like 0.5.

The max function will return the tag with the highest probability. The key argument within it tells the max function which value to use to compare tags — in this case, the probability output by the Text Tags API.

This next function examines the content returned by feedparser, categorizes it, and then uses the values from the Text Tags API to determine whether or not the tag should be kept. It will remove anything outside of the threshold that you’ve set.

The app.route call is a bit of Flask logic which lets the webserver know it should run the main function. The batch_text_tags function allows you to send over multiple examples in a single request so that you get results from the indico API quickly.

The hashChanged function is triggered when you click a link that takes you to a hash URL. The function will pass in the text that occurs after the hash and filter your feed to contain only articles from that category.