Skip to content

Commit 27557c4

Browse files
committed
adds additional examples
1 parent d6d3a9c commit 27557c4

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

README.rst

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,35 +169,35 @@ To get the latest data by a specific metric, run:
169169
"areaCode": "E92000001",
170170
"newCasesByPublishDate": 547,
171171
"cumCasesByPublishDate": 259022,
172-
"newDeathsByDeathDate": null,
173-
"cumDeathsByDeathDate": null
172+
"newDeathsByDeathDate": None,
173+
"cumDeathsByDeathDate": None
174174
},
175175
{
176176
"date": "2020-07-28",
177177
"areaName": "Northern Ireland",
178178
"areaCode": "N92000002",
179179
"newCasesByPublishDate": 9,
180180
"cumCasesByPublishDate": 5921,
181-
"newDeathsByDeathDate": null,
182-
"cumDeathsByDeathDate": null
181+
"newDeathsByDeathDate": None,
182+
"cumDeathsByDeathDate": None
183183
},
184184
{
185185
"date": "2020-07-28",
186186
"areaName": "Scotland",
187187
"areaCode": "S92000003",
188188
"newCasesByPublishDate": 4,
189189
"cumCasesByPublishDate": 18558,
190-
"newDeathsByDeathDate": null,
191-
"cumDeathsByDeathDate": null
190+
"newDeathsByDeathDate": None,
191+
"cumDeathsByDeathDate": None
192192
},
193193
{
194194
"date": "2020-07-28",
195195
"areaName": "Wales",
196196
"areaCode": "W92000004",
197197
"newCasesByPublishDate": 21,
198198
"cumCasesByPublishDate": 17191,
199-
"newDeathsByDeathDate": null,
200-
"cumDeathsByDeathDate": null
199+
"newDeathsByDeathDate": None,
200+
"cumDeathsByDeathDate": None
201201
}
202202
],
203203
"lastUpdate": "2020-07-28T15:34:31.000000Z",
@@ -206,6 +206,49 @@ To get the latest data by a specific metric, run:
206206
}
207207

208208

209+
Set the ``save_as`` input argument to a path to save the data in a file. This
210+
functionality is only available for ``.get_json()``, ``.get_xml()`` and ``.get_csv()``
211+
methods.
212+
213+
Note that the ``save_as`` argument must be set to a file name with the correct extension;
214+
that is, ``.json`` for JSON data, ``.xml`` for XML data, and ``.csv`` for CSV data. It is
215+
assumed that the directory in which you wish to save the file already exists.
216+
217+
You may use relative or absolute paths.
218+
219+
.. code-block:: python
220+
221+
path = "data.csv"
222+
223+
api.get_csv(save_as="some_existing_directory/data.csv")
224+
225+
226+
This will create a file entitled ``data.csv`` under ``some_existing_directory``. The
227+
contents of the file would be as follows:
228+
229+
::
230+
231+
date,areaName,areaCode,newCasesByPublishDate,cumCasesByPublishDate,newDeathsByDeathDate,cumDeathsByDeathDate
232+
2020-07-28,England,E92000001,547,259022,,
233+
2020-07-28,Northern Ireland,N92000002,9,5921,,
234+
2020-07-28,Scotland,S92000003,4,18558,,
235+
2020-07-28,Wales,W92000004,21,17191,,
236+
237+
238+
Set the ``as_string`` input argument to ``True`` for the ``.get_json()`` method if you
239+
wish to receive the result as a JSON string instead of a ``dict`` object:
240+
241+
.. code-block:: python
242+
243+
data = api.get_json(as_string=True)
244+
print(data)
245+
246+
::
247+
248+
{"data":[{"date":"2020-07-28","areaName":"England","areaCode":"E92000001","newCasesByPublishDate":547,"cumCasesByPublishDate":259022,"newDeathsByDeathDate":null,"cumDeathsByDeathDate":null},{"date":"2020-07-28","areaName":"Northern Ireland","areaCode":"N92000002","newCasesByPublishDate":9,"cumCasesByPublishDate":5921,"newDeathsByDeathDate":null,"cumDeathsByDeathDate":null},{"date":"2020-07-28","areaName":"Scotland","areaCode":"S92000003","newCasesByPublishDate":4,"cumCasesByPublishDate":18558,"newDeathsByDeathDate":null,"cumDeathsByDeathDate":null},{"date":"2020-07-28","areaName":"Wales","areaCode":"W92000004","newCasesByPublishDate":21,"cumCasesByPublishDate":17191,"newDeathsByDeathDate":null,"cumDeathsByDeathDate":null}],"lastUpdate":"2020-07-28T15:34:31.000000Z","length":4,"totalPages":1}
249+
250+
251+
209252
-----------
210253

211254
Developed and maintained by `Public Health England`_.

0 commit comments

Comments
 (0)