Skip to content
This repository has been archived by the owner on Mar 1, 2018. It is now read-only.

Commit

Permalink
Merge a7809ca into 196dd67
Browse files Browse the repository at this point in the history
  • Loading branch information
anaschwendler committed Dec 8, 2017
2 parents 196dd67 + a7809ca commit 84d9a32
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 16 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ A `/tmp/serenata-data/irregularities.xz` file will be created. It's a compacted
Also a target directory (where files are saved) can de passed — for example:

```console
$ python rosie.py run chamber_of_deputies /my/serenata/directory/
$ python rosie.py run chamber_of_deputies --path /my/serenata/directory/
```

Besides that, if you want to, you can run the project with years filter - for example:
```console
$ python rosie.py run chamber_of_deputies --years 2017,2016
```

#### Test suite
Expand Down
16 changes: 11 additions & 5 deletions rosie.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ def entered_command(argv):
def help():
message = (
'Usage:',
' python rosie.py run chamber_of_deputies [<path to output directory>]',
' python rosie.py run (chamber_of_deputies | federal_senate) [--path <path to output directory>] [--years 2017,2016]',
'Testing:',
' python rosie.py test',
' python rosie.py test chamber_of_deputies',
' python rosie.py test [chamber_of_deputies | federal_senate]',
)
print('\n'.join(message))

Expand All @@ -29,9 +28,16 @@ def run():
print('A module must be provided.')
help()
exit(1)
target_directory = argv[3] if len(argv) >= 4 else '/tmp/serenata-data/'

target_directory = argv[argv.index('--path') + 1] if '--path' in argv else '/tmp/serenata-data/'

klass = getattr(rosie, target_module)
klass.main(target_directory)
if '--years' in argv:
years = argv[argv.index('--years') + 1]
years = [int(num) for num in years.split(',')]
klass.main(target_directory, years=years)
else:
klass.main(target_directory)


def test():
Expand Down
4 changes: 2 additions & 2 deletions rosie/chamber_of_deputies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rosie.core import Core


def main(target_directory='/tmp/serenata-data'):
adapter = Adapter(target_directory)
def main(target_directory='/tmp/serenata-data', years=None):
adapter = Adapter(target_directory, years=years)
core = Core(settings, adapter)
core()
7 changes: 4 additions & 3 deletions rosie/chamber_of_deputies/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pandas as pd

from serenata_toolbox.chamber_of_deputies.dataset import Dataset
from serenata_toolbox.chamber_of_deputies.dataset import Dataset, AVAILABLE_YEARS
from serenata_toolbox.datasets import fetch

COLUMNS = {
Expand All @@ -17,8 +17,9 @@
class Adapter:
COMPANIES_DATASET = '2016-09-03-companies.xz'

def __init__(self, path):
def __init__(self, path, years=None):
self.path = path
self.years = years or AVAILABLE_YEARS

@property
def dataset(self):
Expand Down Expand Up @@ -63,7 +64,7 @@ def rename_categories(self):

def update_datasets(self):
os.makedirs(self.path, exist_ok=True)
chamber_of_deputies = Dataset(self.path)
chamber_of_deputies = Dataset(self.path, self.years)
chamber_of_deputies.fetch()
chamber_of_deputies.translate()
chamber_of_deputies.clean()
Expand Down
6 changes: 3 additions & 3 deletions rosie/federal_senate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from rosie.core import Core


def main(target_directory='/tmp/serenata-data'):
adapter = Adapter(target_directory)
def main(target_directory='/tmp/serenata-data', years=None):
adapter = Adapter(target_directory, years=years)
core = Core(settings, adapter)
core()
core()
5 changes: 3 additions & 2 deletions rosie/federal_senate/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

class Adapter:

def __init__(self, path):
def __init__(self, path, years=None):
self.path = path
self.years = years or Dataset.AVAILABLE_YEARS

@property
def dataset(self):
Expand Down Expand Up @@ -43,7 +44,7 @@ def create_columns(self):

def update_datasets(self):
os.makedirs(self.path, exist_ok=True)
federal_senate = Dataset(self.path)
federal_senate = Dataset(self.path, years=self.years)
federal_senate.fetch()
federal_senate.translate()
federal_senate_reimbursements_path = federal_senate.clean()
Expand Down

0 comments on commit 84d9a32

Please sign in to comment.