Exemple #1
0
    def testCampListAuth(self):
        user, key = AUTHS['playaevents']
        seed = random.randint(0,1000000000)
        url = sign_url('/events/api/%s/2011/camp/' % APIS['playaevents'], user, key, seed=str(seed))
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        # use one of the camps to get details
        camps = simplejson.loads(response.content)
        self.assert_(len(camps) > 0)

        camp = random.choice(camps)
        seed += 1
        url = sign_url('/events/api/%s/2011/camp/%i/' % (APIS['playaevents'], camp['id']), user, key, seed=str(seed))
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)

        camp2 = simplejson.loads(response.content)

        self.assert_(len(camp2) > 0)
        camp2 = camp2[0]

        keys1 = camp.keys()
        keys2 = camp.keys()
        keys1.sort()
        keys2.sort()

        self.assertEqual(keys1, keys2)

        for key in keys1:
            self.assertEqual(camp[key], camp2[key])
Exemple #2
0
    def testGetRidshareAuth(self):
        url = '/rideshare/api/rideshare/304/'
        user, key = AUTHS['rideshare']
        seed = random.randint(0,1000000000)

        url = sign_url(url, user, key, seed=str(seed))

        response = self.client.get(url)
        if response.status_code == 401:
            print """Got a forbidden response from the Rideshare server, are you sure that you are using the right user & key?
This is set in PROXY_DOMAINS with "authuser" and "authkey".  Currently you have:
user=%s and key=%s""" % (user, key)

        self.assertEqual(response.status_code, 200)
        data = simplejson.loads(response.content)

        self.assertEqual(data['camp'], 'Camposanto')
        self.assert_('contact_email' in data)
        self.assert_('latest_departure' in data and data['latest_departure'] is not None)

        parser = dateutil.parser.parser()
        raw = data['latest_departure']
        dt = parser.parse(raw)
        self.assertEqual(dt.year, 2011)
        self.assertEqual(dt.month, 9)
        self.assertEqual(dt.day, 5)
Exemple #3
0
    def testGetImageCaption(self):
        url = '/gallery/api/photos/alesp/alesp.43340/caption'
        user, key = AUTHS['mediagallery']
        seed = random.randint(0,1000000000)

        url = sign_url(url, user, key, seed=str(seed))

        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, 'Gold and Silver Duo')
Exemple #4
0
    def testGetImageDetl(self):
        url = '/gallery/api/photos/alesp/alesp.43340/json'
        user, key = AUTHS['mediagallery']
        seed = random.randint(0,1000000000)

        url = sign_url(url, user, key, seed=str(seed))

        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        data = simplejson.loads(response.content)
        self.assertEqual(data['status'], 'approved')
        self.assertEqual(data['year'], 2011)
        self.assertEqual(data['title'], 'Gold and Silver Duo')
Exemple #5
0
    def testGetImageAuth(self):
        url = '/gallery/api/photos/alesp/alesp.43340/image'
        user, key = AUTHS['mediagallery']
        seed = random.randint(0,1000000000)

        url = sign_url(url, user, key, seed=str(seed))

        response = self.client.get(url)
        if response.status_code == 401:
            print """Got a forbidden response from the Gallery server, are you sure that you are using the right user & key?
This is set in PROXY_DOMAINS with "authuser" and "authkey".  Currently you have:
user=%s and key=%s""" % (user, key)

        self.assertEqual(response.status_code, 200)
        imgtype = imghdr.what('',response.content)
        self.assertEqual(imgtype, 'jpeg')
