Exemplo n.º 1
0
def go(key):
     params = {'where': json.dumps({'key':key})}
     golinks = ParseDriver.make_parse_get_request('/1/classes/ParseGoLink',params)['results']
     if len(golinks)==0:
          return 'not a valid key'
     else:
          return redirect(golinks[0]['url'])
Exemplo n.º 2
0
def get_attendance(email):
     params = {'limit': sys.maxint}
     params['where'] = json.dumps({
          'member_email': email
          })
     result = ParseDriver.make_parse_get_request('/1/classes/ParseEventMember', params)
     return result['results']
Exemplo n.º 3
0
def save_member_hash():
    h = {}
    params = {'limit':sys.maxint}
    params['where'] = json.dumps({'email': {'$exists': True}})
    members = parse_driver.make_parse_get_request('/1/classes/ParseMember', params)['results']
    for m in members:
        h[m['email']] = m
    save_pickle_key('member_email_hash', h)
Exemplo n.º 4
0
def schedule():
    myEmail = utils.get_email_from_token(request.args.get('token'))
    params = {'where':json.dumps({'member_email': myEmail})}
    schedule = ParseDriver.make_parse_get_request('/1/classes/Commitments', params)['results']
    if len(schedule) == 0:
         return 'no schedule found', 404
    schedule = schedule[0]
    return utils.get_response(schedule['commitments'])
Exemplo n.º 5
0
def save_events_hash():
    events_hash = {}
    params = {'limit':sys.maxint, 'where':json.dumps({'google_id':{'$exists':True}})}
    events = parse_driver.make_parse_get_request('/1/classes/ParseEvent', params)['results']
    print events
    for e in events:
        events_hash[e['google_id']] = e
    save_pickle_key('events_hash', events_hash)
    pass
Exemplo n.º 6
0
def search_golinks():
     searchTerm = request.args.get('searchTerm')
     where = {'$or':[{'key':{'$regex':searchTerm}},
          {'description':{'$regex':searchTerm}},
          {'tags':{'$in':[searchTerm]}}
          ]}
     params = {'where':json.dumps(where)}
     results = ParseDriver.make_parse_get_request('/1/classes/ParseGoLink', params)
     results = results['results']
     return Response(json.dumps(results), mimetype='application/json')
Exemplo n.º 7
0
def save_committee_members_hash():
    h = {}
    params = {'limit':sys.maxint}
    params['where'] = json.dumps({'latest_semester': 'Fall 2015'})
    members = parse_driver.make_parse_get_request('/1/classes/ParseMember', params)['results']
    for m in members:
        if m['committee'] not in h.keys():
            h[m['committee']] = []
        h[m['committee']].append(m)
    save_pickle_key('committee_members_hash', h)
Exemplo n.º 8
0
def recent_golinks():
     email = utils.get_email_from_token(request.args.get('token'))
     page = int(request.args.get('page', '0'))
     params = {}
     params['order'] = '-createdAt'
     params['skip']=page*100
     r = ParseDriver.make_parse_get_request('/1/classes/ParseGoLink', params)
     results = r['results']
     for x in results:
          if 'num_clicks' not in x.keys():
                x['num_clicks']=0
     return utils.get_response(results)
Exemplo n.º 9
0
def save_schedule():
    myEmail = utils.get_email_from_token(request.args.get('token'))
    times = request.get_json().get('schedule')
    params = {'where':json.dumps({'member_email': myEmail})}
    schedule = ParseDriver.make_parse_get_request('/1/classes/Commitments', params)['results']
    s = {'member_email': myEmail, 'commitments': times}
    print 'schedule was '+str(s)
    if len(schedule) == 0:
        ParseDriver.make_parse_post_request('/1/classes/Commitments', s)
    else:
        sid = schedule[0].get('objectId')
        ParseDriver.make_parse_put_request('/1/classes/Commitments/'+sid, s)
    return 'ok'
Exemplo n.º 10
0
def popular_golinks():
     email = utils.get_email_from_token(request.args.get('token'))
     page = int(request.args.get('page', '0'))
     params = {}
     params['order'] = '-num_clicks'
     params['skip']=page*100
     params['where']= json.dumps({'member_email': email})
     r = ParseDriver.make_parse_get_request('/1/classes/ParseGoLink', params)
     results = r['results']
     for x in results:
          if 'num_clicks' not in x.keys():
                x['num_clicks']=0
     return utils.get_response(results)
Exemplo n.º 11
0
def go(key):
    params = {'where': json.dumps({'key': key})}

    # Parse GET request will already encode the params, so no need to encode twice
    golinks = ParseDriver.make_parse_get_request('/1/classes/ParseGoLink',
                                                 params)['results']

    if len(golinks) == 0:
        return 'Not a valid key'
    else:
        # decode from encoded version from Parse
        decoded_url = urllib2.unquote(golinks[0]['url'])
        return redirect(decoded_url)
