morss/README.md

261 lines
11 KiB
Markdown
Raw Permalink Normal View History

2013-09-15 15:59:17 +00:00
#Morss - Get full-text RSS feeds
2013-02-25 15:40:51 +00:00
This tool's goal is to get full-text RSS feeds out of striped RSS feeds,
commonly available on internet. Indeed most newspapers only make a small
description available to users in their rss feeds, which makes the RSS feed
rather useless. So this tool intends to fix that problem.
2013-02-25 20:49:38 +00:00
This tool opens the links from the rss feed, then downloads the full article
from the newspaper website and puts it back in the rss feed.
Morss also provides additional features, such as: .csv and json export, extended
control over output. A strength of morss is its ability to deal with broken
feeds, and to replace tracking links with direct links to the actual content.
Morss can also generate feeds from html and json files (see `feedify.py`), which
for instance makes it possible to get feeds for Facebook or Twitter, using
hand-written rules (ie. there's no automatic detection of links to build feeds).
Please mind that feeds based on html files may stop working unexpectedly, due to
html structure changes on the target website.
Additionally morss can grab the source xml feed of iTunes podcast, and detect
rss feeds in html pages' `<meta>`.
You can use this program online for free at **[morss.it](http://morss.it/)**
(there's also a [test](http://test.morss.it/) version).
##Dependencies
You do need:
2015-04-07 11:01:41 +00:00
- [python](http://www.python.org/) >= 2.6 (python 3 is supported)
- [lxml](http://lxml.de/) for xml parsing
2013-10-12 21:43:09 +00:00
- [dateutil](http://labix.org/python-dateutil) to parse feed dates
- [html2text](http://www.aaronsw.com/2002/html2text/)
2015-08-29 10:32:40 +00:00
- [OrderedDict](https://pypi.python.org/pypi/ordereddict) if using python &lt; 2.7
2017-03-09 01:25:45 +00:00
- [wheezy.template](https://pypi.python.org/pypi/wheezy.template) to generate HTML pages
2017-03-08 21:45:13 +00:00
- [chardet](https://pypi.python.org/pypi/chardet)
Simplest way to get these:
pip install -r requirements.txt
You may also need:
- Apache, with python-cgi support, to run on a server
- a fast internet connection
2013-06-19 19:16:46 +00:00
GPL3 code.
##Arguments
morss accepts some arguments, to lightly alter the output of morss. Arguments
may need to have a value (usually a string or a number). In the different "Use
cases" below is detailed how to pass those arguments to morss.
The arguments are:
- Change what morss does
- `json`: output as JSON
- `proxy`: doesn't fill the articles
- `clip`: stick the full article content under the original feed content (useful for twitter)
- `keep`: by default, morss does drop feed description whenever the full-content is found (so as not to mislead users who use Firefox, since the latter only shows the description in the feed preview, so they might believe morss doens't work), but with this argument, the description is kept
2014-11-07 09:20:33 +00:00
- `search=STRING`: does a basic case-sensitive search in the feed
- Advanced
2014-01-12 23:16:58 +00:00
- `csv`: export to csv
- `md`: convert articles to Markdown
- `indent`: returns indented XML or JSON, takes more place, but human-readable
2014-06-16 12:00:02 +00:00
- `nolink`: drop links, but keeps links' inner text
- `noref`: drop items' link
- `hungry`: grab full-article even if it already looks long enough
- `cache`: only take articles from the cache (ie. don't grab new articles' content), so as to save time
- `debug`: to have some feedback from the script execution. Useful for debugging
- `mono`: disable multithreading while fetching, makes debugging easier
2015-02-20 17:58:16 +00:00
- `theforce`: force download the rss feed and ignore cached http errros
- `silent`: don't output the final RSS (useless on its own, but can be nice when debugging)
2016-01-31 12:53:01 +00:00
- `encoding=ENCODING`: overrides the encoding auto-detection of the crawler. Some web developers did not quite understand the importance of setting charset/encoding tags correctly...
- http server only
2014-06-27 22:59:57 +00:00
- `callback=NAME`: for JSONP calls
- `cors`: allow Cross-origin resource sharing (allows XHR calls from other servers)
- `html`: changes the http content-type to html, so that python cgi erros (written in html) are readable in a web browser
- `txt`: changes the http content-type to txt (for faster "`view-source:`")
2014-11-07 09:20:33 +00:00
- Completely useless
- `strip`: remove all description and content from feed items
- `empty`: remove all feed items
2013-06-19 19:16:46 +00:00
##Use cases
2013-04-28 09:37:11 +00:00
morss will auto-detect what "mode" to use.
###Running on a server
####Via mod_cgi/FastCGI with Apache/nginx
For this, you'll want to change a bit the architecture of the files, for example
into something like this.
2013-02-25 20:49:38 +00:00
```
/
├── cgi
│   │
│   ├── main.py
│   ├── morss
│   │   ├── __init__.py
│   │   ├── __main__.py
│   │   ├── morss.py
│   │   └── ...
│   │
│   ├── dateutil
│   └── ...
├── .htaccess
├── index.html
└── ...
```
For this, you need to make sure your host allows python script execution. This
method uses HTTP calls to fetch the RSS feeds, which will be handled through
`mod_cgi` for example on Apache severs.
Please pay attention to `main.py` permissions for it to be executable. Also
ensure that the provided `/www/.htaccess` works well with your server.
####Using uWSGI
Running this command should do:
uwsgi --http :9090 --plugin python --wsgi-file main.py
However, one problem might be how to serve the provided `index.html` file if it
isn't in the same directory. Therefore you can add this at the end of the
command to point to another directory `--pyargv '--root ../../www/'`.
####Using morss' internal HTTP server
Morss can run its own HTTP server. The later should start when you run morss
without any argument, on port 8080.
You can change the port and the location of the `www/` folder like this `python -m morss 9000 --root ../../www`.
####Passing arguments
Then visit: **`http://PATH/TO/MORSS/[main.py/][:argwithoutvalue[:argwithvalue=value[...]]]/FEEDURL`**
For example: `http://morss.example/:clip/https://twitter.com/pictuga`
*(Brackets indicate optional text)*
The `main.py` part is only needed if your server doesn't support the Apache redirect rule set in the provided `.htaccess`.
Works like a charm with [Tiny Tiny RSS](http://tt-rss.org/redmine/projects/tt-rss/wiki), and most probably other clients.
###As a CLI application
Run: **`python[2.7] -m morss [argwithoutvalue] [argwithvalue=value] [...] FEEDURL`**
For example: `python -m morss debug http://feeds.bbci.co.uk/news/rss.xml`
*(Brackets indicate optional text)*
###As a newsreader hook
To use it, the newsreader [Liferea](http://lzone.de/liferea/) is required
(unless other newsreaders provide the same kind of feature), since custom
scripts can be run on top of the RSS feed, using its
[output](http://lzone.de/liferea/scraping.htm) as an RSS feed.
To use this script, you have to enable "(Unix) command" in liferea feed settings, and use the command: **`[python2.7] PATH/TO/MORSS/main.py [argwithoutvalue] [argwithvalue=value] [...] FEEDURL`**
For example: `python2.7 PATH/TO/MORSS/main.py http://feeds.bbci.co.uk/news/rss.xml`
*(Brackets indicate optional text)*
###As a python library
2014-05-24 17:03:05 +00:00
Quickly get a full-text feed:
```python
>>> import morss
2014-05-24 17:14:12 +00:00
>>> xml_string = morss.process('http://feeds.bbci.co.uk/news/rss.xml')
2014-05-24 17:03:05 +00:00
>>> xml_string[:50]
"<?xml version='1.0' encoding='UTF-8'?>\n<?xml-style"
```
2014-05-24 17:14:12 +00:00
Using cache and passing arguments:
2014-05-24 17:03:05 +00:00
```python
>>> import morss
>>> url = 'http://feeds.bbci.co.uk/news/rss.xml'
>>> cache = '/tmp/morss-cache.db' # sqlite cache location
2014-06-27 22:58:37 +00:00
>>> options = {'csv':True, 'md':True}
2014-05-24 17:03:05 +00:00
>>> xml_string = morss.process(url, cache, options)
>>> xml_string[:50]
'{"title": "BBC News - Home", "desc": "The latest s'
```
`morss.process` is actually a wrapper around simpler function. It's still
possible to call the simpler functions, to have more control on what's happening
under the hood.
2014-05-24 17:03:05 +00:00
Doing it step-by-step:
```python
import morss, morss.crawler
2014-05-21 13:05:35 +00:00
url = 'http://newspaper.example/feed.xml'
2014-06-27 22:58:37 +00:00
options = morss.Options(csv=True, md=True) # arguments
morss.crawler.sqlite_default = '/tmp/morss-cache.db' # sqlite cache location
2017-03-09 01:17:40 +00:00
rss = morss.FeedFetch(url, options) # this only grabs the RSS feed
rss = morss.FeedGather(rss, url, options) # this fills the feed and cleans it up
2014-11-08 19:32:34 +00:00
output = morss.Format(rss, options) # formats final feed
```
##Cache information
morss uses a small cache directory to make the loading faster. Given the way
it's designed, the cache doesn't need to be purged each while and then, unless
you stop following a big amount of feeds. Only in the case of mass un-subscribing,
you might want to delete the cache files corresponding to the bygone feeds. If
morss is running as a server, the cache folder is at `MORSS_DIRECTORY/cache/`,
and in `$HOME/.cache/morss` otherwise.
##Configuration
2013-04-04 16:31:26 +00:00
###Length limitation
When parsing long feeds, with a lot of items (100+), morss might take a lot of
time to parse it, or might even run into a memory overflow on some shared
hosting plans (limits around 10Mb), in which case you might want to adjust the
different values at the top of the script.
2013-05-23 19:48:45 +00:00
- `MAX_TIME` sets the maximum amount of time spent *fetching* articles, more time might be spent taking older articles from cache. `-1` for unlimited.
- `MAX_ITEM` sets the maximum number of articles to fetch. `-1` for unlimited. More articles will be taken from cache following the nexts settings.
- `LIM_TIME` sets the maximum amount of time spent working on the feed (whether or not it's already cached). Articles beyond that limit will be dropped from the feed. `-1` for unlimited.
- `LIM_ITEM` sets the maximum number of article checked, limiting both the number of articles fetched and taken from cache. Articles beyond that limit will be dropped from the feed, even if they're cached. `-1` for unlimited.
###Other settings
- `DELAY` sets the browser cache delay, only for HTTP clients
- `TIMEOUT` sets the HTTP timeout when fetching rss feeds and articles
- `THREADS` sets the number of threads to use. `1` makes no use of multithreading.
###Content matching
The content of articles is grabbed with our own readability fork. This means
that most of the time the right content is matched. However sometimes it fails,
therefore some tweaking is required. Most of the time, what has to be done is to
add some "rules" in the main script file in *readability* (not in morss).
2013-03-29 19:05:53 +00:00
Most of the time when hardly nothing is matched, it means that the main content
of the article is made of images, videos, pictures, etc., which readability
doesn't detect. Also, readability has some trouble to match content of very
small articles.
2013-04-04 16:31:26 +00:00
morss will also try to figure out whether the full content is already in place
(for those websites which understood the whole point of RSS feeds). However this
detection is very simple, and only works if the actual content is put in the
"content" section in the feed and not in the "summary" section.
2013-04-04 16:31:26 +00:00
2013-06-19 19:16:46 +00:00
***
##Todo
You can contribute to this project. If you're not sure what to do, you can pick
from this list:
- Add ability to run morss.py as an update daemon
2015-05-04 14:23:08 +00:00
- Add ability to use custom xpath rule instead of readability