예제 #1
0
def populateData(start_date, end_date):
    events = crawler(start_date, end_date)
    events = processGeoInfo(events)

    # populate data into db
    for e in events:
        try:
            add_activity(db_handler, e['Name'], e['CreatorId'], e['Location'], e['latlon']['lat'], \
                e['latlon']['lng'], e['Date'], e['Time'], e['Description'], e['Tag'])
        except:
            continue
예제 #2
0
파일: PinGT.py 프로젝트: LancelotGT/Pin-GT
def populateData(start_date, end_date):
    events = crawler(start_date, end_date)
    events = processGeoInfo(events)

    # populate data into db
    for e in events:
        try:
            add_activity(db_handler, e['Name'], e['CreatorId'], e['Location'], e['latlon']['lat'], \
                e['latlon']['lng'], e['Date'], e['Time'], e['Description'], e['Tag'])
        except:
            continue
예제 #3
0
def events():
    error = None
    if request.method == "GET":
        startDate = request.args.get('startDate', type=str)
        endDate = request.args.get('endDate', type=str)
        tag = request.args.get('tag', type=str)
        entries = select_activity(db_handler, startDate, endDate, tag)
        return jsonify(events=entries)
    elif request.method == "POST":
        name = request.json['name']
        date = request.json['date']
        time = request.json['time']
        tags = request.json['tags']
        location = request.json['location']
        latlon = request.json['latlon']
        description = request.json['description']
        gtID = session['username']

        # some input checking
        if len(name) == 0 or len(date) == 0 or len(time) == 0 or len(tags) == 0 \
            or len(location) == 0 or (not isinstance(latlon, dict)) \
            or len(description) == 0 or len(gtID) == 0:
            return "Bad request", 400
        try:
            int(gtID)
        except:
            return "Bad request", 400
        if not isinstance(tags, list):
            return "Bad request", 400
        r = re.compile('.{4}-.{2}-.{2}')
        if not (len(date) == 10):
            return "Bad request", 400
        else:
            if not r.match(date):
                return "Bad request", 400

        add_activity(db_handler, name, gtID, location, latlon['lat'], latlon['lon'], \
                  date, time, description, tags)
        return "OK"
    elif request.method == "UPDATE":
        activityID = long(request.json['activityID'])
        name = request.json['name']
        date = request.json['date']
        time = request.json['time']
        tags = request.json['tags']
        description = request.json['description']

        # some input checking
        if len(name) == 0 or len(date) == 0 or len(time) == 0 or len(tags) == 0 \
            or len(description) == 0:
            return "Bad request", 400
        if not isinstance(tags, list):
            return "Bad request", 400
        r = re.compile('.{4}-.{2}-.{2}')
        if not (len(date) == 10):
            return "Bad request", 400
        else:
            if not r.match(date):
                return "Bad request", 400

        act = get_activity(db_handler, activityID)
        creatorID = act[2]
        gtID = long(session['username'])
        if gtID == creatorID:
            update_activity(db_handler, activityID, name, date, time, tags,
                            description)
            return "OK"
        else:
            return "Not authorized", 403
    elif request.method == "DELETE":
        activityID = long(request.json['activityID'])
        act = get_activity(db_handler, activityID)
        creatorID = act[2]
        gtID = long(session['username'])
        if gtID == creatorID:
            delete_notification(db_handler, activityID, gtID)
            delete_activity(db_handler, activityID)
            return "OK"
        else:
            return "Not authorized", 403

    return redirect(url_for('/'))
예제 #4
0
파일: PinGT.py 프로젝트: LancelotGT/Pin-GT
def events():
    error = None
    if request.method == "GET":
        startDate = request.args.get('startDate', type=str)
        endDate = request.args.get('endDate', type=str)
        tag = request.args.get('tag', type=str)
        entries = select_activity(db_handler, startDate, endDate, tag)
        return jsonify(events=entries)
    elif request.method == "POST":
        name = request.json['name']
        date = request.json['date']
        time = request.json['time']
        tags = request.json['tags']
        location = request.json['location']
        latlon = request.json['latlon']
        description = request.json['description']
        gtID = session['username']

        # some input checking
        if len(name) == 0 or len(date) == 0 or len(time) == 0 or len(tags) == 0 \
            or len(location) == 0 or (not isinstance(latlon, dict)) \
            or len(description) == 0 or len(gtID) == 0:
            return "Bad request", 400
        try:
            int(gtID)
        except:
            return "Bad request", 400
        if not isinstance(tags, list):
            return "Bad request", 400
        r = re.compile('.{4}-.{2}-.{2}')
        if not (len(date) == 10):
            return "Bad request", 400
        else:
            if not r.match(date):
                return "Bad request", 400

        add_activity(db_handler, name, gtID, location, latlon['lat'], latlon['lon'], \
                  date, time, description, tags)
        return "OK"
    elif request.method == "UPDATE":
        activityID = long(request.json['activityID'])
        name = request.json['name']
        date = request.json['date']
        time = request.json['time']
        tags = request.json['tags']
        description = request.json['description']

        # some input checking
        if len(name) == 0 or len(date) == 0 or len(time) == 0 or len(tags) == 0 \
            or len(description) == 0:
            return "Bad request", 400
        if not isinstance(tags, list):
            return "Bad request", 400
        r = re.compile('.{4}-.{2}-.{2}')
        if not (len(date) == 10):
            return "Bad request", 400
        else:
            if not r.match(date):
                return "Bad request", 400

        act = get_activity(db_handler, activityID)
        creatorID = act[2]
        gtID = long(session['username'])
        if gtID == creatorID:
            update_activity(db_handler, activityID, name, date, time, tags, description)
            return "OK"
        else:
            return "Not authorized", 403
    elif request.method == "DELETE":
        activityID = long(request.json['activityID'])
        act = get_activity(db_handler, activityID)
        creatorID = act[2]
        gtID = long(session['username'])
        if gtID == creatorID:
            delete_notification(db_handler, activityID, gtID)
            delete_activity(db_handler, activityID)
            return "OK"
        else:
            return "Not authorized", 403

    return redirect(url_for('/'))