3a2f834 by Anon Ray at 2013-07-09 1
# SwtMaker
2
# -------
3
# Server-side component to make sweets and post them to specified 
4
# sweet store
5
#
6
# License: BSD, see LICENSE for more details.
7
# Servelots 2013
8
# Authors:
9
#   Arvind Khadri <arvind@servelots.com>
10
#   Anon Ray <rayanon@servelots.com>
11
12
import requests
13
import json
14
from datetime import datetime
15
16
TIMESTAMP_FORMAT = '%d-%m-%Y %H:%M:%S'
17
18
def sweet(sweet_url, sweet_list):
19
    sweets = makeSweet(sweet_list)
20
    if not sweets:
21
        return False
22
    else:
23
        request = requests.api.post(sweet_url, {'data': json.dumps(sweets)})
24
        if request.status_code == 200:
25
            return True
26
        else:
27
            return False
28
29
def makeSweet(sweet_list):
30
    for sweet in sweet_list:
31
        if len(sweet['who']) and len(sweet['what']) and len(sweet['where'])\
32
           and len(sweet['how']):
33
            sweet['created'] = datetime.utcnow().strftime(TIMESTAMP_FORMAT)
34
        else:
35
            return False
36
    return sweet_list