-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get-checklist script updated and now uses click.
1. Moved the script from bin to ebird.pages.scripts to reduce the risk of conflict with other ebird libraries. 2. Changed the library used for command line arguments from pyCLI to the rather excellent click. 3. Removed support for passing multiple identifiers to the get-checklists script. 4. Added simple tests for the command line script that can be called manually to make sure everything works with the ebird site. 5. Removed TODOs that were completed or no longer needed.
1 parent
e425e80
commit 2c23088
Showing
12 changed files
with
78 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
include *.md *.txt *.py *.cfg | ||
recursive-include bin *.py | ||
recursive-include ebird *.py | ||
recursive-include tests *.py | ||
recursive-include tests *.py *.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import datetime | ||
import json | ||
|
||
|
||
class JSONDateEncoder(json.JSONEncoder): | ||
|
||
def default(self, o): | ||
if isinstance(o, datetime.date): | ||
return o.isoformat() | ||
if isinstance(o, datetime.time): | ||
return o.isoformat() | ||
if isinstance(o, datetime.timedelta): | ||
return str(o) | ||
else: | ||
super().default(o) | ||
|
||
|
||
def save(fp, values, indent): | ||
"""Save the JSON data to a file or stdout. | ||
:param fp: the writer. | ||
:param values: the python data to be saved. | ||
:param indent: the level of indentation when prettyprinting the output. | ||
""" | ||
fp.write(json.dumps(values, indent=indent, cls=JSONDateEncoder).encode('utf-8')) | ||
if fp.name == '<stdout>': | ||
fp.write(b'\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Command-line script to scape the web page(s) for a checklists and | ||
save the data in JSON format to a file or to stdout. | ||
""" | ||
|
||
import click | ||
|
||
from ebird.pages import get_checklist | ||
|
||
from .base import save | ||
|
||
|
||
# noinspection PyShadowingBuiltins | ||
@click.command() | ||
@click.option('--id', prompt=True, | ||
help="The unique identifier for the checklist.") | ||
@click.option('--out', prompt=True, type=click.File('wb'), | ||
help='The name of a file to write the results to. To print' | ||
' the results to the screen use -.') | ||
@click.option('--indent', type=int, default=None, | ||
help='Pretty-print the results with this level of indentation.') | ||
def cli(id, out, indent): | ||
"""Get the data for a checklist from its eBird web page.""" | ||
save(out, get_checklist(id), indent) | ||
|
||
if __name__ == '__main__': | ||
cli() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.1.dev1' | ||
__version__ = '0.1' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
|
||
# Tests for the get-checklists script. | ||
|
||
# Get the data for a checklist. | ||
get-checklist --id S38645981 --out - | ||
|
||
# Missing values should be prompted for. | ||
get-checklist --out - |