Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

foreign PR from boeddeker #10

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a20a88c
changed database to class style, for ensureing that the filename is c…
boeddeker Mar 20, 2016
3dc8530
Bugfix: removed termfeed.support in setup.py
boeddeker Mar 20, 2016
9a4e005
Bugfix: import was wrong
boeddeker Mar 20, 2016
9e075e3
add dependencies: 'plumbum', 'arrow'
boeddeker Mar 20, 2016
2846cfa
changed database backend from shelve to json
boeddeker Mar 20, 2016
a02d09c
replaced colors with plumbum, show all feed at the same time, show time
boeddeker Mar 20, 2016
0262142
Bugfix: some self's where missing
boeddeker Mar 20, 2016
d071cc7
append options: -b -> -b [<category>] shows the deeds from <category>
boeddeker Mar 20, 2016
587d4cb
add option to load library from file and print library to stdout
boeddeker Mar 20, 2016
64c0937
Update README.md
boeddeker Mar 20, 2016
750185b
start with change docopt and click and change database backend struct
boeddeker Mar 23, 2016
7576d27
new: dev: add cached-property package
rachmadaniHaryono Mar 23, 2017
36e5f4e
new: dev: add __main__ file.
rachmadaniHaryono Mar 23, 2017
920274c
fix: dev: fix UnboundLocalError on file var
rachmadaniHaryono Mar 24, 2017
e0437bc
chg: dev: add option to create json setting
rachmadaniHaryono Mar 24, 2017
356c2b1
chg: usr: exit when no rss found
rachmadaniHaryono Mar 24, 2017
f81b534
Merge branch 'rachmadaniHaryono-feature/py3-fix'
boeddeker Mar 24, 2017
6e61cee
pep8
boeddeker Mar 24, 2017
2a88946
bumpversion patch
boeddeker Mar 24, 2017
4b52387
gitignore
boeddeker Mar 24, 2017
917d9be
revert some changes
boeddeker Mar 24, 2017
855e2de
test
boeddeker Mar 24, 2017
3103c21
makefile
boeddeker Mar 24, 2017
ffd7c05
add example db.yaml
boeddeker Mar 24, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[bumpversion]
current_version = 0.0.12
commit = False
tag = False

[bumpversion:file:setup.py]

[bumpversion:file:termfeed/feed.py]

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,6 @@ docs/_build/

# PyBuilder
target/

#IDE's
.idea/
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


help:
cat Makefile

install:
pip install .

.PHONY: tests
tests:
nosetests tests/

feed:
python -m feed

bumpversion_patch:
bumpversion patch

bumpversion_minor:
bumpversion minor

bumpversion_mayor:
bumpversion mayor
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,31 @@ To read, preview, open, store, or delete your favorite RSS feeds from the comman

If 1) you are a terminal addict, and 2) you want to stay up to date with the outside world by reading quick feed and summaries WITHOUT having to leave your terminal; then TermFeed is for you. These are the main reasons I created TermFeed.

# Changes agains original

```Usage: feed [OPTIONS] COMMAND [ARGS]...

Options:
-l, --label TEXT
-n, --dry-run
-v, --verbose Levels: -v:INFO, -vvv:DEBUG
-h, --help Show this message and exit.

Commands:
add
browse
edit
load
remove
show
```

Config file is a termdeef/db.yaml
Modifications are made to support git repos.



# Old Readme

### Usage

Expand All @@ -24,9 +48,9 @@ If 1) you are a terminal addict, and 2) you want to stay up to date with the out
- browse latest feed from the single link `<RSS-LINK>` provided.
- e.g. `$ feed https://news.ycombinator.com/rss`

`$ feed -b`
`$ feed -b [<category>]`

- browse latest feeds by category of your library.
- browse latest feeds by <category> of your library. If <category> is missing select input appear.

`$ feed -t`

Expand All @@ -51,9 +75,9 @@ If 1) you are a terminal addict, and 2) you want to stay up to date with the out
`$ feed -D <category>`
- Remove entire category (with its URLs) from library.

`$ feed -R`
`$ feed -R [<file>]`

- rebuild the library from `urls.py`
- rebuild the library. Default `rss.yaml`


### Features (what you can do?)
Expand Down
18 changes: 13 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,23 @@