Exemple #6
0
    def import_camps(self, fname, year, maxrows):
        reader = csv.reader(open(fname, 'r'))
        keys = {
            'bm_fm_id' : 0,
            'year' : 1,
            'name' : 3,
            'location' : 4,
            'url' : 5,
            'description' : 8,
            'contact_email' : 14,
            'hometown' : (11,12,13),
            }

        common_misspellings = {
            'Engadgment' : 'Engagement',
            'Engagment' : 'Engagement',
            'Coming out' : 'Coming Out',
            'Inititation' : 'Initiation'
            }

        campct = 0
        errct = 0
        timestamp = datetime.datetime.now()
        timestamp = time.mktime(timestamp.timetuple())
        seed = str(int(timestamp))
        ix = 0
        section = settings.PROXY_DOMAINS['playaevents']
        remote = 'http://%s:%s' % (section['server'], section.get('port',80))

        for row in reader:
            if row:
                data = {}

                year = row[keys['year']]

                name = smart_unicode(row[keys['name']], errors='ignore')
                name = name.replace('"', '')
                data['slug'] = slugify(name)

                for key, val in keys.items():
                    if not key == 'hometown':
                        data[key] = row[val]

                city, state, country = keys['hometown']
                city, state, country = row[city], row[state], row[country]
                home = ""
                for e in (city, state, country):
                    e = e.strip()
                    if e:
                        if home:
                            home = "%s, " % e
                        else:
                            home = e

                if home.endswith(', '):
                    home = home[:-2]
                data['hometown'] = home

                if 'description' in data:
                    data['description'] = data['description'].replace('', '\n')

                # camp locations are "Street" and "Time"
                loc = row[keys['location']]
                if loc:
                    loc = loc.replace(" o'clock", '')
                    loc = loc.replace(" o’clock", '')
                    loc = loc.replace('14','15')

                    data['location_string'] = loc
                    if '&' in loc:
                        street, timestr = loc.split('&',1)

                        street = street.strip()
                        timestr = timestr.strip()
                        if street[0] in '0123456789':
                            # probably reversed
                            t = timestr
                            timestr = street
                            street = t
                        print ('Street = %s Time = %s' % (street, timestr))
                        if str(timestr[0]) in '0123456789':
                            if not ':' in timestr:
                                timestr = '%s:00' % timestr
                            data['time_street_name'] = timestr.split(' ')[0]
                        else:
                            print 'bad time: %s [%s]' % (timestr, timestr[0])
                        for bad, good in common_misspellings.items():
                            if street == bad:
                                street = good
                                loc.replace(bad,good)
                                data['location_string'] = loc
                        data['circular_street_name'] = street

                url = '/api/0.2/%s/camp/' % year
                url = sign_url(url, section['authuser'], section['authkey'], seed = "%s%i" % (seed, ix))
                print "Updating ID#%s, Name: %s, Loc: %s" % (data.get('bm_fm_id','---'), data['name'], loc)
                resp, content = remote_json(remote, url, data=data, method='PUT')
                if resp['status'] != '200':
                    print 'error #%s\n%s\ndata: %s' % (resp['status'], content, data)
                    errct += 1
                else:
                    campct += 1
                ix += 1

            if maxrows > 0 and ix >= maxrows:
                break

        print ("done, loaded %i Camps, %i errors" % (campct, errct))
Exemple #7
0
    def import_art(self, fname, default_year):
        reader = csv.reader(open(fname, 'r'))
        keys = {
            'year' : 0,
            'bm_fm_id' : 2,
            'artist' : 3,
            'name' : 6,
            'location' : 7,
            'description' : 9,
            'contact_email' : 10
            }

        artct = 0
        errct = 0
        timestamp = datetime.datetime.now()
        timestamp = time.mktime(timestamp.timetuple())
        seed = str(int(timestamp))
        ix = 0
        section = settings.PROXY_DOMAINS['playaevents']
        remote = 'http://%s:%s' % (section['server'], section.get('port',80))

        for row in reader:
            if row:
                data = {}

                year = row[keys['year']]

                name = smart_unicode(row[1], errors='ignore')
                name = name.replace('"', '')
                data['slug'] = slugify(name)

                for key, val in keys.items():
                    data[key] = row[val]

                if 'description' in data:
                    data['description'] = data['description'].replace('', '\n')

                # art locations are "time" and "distance"
                loc = row[keys['location']]
                if loc:
                    loc = loc.replace(" o'clock", '')
                    loc = loc.replace(" o’clock", '')

                    data['location_string'] = loc
                    if ' ' in loc:
                        timestr, distance = row[keys['location']].split(' ',1)
                        if timestr[0] in '0123456789':
                            if not ':' in timestr:
                                timestr = '%s:00' % timestr
                            data['time_address'] = timestr
                            distance = distance.split(',')[0]
                        try:
                            data['distance'] = int(distance)
                        except ValueError:
                            pass
                artist = data.get('artist','')
                if len(artist) > 255:
                    suffix = " [and more]"
                    artist = artist[:(255-len(suffix))]
                    pos = artist.rfind(' ')
                    if pos > -1:
                        artist = artist[:pos]
                    artist = "%s%s" % (artist, suffix)
                    data['artist'] = artist




                url = '/api/0.2/%s/art/' % year
                url = sign_url(url, section['authuser'], section['authkey'], seed = "%s%i" % (seed, ix))
                print "Updating ID#%s, Name: %s, Loc: %s" % (data.get('bm_fm_id','---'), data['name'], loc)
                resp, content = remote_json(remote, url, data=data, method='PUT')
                if resp['status'] != '200':
                    print 'error #%s\n%s\ndata: %s' % (resp['status'], content, data)
                    errct += 1
                else:
                    artct += 1
                ix += 1

        print ("done, loaded %i art installations, %i errors" % (artct, errct))