Skip to content

Commit 7a5a626

Browse files
committed
Restructured into package; added setup.py; changed location of my_bonds.yaml to ~/.ppserve/
1 parent a4d663a commit 7a5a626

19 files changed

+50
-12
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include ppserve/templates/*

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The currency and `clean_or_dirty` may be omitted (currency defaults to the argum
1212

1313
## Configuration
1414

15-
A file `my_bonds.yaml` in the script directory can be used to preconfigure bonds (e.g. if some of the data is not available from the price source).
15+
A file `my_bonds.yaml` in `~/.ppserve/` can be used to preconfigure bonds (e.g. if some of the data is not available from the price source).
1616
This is mostly useful for providing missing information needed for accrued interest computation.
1717
The format is as follows:
1818

@@ -27,6 +27,12 @@ The format is as follows:
2727
...
2828
```
2929

30+
## Installation
31+
32+
Installation is done by running `python setup.py install --user` (skip `--user` to install system-wide).
33+
This installs a binary called `ppserve`.
34+
Check `ppserve -h` to see command line options.
35+
3036
## Dependencies
3137

3238
[`BeautifulSoup`](https://www.crummy.com/software/BeautifulSoup/) for scraping, [`bottle`](http://bottlepy.org/docs/dev/) for serving HTML, [`coloredlogs`](https://pypi.org/project/coloredlogs/) for fancy output, [`CurrencyConverter`](https://pypi.org/project/CurrencyConverter/) for currency conversion.

bin/ppserve

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env python3
2+
3+
import ppserve
4+
ppserve.main()

ppserve/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .ppserve import main

my_bonds.py ppserve/my_bonds.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
from datetime import date
2-
from price_sources.securities import Bond
3-
from price_sources import ArivaPriceSource
1+
from .price_sources.securities import Bond
2+
from .price_sources import ArivaPriceSource
43

54
import logging
65
logger = logging.getLogger('my_bonds')
76

87
import yaml
98
from pathlib import Path
109

11-
script_path = Path(__file__).parent/'my_bonds.yaml'
10+
yaml_file = Path.home()/'.ppserve'/'my_bonds.yaml'
1211

1312
try:
14-
data = yaml.load(open(script_path, 'r').read())
13+
logger.info('Found configuration in {}'.format(str(yaml_file)))
14+
data = yaml.load(open(yaml_file, 'r').read())
1515
except FileNotFoundError:
16+
logger.info('No my_bonds.yaml found.')
1617
data = {}
1718

1819
# Sanitize symbols; they may be of integer type if entered without quotes

ppserve.py ppserve/ppserve.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
from bottle import route, run, SimpleTemplate, abort, redirect, template
2929
from threading import Thread
3030

31-
from price_sources import ArivaPriceSource
32-
from price_sources.securities import Bond
31+
from .price_sources import ArivaPriceSource
32+
from .price_sources.securities import Bond
3333

3434
import logging
3535
import coloredlogs
@@ -38,7 +38,7 @@
3838
coloredlogs.install(level=getattr(logging, args.log_level))
3939

4040
logger.info('Loading manually configured securities.')
41-
from my_bonds import my_bonds
41+
from .my_bonds import my_bonds
4242

4343
template_path = Path(__file__).parent/"templates"
4444
portfolio_performance_template = SimpleTemplate(
@@ -129,8 +129,7 @@ def update_sec_prices(sec):
129129
sec.update_historic(start_date, date.today())
130130
sec.write_quotes()
131131

132-
if __name__ == "__main__":
133-
132+
def main():
134133
try:
135134
Thread(
136135
target=run, name="price server",
@@ -154,3 +153,6 @@ def update_sec_prices(sec):
154153

155154
except KeyboardInterrupt:
156155
sys.exit()
156+
157+
if __name__ == "__main__":
158+
main()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

price_sources/securities/security.py ppserve/price_sources/securities/security.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def price_history(self): return self._price_history
9191

9292
@property
9393
def _quotes_path(self):
94-
return Path(__file__).parent/'quotes'/(self.symbol + '.quotes')
94+
return Path.home()/'.ppserve'/'quotes'/(self.symbol + '.quotes')
9595

9696
def write_quotes(self, path=None):
9797
if path is None:
File renamed without changes.
File renamed without changes.

setup.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from setuptools import setup
2+
3+
setup(name='ppserve',
4+
description='Serves prices of financial securities fetched from the internet in a format that Portfolio Performance understands',
5+
version='0.1',
6+
url='https://github.com/fberg/ppserve',
7+
author='Franz Berger',
8+
license='GPL-3',
9+
packages=[
10+
'ppserve',
11+
'ppserve.price_sources',
12+
'ppserve.price_sources.securities'
13+
],
14+
scripts=['bin/ppserve'],
15+
install_requires=[
16+
'PyYAML',
17+
'bs4',
18+
'coloredlogs',
19+
'bottle',
20+
'CurrencyConverter'
21+
],
22+
include_package_data=True
23+
)

0 commit comments

Comments
 (0)