-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
133 additions
and
88 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
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,26 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
|
||
import csv | ||
|
||
|
||
def write_csv(fhandle, outages, fields): | ||
"""Write a list of outages to a file as CSV. | ||
Example: | ||
>>> from six import StringIO | ||
>>> s = StringIO() | ||
>>> t = arrow.get(0) | ||
>>> write_outages_csv(s, [Outage(t, t)], Outage.fields()) | ||
>>> s.getvalue() | ||
'start,finish,before,after,meta\\r\\n1970-01-01T00:00:00+00:00,1970-01-01T00:00:00+00:00,,,{}\\r\\n' | ||
Args: | ||
fhandle (io.TextIOWrapper): the file object to write the CSV data to | ||
outages (list): a list of :class:`Outage` objects to write. | ||
""" | ||
writer = csv.DictWriter(fhandle, fields) | ||
writer.writeheader() | ||
writer.writerows([o.for_json() for o in outages]) |
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,12 @@ | ||
# -*- coding: utf-8 -*- | ||
try: | ||
import pygsheets | ||
except ImportError: | ||
pygsheets = None | ||
|
||
|
||
def write_to_sheet(out, data, fields): | ||
pass | ||
|
||
|
||
Writer = write_to_sheet if pygsheets else None |
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,18 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
|
||
import json | ||
|
||
|
||
def encoder(obj): | ||
try: | ||
return obj.for_json() | ||
except AttributeError: | ||
raise TypeError(repr(obj) + " is not JSON serializable") | ||
|
||
|
||
def write_json(out, data, **_): | ||
json.dump(list(data), out, indent=4, default=encoder) | ||
|
||
|
||
Writer = write_json |
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,16 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
|
||
|
||
def write_text(out, data, **_): | ||
for obj in data: | ||
try: | ||
obj = obj.humanize() | ||
except AttributeError: | ||
obj = obj.for_json() | ||
out.write("\n".join( | ||
": ".join(i) for i in obj.items())) | ||
out.write("\n") | ||
|
||
|
||
Writer = write_text |
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
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,26 @@ | ||
# -*- coding: utf-8 -*- | ||
import json | ||
|
||
import arrow | ||
import pytest | ||
from uptime_report.format.json import encoder | ||
from uptime_report.outage import Outage | ||
|
||
|
||
def test_encode_outage(): | ||
s = arrow.utcnow() | ||
f = s.replace(hours=-1) | ||
o = Outage(start=s, finish=f) | ||
assert json.loads(json.dumps(o, indent=4, default=encoder)) == { | ||
'before': None, 'after': None, 'meta': {}, | ||
'finish': f.for_json(), | ||
'start': s.for_json() | ||
} | ||
|
||
|
||
def test_encode_outage_fail(): | ||
s = arrow.utcnow() | ||
f = s.replace(hours=-1) | ||
o = Outage(start=s, finish=f, meta={'wut': set()}) | ||
with pytest.raises(TypeError): | ||
json.dumps(o, indent=4, default=encoder) |
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