Package: trackthenews
Track The Newstrackthenewsis the script that powers@FOIAfeed, a Twitter bot that monitors news outlets for reporting that incorporates public records laws like the Freedom of Information Act (FOIA), and tweets links to and excerpts from matching articles. The underlying software can track any collection of RSS feeds for any keywords.If you want to run your own instance oftrackthenews, you can download and install the package, and run its built-in configuration process. It can be installed withpip:Python 3.9 is what we currently test against, though it may work with other versions.pip3installtrackthenewsor by cloning the GitHub repository and runningsetup.py:python3setup.pyinstallOnce it is installed, you can create a configuration by running the following command in the appropriate directory:trackthenews--configBy default, the script will place all configuration files in a newttnconfigfolder in your current working directory, but you can also designate a directory for it to use.python3trackthenews--config~/foo/bar/pathThat configuration process will create the necessary files and walk you through setting up a Twitter bot for matching stories. After it is configured, you'll need to use a text editor to add thematchwordsand RSS feeds to their respective files.Sample RSS feed and matchword files can be found in the project's GitHub repo. The RSS feed file is a JSON array of objects corresponding to each feed. Each object requires aurlfield, and should also have anoutletfield.The next two fields are optional: if you know the feed uses redirect URLs, you may setredirectLinkstotrueand the script will attempt to follow those redirects to store and tweet canonical URLs; if the feed uses URLs that depend on query- or hash-strings to display correctly—basically, if the content relies on text in the URL bar after a?or#—you can setdelicateURLstotrueand the script will leave the URLs exactly as is.Once you've got everything set up, you can run the program without the--configflag to check for matching articles.trackthenewsIf you designated a custom installation directory, or if you're running it from another directory (or acronjob, for example) you will need to designate the directory in which the configuration files are installed.trackthenews~/foo/bar/pathSettings, such as the background color for new posts, the font, and the user-agent, are all located inconfig.yaml, in the designated configuration directory.How it worksMost of the script is dedicated to theArticleclass.Articles are created based on inputs. Currently those inputs are RSS feeds, which are stored inrssfeeds.json, but in future versions other inputs will include direct URLs, news APIs, Twitter feeds, or scraped pages.A series ofArticlemethods then scrape and isolate the contents of each article (currently that cleanup is done with aPython port of Readability, but future versions may incorporate some per-site parsing), check whether it's suitable for posting, and then prepare images for tweeting.Finally, theArticletweets itself.All articles are recorded in a sqlite database.Advanced feature: blocklistIn some cases, you may wish to suppress articles from being posted, even though they would otherwise match. You can do so by writing a new function,check, and placing it in a file namedblocklist.pyin the configuration directory.checktakes an Article (and so has access to itsoutlet,title, andurl) and should returntruefor any article that should be skipped.LicenseMIT.