示例#1
0
def get_orchards():
    orchards_query = "SELECT * from orchard"
    orchards = query_db(orchards_query)
    records = orchards['records']
    orchards_list = []
    for record in records:
        orchards_list.append(orchard_entry_to_dict(record))
    return orchards_list
示例#2
0
def get_users():
    users_query = "SELECT * from UserData"
    users = query_db(users_query)
    records = users['records']
    users_list = []
    for record in records:
        users_list.append({
            'name': record[4]['stringValue'],
            'position': get_position(record[3]['longValue']),
            'email': record[1]['stringValue']
        })
    print(str(users_list))
    return users_list
示例#3
0
def lambda_handler(event, context):
    print(str(event))
    email = event['pathParameters']['email']
    query_str = "SELECT * FROM UserData where email = '" + email + "'"
    response = query_db(query_str)
    user_data = response['records'][0]
    user = {
        'name': user_data[4]['stringValue'],
        'position': get_position(user_data[3]['longValue']),
        'email': user_data[1]['stringValue']
    }
    print(str(user))
    return respond(statusCode="200", res=user)
def lambda_handler(event, context):
    # Note on this lambda, there is code here that creates a more formatted and sorted version of the annoucements, but it is not live because
    print(str(event))
    query = "SELECT * FROM announcements"
    result = query_db(query)
    records = result['records']
    annoucements = []
    for record in records:
        annoucements.append(annoucement_entry_to_dict(record))
    sorted_annoucements = sorted(annoucements,
                                 key=itemgetter('dateTime'),
                                 reverse=True)
    print(sorted_annoucements)
    return respond(statusCode="200", res=result['records'])
def lambda_handler(event, context):
    print(str(event))
    body_str = event['body']
    body = json.loads(body_str)
    
    # Escape characters for SQL query
    for key in ['title', 'description', 'date', 'email']:
        body[key] = body[key].replace("'", "''")
    
    query_str = f"INSERT INTO announcements (title, description, date, email) VALUES ('{body['title']}', '{body['description']}', '{body['date']}', '{body['email']}')"
    print(query_str)
    result = query_db(query_str)
    print(str(result))
    return respond(statusCode="200", res="Successfully added announcement.")
def lambda_handler(event, context):
    # TODO add entries for the other items like the individual trees and stuff
    print(str(event))
    body_str = event['body']
    body = json.loads(body_str)
    if "lastupdated" not in body.keys():
        today = date.today()
        d = today.strftime("%m/%d/%y")
        print("Today's date:  ", d)
        body['lastupdated'] = d
    query_str = f"INSERT INTO orchard (name, location, targetfruitpertree, averagenumberclusters, potentialfruitpertree, lastupdated) VALUES ('{body['name']}', '{body['location']}', {body['targetFruitPerTree']}, {body['averageNumberOfClusters']}, {body['potentialFruitPerTree']}, '{body['lastupdated']}');"
    print(query_str)
    result = query_db(query_str)
    print(str(result))
    return respond(statusCode="200", res="Successfully added orchard.")
def lambda_handler(event, context):
    print(str(event))

    query = "SELECT * FROM announcements"
    result = query_db(query)
    records = result['records']
    annoucements = []
    for record in records:
        annoucements.append(annoucement_entry_to_dict(record))
    sorted_annoucements = sorted(annoucements,
                                 key=itemgetter('dateTime'),
                                 reverse=True)

    # for a in announcements:
    #     print(a)
    # sorted(announcements, key = lambda i: i['age'])
    # print(result['records'])
    print(sorted_annoucements)

    return respond(statusCode="200", res=result['records'])
def lambda_handler(event, context):
    print(str(event))

    body_str = event['body']
    body = json.loads(body_str)
    orch_id = event['pathParameters']['id']
    query_str = "UPDATE orchard SET "
    vars_to_change = []
    for key in [
            'averagenumberclusters', 'potentialfruitpertree',
            'targetfruitpertree', 'lastupdated'
    ]:
        if (key in body.keys()):
            if (key == 'lastupdated'):
                vars_to_change.append("%s = '%s'" % (key, body[key]))
            else:
                vars_to_change.append("%s = %s" % (key, body[key]))
    query_str += ', '.join(vars_to_change)
    query_str += (" WHERE orchardid = %s" % orch_id)
    print(query_str)
    result = query_db(query_str)
    print(str(result))
    return respond("Upload successful", 200)