-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.py
More file actions
36 lines (27 loc) · 963 Bytes
/
users.py
File metadata and controls
36 lines (27 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
__author_ = "Josphat Mutuku"
__date__ ="2019-07-03"
"""
import requests
import unittest
import ijson
USERS_URL = 'http://jsonplaceholder.typicode.com/users'
def get_users():
# Do a GET request to the /users endpoint
response = requests.get(USERS_URL)
if response.ok:
return response
else:
return None
def parse_json(json_filename):
with open(json_filename, 'rb') as input_file:
# load json iteratively
parser = ijson.parse(input_file)
for prefix, event, value in parser:
print('prefix={}, event={}, value={}'.format(prefix, event, value))
def extract_company_names(json_filename):
with open(json_filename, 'rb') as input_file:
company_names = ijson.items(input_file, 'item.company.name')
for name in company_names:
if name.endswith('Group'):
print('Company Name: {}'.format(name))