-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_simple.py
More file actions
55 lines (36 loc) · 1.15 KB
/
example_simple.py
File metadata and controls
55 lines (36 loc) · 1.15 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This example covers a very basic example implementation on how to create
# a valid ouput in the openapiaryformat.
# This is more or less basic python object and json handling and can
# hopefully get beginner going.
import json
apiaries = []
apiary1 = {
"name" : "My First Apiary",
"type" : "apiary",
"description": "This was the initial Apiary"
}
apiaries.append(apiary1)
apiary2 = {
"name" : "The Second One",
"type" : "apiary",
"description" : "",
}
apiary2["location"] = {
"latitude": 50.0724825,
"longitude": 8.2483534
},
apiaries.append(apiary2)
output_string = json.dumps(apiaries, encoding="utf-8", indent=2)
print "--------------Generated Data-----------------"
print output_string
print "---------------------------------------------\n"
apiaries_loaded = json.loads(output_string)
print "----------------Loaded Data------------------"
print apiaries_loaded
print "---------------------------------------------\n"
print "--------------Iterating Data-----------------"
for apiary in apiaries_loaded:
print apiary["name"]
print "---------------------------------------------\n"