blob: c57b43044ed3b9a47dd340e7804ec9e6c17fbe5c (
plain)
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
|
import json
class JSONFactory(object):
"""Factory class to create JSON messages to be sent to the shoutbox API"""
running_id = 1
@staticmethod
def make_object(text, user, timestamp, ip):
"""
Create a JSON object from the passed parameters and
add a running id
"""
message = json.dumps({
"id": JSONFactory.running_id,
"text": text,
"user": user,
"timestamp": timestamp,
"ip": ip
})
JSONFactory.running_id += 1
return message
@staticmethod
def make_array(object_list):
"""Create a JSON array from a list of JSON objects"""
return "[\n" + ",\n".join(object_list) + "\n]"
|