Esempio n. 1
0
def requests():
    if request.method == 'POST':
        print(request.data)
        if not request.json:
            abort(400)
        print(request.json)
        data = request.json
        if "location" in data:
            location = data["location"]
            lonlat = location.split(',')
            del data["location"]
            print(lonlat)
            locDetail = get_taluka(lonlat[0], lonlat[1])
            data['location'] = locDetail
            data['location']["requestLocation"] = lonlat
        else:
            print('ERROR : LOCATION not provided')
        localtime = int(time.time()) * 1000
        data["status"] = "NEW"
        data["translated_info"] = translate.convert(data["info"], 'de-en')
        data["timestamp"] = {}
        data["timestamp"]["created"] = localtime
        data["timestamp"]["updated"] = localtime

        #write to db

        db = dbclient.createdb('request')
        dbclient.createdoc(db, data)

        return json.dumps(data)
Esempio n. 2
0
def queryrequests(key):
    if request.method == 'GET':
        if key:
            key = key.lower()
        db = dbclient.createdb('request')
        result = dbclient.getresults(db,'get_location',key)
        print(result)
        return json.dumps(result['rows'])
Esempio n. 3
0
def queryrequests(key):
    if request.method == 'GET':
        if key:
            key = key.lower()
        db = dbclient.createdb('request')
        result = dbclient.getresults(db, 'get_location', key)
        newlist = sorted(result['rows'],
                         key=lambda k: k['value']['timestamp']['created'])
        return json.dumps(newlist)
Esempio n. 4
0
def putrequests(id):
    if request.method == 'PUT':
        print(request.data)
        if not request.json:
            abort(400)
        print(request.json)
        data = request.json
        db = dbclient.createdb('request')
        doc = dbclient.getres(db, id)
        print(doc)
        doc['status'] = "IN PROGRESS"
        dbclient.updateres(doc)

        sms.send_sms(doc['number'],
                     "Your request has been update with: " + data['comment'])
        #translate
        return "SUCCESS"
Esempio n. 5
0
def counts(key):
    if request.method == 'GET':
        if key:
            key = key.lower()
        db = dbclient.createdb('request')
        result = dbclient.getresults(db, 'get_location', key)
        resultFF = dbclient.getresults(db, 'get_requests_fulfilled', key)
        resultVol = dbclient.getresults(db, 'get_volunteers', key, 2)

        print(resultFF)
        print(resultVol)
        data = {}
        data['affected'] = 1000
        data['volunteers'] = 20
        data['requests'] = {}
        data['requests']['total'] = len(result['rows'])
        data['requests']['fulfilled'] = len(resultFF['rows'])

        return json.dumps(data)