setup(
name='TermFeed',
description=('Browse, read, and open your favorite rss feed in the terminal (without curses).'),
description=(
'Browse, read, and open your favorite rss feed in the terminal (without curses).'),
author='Aziz Alto',
url='https://github.com/iamaziz/TermFeed',
download_url='https://github.com/iamaziz/TermFeed/archive/master.zip',
license = "MIT",
license="MIT",
author_email='[email protected]',
version='0.0.11',
install_requires=['feedparser'],
packages=['termfeed', 'termfeed.support'],
version='0.0.12',
install_requires=[
'feedparser',
'pyyaml',
'docopt',
'plumbum',
'arrow',
'cached-property>=1.3.0',
],
packages=['termfeed'],
scripts=[],
entry_points={
'console_scripts': [
Expand Down
8 changes: 8 additions & 0 deletions termfeed/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from .feed import main

if __name__ == '__main__':

main()
198 changes: 198 additions & 0 deletions termfeed/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-

"""
database operations.

database.py manipulate database add, update, delete
"""

import yaml, json, re
from plumbum import local
from plumbum import colors as c
from os import path
from cached_property import cached_property
from pathlib import Path
import logging
logger = logging.getLogger(__name__)

log_info = logger.info
log_debug = logger.debug


class DataBase:

file = local.env.home / '.termfeed.json'
__data = None
dry_run = False

@cached_property
def data(self):
# The following will only called once
log_info('Load library')
if not self.__data:
if not self.file.exists():
file = local.path(__file__).dirname / 'db.yaml'
if not file.exists():
raise FileNotFoundError(file)
with open(file, 'r') as f:
log_info('Open yaml')
return yaml.load(f)
else:
with open(self.file, 'r') as f:
log_info('Open json')
self.__data = json.load(f)
return self.__data.copy() # ensure copy, for comp in __del__

# def set_data(self, data):
# verify_data(data)
# self.__data = data
# del self.data
# with self:
# pass

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
# type, value, traceback
verify_data(self.data)
if not self.dry_run:
print('Backup changed library in {}.'.format(self.file))
with open(self.file, 'w') as f:
json.dump(self.data, f)
log_info('Write to json')
log_debug(json.dumps(self.data))
log_debug(self.as_yaml)
else:
print('Normaly would write the following to file {}: '.format(self.file))
print(c.highlight | c.black | json.dumps(self.data))

debug_flag = False

@property
def labels(self):
labels = set()
for _, val in self.data.items():
labels |= set(val['label'])
return labels

@property
def as_yaml(self):
return yaml.dump(self.data) # , default_flow_style=False

def link_for_label(self, *labels):
return [link for link, val in self.data.items() if any(True for l in labels if l in val['label'])]

@property
def links(self):
return self.data.keys()

def browse_links(self, label):
if label in self.labels:
links = self(label)
print('{} resources:'.format(label))
for link in links:
print('\t{}'.format(link))
else:
print('no category named {}'.format(label))
print(self)

def __str__(self):
out = 'available lables: \n\t' + '\n\t'.join(self.labels)
return(out)

def print_labels(self):
print(self)

def link_as_yaml(self, link):
return yaml.dump({link:self.data[link]})

def add_link(self, link, *labels, flag = None, title=''):
if link not in self.data:
if not flag:
flag = []
template = dict(title=title, flag=flag, label=list(labels))
self.data[link] = verify_entry(template, link)
print('Added:')
print(self.link_as_yaml(link))
if logger.level <= logging.INFO:
print(self.as_yaml)
elif not title == '' or not title == self.data[link]['title']:
self.data[link]['label'] = list(set(self.data[link]['label']) | set(labels))
self.data[link]['title'] = title
log_info('Title has changed')
print(self.as_yaml)

elif set(labels) | set(self.data[link]['label']) == set(self.data[link]['label']):
print('{} already exists and has all labels: {}!!'.format(link, labels))
print(self.as_yaml)
else:
self.data[link]['label'] = list(set(self.data[link]['label']) | set(labels))
# print('Created new category .. {}'.format(topic))
print(self.link_as_yaml(link))
if logger.level <= logging.INFO:
print(self.as_yaml)

def remove_link(self, link):
done = False
if link in self.data:
del self.data[link]
print('removed: {}'.format(link))
else:
print('URL not found: {}'.format(link))

def delete_topic(self, label):
if label == '':
print('Default topic "General" cannot be removed.')
exit()
try:
for link in self.data:
if label in self.data[link]['label']:
self.data[link]['label'] = list(set(self.data[link]['label']) - set(label))
print('Removed "{}" from your library.'.format(label))
except KeyError:
print('"{}" is not in your library!'.format(label))
exit()


def verify_entry(entry, link):
allowed_keys = {'label', 'flag', 'title'}
if not entry:
entry = dict()
if not (entry.keys() | allowed_keys) == allowed_keys:
print('The url {} has invalid keys: '.format(link), entry)
exit()
if not isinstance(entry.setdefault('title', ''), str):
print('The url {} has invalid title member: {}'.format(link, entry['title']))
exit()
if not isinstance(entry.setdefault('flag', []), list):
print('The url {} has invalid flag type: {}'.format(link, entry['flag']))
exit()
if not all([isinstance(f, str) for f in entry['flag']]):
print('The url {} has invalid flag member: {}'.format(link, entry['flag']))
exit()
if not isinstance(entry.setdefault('label', []), list):
print('The url {} has invalid flag type: {}'.format(link, entry['label']))
exit()
if not all([isinstance(l, str) for l in entry['label']]):
print('The url {} has invalid flag member: {}'.format(link, entry['label']))
exit()
return entry


def verify_data(data):
for link in data:
data[link] = verify_entry(data[link], link)

# if __name__ == '__main__':

# for l in read('News'):
# print(l)

# remove_link('http://rt.com/rss/')

# add_link('http://rt.com/rss/', 'News')

# for l in read('News'):
# print(l)
13 changes: 13 additions & 0 deletions termfeed/db.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
https://github.com/boeddeker/TermFeed/commits/master.atom:
flag: [git, github]
label: [github]
title: TermFeed
https://github.com/boeddeker/TermFeed/commits/master.atom:
flag: [git, github]
label: [github]
title: TermFeed
http://blog.jupyter.org/rss/:
flag: []
label: [github]
title: blog.jupyter

21 changes: 0 additions & 21 deletions termfeed/dbinit.py

This file was deleted.

Loading