예제 #1
0
파일: entries.py 프로젝트: drcraig/skim
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
예제 #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 []
예제 #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
예제 #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'
예제 #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 []
예제 #6
0
파일: crawl.py 프로젝트: drcraig/skim
def entry_file(feed_url, entry, filename, mode):
    with open_file_from(entry_directory(feed_url, entry), filename, mode) as f:
        yield f
예제 #7
0
파일: crawl.py 프로젝트: drcraig/skim
def feed_file(feed_url, filename, mode):
    with open_file_from(feed_directory(feed_url), filename, mode) as f:
        yield f