Example #1
0
def full_entry(feed_slug, entry_slug):
    feed_dir = join(STORAGE_ROOT, 'feeds', feed_slug)
    entry_dir = join(feed_dir, entry_slug)

    with open_file_from(feed_dir, 'feed.json', 'r') as feed_file, \
         open_file_from(entry_dir, 'entry.json', 'r') as entry_file, \
         open_file_from(entry_dir, 'entry.html', 'r') as entry_html:

        entry = json.load(entry_file)
        entry['published'] = datetime_from_iso(entry['published'])
        entry['feed'] = json.load(feed_file)
        entry['feed']['slug'] = feed_slug
        entry['body'] = entry_html.read()
        return entry
Example #2
0
def subscriptions():
    by_url = {}
    try:
        with open_file_from(STORAGE_ROOT, 'subscriptions.opml', 'rb') as f:
            for category, title, feed_url in opml_feeds(f):
                if feed_url not in by_url:
                    by_url[feed_url] = {
                        'url': feed_url,
                        'slug': slug(feed_url),
                        'title': title,
                        'categories': []
                    }

                    entry_count, first_entry, latest_entry = feed_stats(feed_url)
                    by_url[feed_url].update({
                        'entry_count': entry_count,
                        'first_entry': first_entry,
                        'latest_entry': latest_entry
                    })
                by_url[feed_url]['categories'].append(category)
        return sorted(by_url.values(), key=lambda s: s['slug'])
    except OSError:
        return []
Example #3
0
def test_open_from_file_does_not_exist():
    directory = tempfile.mkdtemp()
    with pytest.raises(FileNotFoundError):
        with open_file_from(os.path.join(directory), 'hello', mode='r') as f:
            pass  # pragma: no cover
Example #4
0
def test_open_from_directory_exists():
    directory = tempfile.mkdtemp()
    with open_file_from(os.path.join(directory), 'hello', mode='w') as f:
        f.write('world')
    with open(os.path.join(directory, 'hello'), 'r') as f:
        assert f.read() == 'world'
Example #5
0
def subscription_urls():
    try:
        with open_file_from(STORAGE_ROOT, 'subscriptions.opml', 'rb') as f:
            return list(unique(feed_url for _, _, feed_url in opml_feeds(f)))
    except OSError:
        return []
Example #6
0
def entry_file(feed_url, entry, filename, mode):
    with open_file_from(entry_directory(feed_url, entry), filename, mode) as f:
        yield f
Example #7
0
def feed_file(feed_url, filename, mode):
    with open_file_from(feed_directory(feed_url), filename, mode) as f:
        yield f