https://github.com/buzzfeed/python-operative
Python bridge for Operative
https://github.com/buzzfeed/python-operative
Last synced: about 1 year ago
JSON representation
Python bridge for Operative
- Host: GitHub
- URL: https://github.com/buzzfeed/python-operative
- Owner: buzzfeed
- License: mit
- Created: 2013-08-19T16:39:43.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-07-21T19:52:57.000Z (over 11 years ago)
- Last Synced: 2025-01-08T22:43:11.310Z (about 1 year ago)
- Language: Python
- Size: 277 KB
- Stars: 0
- Watchers: 269
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
python-operative
=========
**python-operative** is a very light-weight Python bridge to the Operative FTP flatfile system.
Setup
-----
Setup virtualenv:
```
$ mkvirtualenv --distribute python-operative
$ workon python-operative
```
Run installation script:
```
$ python setup.py install
```
Testing
-------
There are two options for running the tests.
If you prefer not to test using a live FTP endpoint, then you can use the caliendo cache instead.
###Using Live FTP endpoint
Copy default settings file:
```
cp operative/settings.py.default operative/settings.py
```
Update the settings.py file with your own FTP credentials
###Using caliendo cache
Set caliendo env vars:
```
$ export USE_CALIENDO=True
$ export CALIENDO_CACHE_PREFIX=/absolute/path/to/caliendo/dir
```
Run tests:
```
$ python setup.py nosetests
```
Usage
-----
Using **python-operative** to retrieve data from an Operative flatfile report is very straightforward.
First step is to define an FTPCredentials object:
```python
import operative
FTP_LOGIN_DICT = {
'host': ,
'port': ,
'username': ,
'password': }
ftp_creds = operative.FTPCredentials(**FTP_LOGIN_DICT)
```
From there you can pull an array of Report objects:
```python
import datetime
from operative.reports.line_item_report import LineItemReport
since = datetime.datetime.today() - datetime.timedelta(days=1)
path = '/flatfile'
line_item_reports = LineItemReport().get_report_files(ftp_credentials=ftp_creds, ftp_path=path, since=since)
```
Each Report object has a 'data' array attribute that represents the rows in the report.
Each item in the 'data' array is a **python-operative** model. In the case of this example, they would be LineItem models.
See the [model definitions](https://github.com/buzzfeed/python-operative/blob/master/operative/models/__init__.py) for more info.
Extending / Contributing
------------------------
If you need to represent an Operative object that is not currently supported, then simply add it to the [model definitions](https://github.com/buzzfeed/python-operative/blob/master/operative/models/__init__.py).
If you need a report that is currently not supported, then add it to the [report definitions](https://github.com/buzzfeed/python-operative/tree/master/operative/reports).