Exemplo n.º 12
0
def attendance():
     requesterEmail = utils.get_email_from_token(request.args.get('token'))
     me = scripts.load_pickle_key('member_email_hash')[requesterEmail]
     emails = scripts.load_pickle_key('committee_members_hash')[me['committee']]
     emails = [x['email'] for x in emails]
     params = {'limit':sys.maxint, 'where': json.dumps({'member_email': {'$in':emails}})}
     event_members = ParseDriver.make_parse_get_request('/1/classes/ParseEventMember', params)['results']
     # return a dictionary with keys emails, values list of attended events
     h = {}
     seen = []
     for em in event_members:
          if em['member_email'] not in seen:
                seen.append(em['member_email'])
                h[em['member_email']] = []
          h[em['member_email']].append({'event_id': em['event_id'], 'type': em['type']})
     return utils.get_response(h)
Exemplo n.º 13
0
def lookup():
    try:
        # URL should already be encoded
        url = request.args.get('url', '')
    except KeyError:
        # may want to return an empty JSON instead
        return 'No key found in the lookup function'

    params = {'where': json.dumps({'url': url})}
    golinks = ParseDriver.make_parse_get_request('/1/classes/ParseGoLink',
                                                 params)['results']

    matching_golinks = []
    # check for multiple go-links that map to same URL
    for g in golinks:
        decoded_key = urllib2.unquote(g['key'])
        matching_golinks.append(decoded_key)

    return json.dumps(matching_golinks)
Exemplo n.º 14
0
def record_attendance():
     form = request.get_json()
     myEmail = utils.get_email_from_token(request.args.get('token'))
     event_id = form.get('event_id')
     email = form.get('email')
     params = {'where': json.dumps({'event_id': event_id, 'member_email': email})}
     ems = ParseDriver.make_parse_get_request('/1/classes/ParseEventMember', params)['results']
     myPosition = utils.get_position_from_email(myEmail)
     if myPosition == 'exec':
          myPosition = 'chair'
     if len(ems) == 0:
          print 'there are no ems that match'
          data = {'event_id': event_id, 'member_email': email, 'type': myPosition}
          ParseDriver.make_parse_post_request('/1/classes/ParseEventMember', data)
     else:
          print 'there are matching ems ('+str(len(ems))+')'
          em = ems[0]
          url = '/1/classes/ParseEventMember/'+em['objectId']
          data = {'type':myPosition}
          ParseDriver.make_parse_put_request(url,  data)

     return 'ok'
Exemplo n.º 15
0
def tabling_slots():
     params = {'limit': sys.maxint}
     tabling_slots = ParseDriver.make_parse_get_request('/1/classes/ParseTablingSlot', params)['results']
     for slot in tabling_slots:
          slot['member_emails'] = slot['member_emails'].split(',')
     return Response(json.dumps(tabling_slots), mimetype = 'application/json')
Exemplo n.º 16
0
def all_blogposts():
     params = {'limit':sys.maxint, 'order': '-updatedAt'}
     posts = ParseDriver.make_parse_get_request('/1/classes/BlogPost', params)['results']
     return utils.get_response(posts)
Exemplo n.º 17
0
def get_blogpost():
     post_id = request.args.get('id')
     post = ParseDriver.make_parse_get_request('/1/classes/BlogPost/'+str(post_id), '')
     print post
     return utils.get_response(post)
Exemplo n.º 18
0
def current_members():
     params = {'limit': sys.maxint, 'where': json.dumps({'latest_semester': config.CURRENT_SEMESTER})}
     members = ParseDriver.make_parse_get_request('/1/classes/ParseMember', params)['results']
     return Response(json.dumps(members), mimetype='application/json')
Exemplo n.º 19
0
def get_events():
     params = {'limit':sys.maxint}
     params['where'] = json.dumps({'semester_name': config.CURRENT_SEMESTER})
     events = ParseDriver.make_parse_get_request('/1/classes/ParseEvent', params)['results']
     return utils.get_response(events)
Exemplo n.º 20
0
def get_events_by_id(eids):
     params = {'limit':sys.maxint,
                'where': json.dumps( {'google_id': {'$in': eids}})}

     result = ParseDriver.make_parse_get_request('/1/classes/ParseEvent', params)
     return result['results']
Exemplo n.º 21
0
def member_email_hash():
     params = {'limit': sys.maxint}
     params['where'] = json.dumps({'email': {'$exists':True}})
     members = ParseDriver.make_parse_get_request('/1/classes/ParseMember', params)['results']
     h= dict((x['email'], x) for x in members)
     return Response(json.dumps(h), mimetype = 'application/json')
Exemplo n.º 22
0
def count_golinks():
     params = {'count':1}
     r = ParseDriver.make_parse_get_request('/1/classes/ParseGoLink', params)
     return r['count']