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

Commit

Permalink
Add command line option to limit dataset years
Browse files Browse the repository at this point in the history
Following @Irio PR with the option to limit dataset years, this PR:
- Update the way to select an specific path to save the datasets
- Fetch the `Dataset()` method for year, only if `years` is no None
- Update the README.md to this new option
  • Loading branch information
anaschwendler committed Dec 8, 2017
1 parent 5d9bb16 commit e8e24fa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 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
6 changes: 4 additions & 2 deletions rosie.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def entered_command(argv):
def help():
message = (
'Usage:',
' python rosie.py run (chamber_of_deputies | federal_senate) [<path to output directory>] [--years 2017,2016]',
' python rosie.py run (chamber_of_deputies | federal_senate) [--path <path to output directory>] [--years 2017,2016]',
'Testing:',
' python rosie.py test [chamber_of_deputies | federal_senate]',
)
Expand All @@ -28,7 +28,9 @@ 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)
if '--years' in argv:
years = argv[argv.index('--years') + 1]
Expand Down
5 changes: 4 additions & 1 deletion rosie/chamber_of_deputies/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def rename_categories(self):

def update_datasets(self):
os.makedirs(self.path, exist_ok=True)
chamber_of_deputies = Dataset(self.path, self.years)
if self.years:
chamber_of_deputies = Dataset(self.path, self.years)
else:
chamber_of_deputies = Dataset(self.path)
chamber_of_deputies.fetch()
chamber_of_deputies.translate()
chamber_of_deputies.clean()
Expand Down
5 changes: 4 additions & 1 deletion rosie/federal_senate/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def create_columns(self):

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

0 comments on commit e8e24fa

Please sign in to comment.