Skip to content

Commit

Permalink
reformatted "table" to "markdown" | closes #24
Browse files Browse the repository at this point in the history
  • Loading branch information
erayerdin committed Oct 30, 2018
1 parent 2b6e89e commit bbaa0cb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,23 @@ from pprint import pprint

# Call the API
print(pypistats.recent("pillow"))
print(pypistats.recent("pillow", "day", output="table"))
print(pypistats.recent("pillow", "day", output="markdown"))
pprint(pypistats.recent("pillow", "week", output="json"))
print(pypistats.recent("pillow", "month"))

print(pypistats.overall("pillow"))
print(pypistats.overall("pillow", mirrors=True, output="table"))
print(pypistats.overall("pillow", mirrors=True, output="markdown"))
pprint(pypistats.overall("pillow", mirrors=False, output="json"))

print(pypistats.python_major("pillow"))
print(pypistats.python_major("pillow", version=2, output="table"))
print(pypistats.python_major("pillow", version=2, output="markdown"))
pprint(pypistats.python_major("pillow", version="3", output="json"))

print(pypistats.python_minor("pillow"))
print(pypistats.python_minor("pillow", version=2.7, output="table"))
print(pypistats.python_minor("pillow", version=2.7, output="markdown"))
pprint(pypistats.python_minor("pillow", version="3.7", output="json"))

print(pypistats.system("pillow"))
print(pypistats.system("pillow", os="darwin", output="table"))
print(pypistats.system("pillow", os="darwin", output="markdown"))
pprint(pypistats.system("pillow", os="linux", output="json"))
```
10 changes: 5 additions & 5 deletions example/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@

# Call the API
print(pypistats.recent("pillow"))
# print(pypistats.recent("pillow", "day", output="table"))
# print(pypistats.recent("pillow", "day", output="markdown"))
# pprint(pypistats.recent("pillow", "week", output="json"))
# print(pypistats.recent("pillow", "month"))

# print(pypistats.overall("pillow"))
# print(pypistats.overall("pillow", mirrors=True, output="table"))
# print(pypistats.overall("pillow", mirrors=True, output="markdown"))
# pprint(pypistats.overall("pillow", mirrors=False, output="json"))

# print(pypistats.python_major("pillow"))
# print(pypistats.python_major("pillow", version=2, output="table"))
# print(pypistats.python_major("pillow", version=2, output="markdown"))
# pprint(pypistats.python_major("pillow", version="3", output="json"))

# print(pypistats.python_minor("pillow"))
# print(pypistats.python_minor("pillow", version=2.7, output="table"))
# print(pypistats.python_minor("pillow", version=2.7, output="markdown"))
# pprint(pypistats.python_minor("pillow", version="3.7", output="json"))
# print(
# pypistats.python_minor(
Expand All @@ -46,5 +46,5 @@
# )

# print(pypistats.system("pillow"))
# print(pypistats.system("pillow", os="darwin", output="table"))
# print(pypistats.system("pillow", os="darwin", output="markdown"))
# pprint(pypistats.system("pillow", os="linux", output="json"))
2 changes: 1 addition & 1 deletion pypistats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def pypi_stats_api(
endpoint,
params=None,
output="table",
output="markdown",
start_date=None,
end_date=None,
sort=True,
Expand Down
14 changes: 4 additions & 10 deletions pypistats/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,11 @@ def _valid_yyyy_mm(date_string):


def _define_format(args) -> str:
# "table" means "markdown". legacy.
if args.json:
return "json"

if args.json or args.format == "json":
output = "json"
elif args.format == "markdown":
output = "table"
else:
warnings.warn(f'Unknown format: {args.format}. Using "markdown".')
output = "table"

return output
_format = args.format
return _format


FORMATS = ("json", "markdown")
Expand Down
7 changes: 3 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TestCli(unittest.TestCase):
class __Args:
def __init__(self):
self.json = False # type: bool
self.format = None # type: str
self.format = "markdown" # type: str

def test__month(self):
# Arrange
Expand Down Expand Up @@ -94,10 +94,9 @@ def test__define_format_default(self):
# Setup
args = self.__Args()
args.json = False
args.format = None

_format = cli._define_format(args)
self.assertEqual(_format, "table")
self.assertEqual(_format, "markdown")

def test__define_format_json_flag(self):
args = self.__Args()
Expand All @@ -120,4 +119,4 @@ def test__define_format_markdown(self):
args.format = "markdown"

_format = cli._define_format(args)
self.assertEqual(_format, "table")
self.assertEqual(_format, "markdown")

0 comments on commit bbaa0cb

Please sign in to comment.