Beispiel #1
0
    def setUp(self):
        super(FivehundredPXTestCase, self).setUp()
        self.consumer_key = CONSUMER_KEY
        self.consumer_secret = CONSUMER_SECRET
        self.oauth_token = OAUTH_TOKEN
        self.oauth_token_secret = OAUTH_TOKEN_SECRET
        self.handler = OAuthHandler(self.consumer_key, self.consumer_secret)
        self.handler.set_access_token(self.oauth_token,
                                      self.oauth_token_secret)
        self.api = FiveHundredPXAPI(auth_handler=self.handler)
        self.unauthorized_api = FiveHundredPXAPI()

        if SECOND_USER:
            self.second_handler = OAuthHandler(self.consumer_key,
                                               self.consumer_secret)
            self.second_oauth_token = SECOND_OAUTH_TOKEN
            self.second_oauth_token_secret = SECOND_OAUTH_TOKEN_SECRET
            self.second_handler.set_access_token(
                self.second_oauth_token, self.second_oauth_token_secret)
            self.second_api = FiveHundredPXAPI(
                auth_handler=self.second_handler)

        self.follower_id = '925306'
        self.user_id = '642049'
        self.filepath = 'images/africa.jpg'
Beispiel #2
0
 def setUp(self):
     super(BaseTestCase, self).setUp()
     self.handler = OAuthHandler(self.consumer_key, self.consumer_secret)
     self.handler.set_access_token(self.oauth_token,
                                   self.oauth_token_secret)
     self.api = FiveHundredPXAPI(auth_handler=self.handler)
     self.unauthorized_api = FiveHundredPXAPI()
     self.follower_id = '925306'  # test user id
     self.user_id = '727199'  # this is akirahrkw's id
     self.photo = None  # sample photo for test
Beispiel #3
0
def get_location_images(land_mark_id):
    '''
    Function used to hooked in 500px API to get images based on location land mark.
    '''
    CONSUMER_KEY = 'RWABV8oGpEnZff17T3J7FM417m5l0NrO5zeQfrrF'
    CONSUMER_SECRET = 'C2ppB7O2NKXhzAZgK7N6Gd0rQL6aJI5OvQimysXG'

    handler = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    api = FiveHundredPXAPI(handler)
    land_mark = LandMark.objects.get(id=land_mark_id)

    photo = api.photos_search(
        rpp=10,
        only=
        "City and Architecture,Landscapes,Nature,Travel,Urban Exploration,Street, Commercial",
        term=land_mark.name,
        geo='%s,%s,5km' % (land_mark.latitude, land_mark.longitude),
        consumer_key=CONSUMER_KEY)

    if not photo['photos']:
        photo = api.photos_search(rpp=10,
                                  geo='%s,%s,5km' %
                                  (land_mark.latitude, land_mark.longitude),
                                  consumer_key=CONSUMER_KEY)

    if photo['photos']:
        for data in photo['photos']:
            images = data['images'][0]
            image_url = images['url']
            image_format = images['format']
            description = data['description']
            date_created = data['created_at']
            owner = data['user']['fullname']
            Image.objects.get_or_create(date_added=date_created,
                                        land_mark=land_mark,
                                        image=image_url,
                                        image_type=image_format,
                                        description=description,
                                        owner=owner)
Beispiel #4
0
	def __init__(self,searchEngine):
		self.searchEngine = searchEngine
		self.count = 0
		if searchEngine == 'google':
			self.baseDir = 'googleImageResults'
			self.rootUrl = 'https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q='
			self.apiKey = 'replace your api key here' # not needed if want < 64 images. Have not implemented the paid account version
			self.opUrlKey = 'unescapedUrl'
		elif searchEngine == 'bing':
			self.baseDir = 'bingImageResults'
			self.rootUrl = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?Query='
			self.apiKey = 'replace your api key here'
			self.opUrlKey = 'MediaUrl'
		elif searchEngine == '500px':
			self.baseDir = '500pxImageResults'
			self.CONSUMER_KEY = 'your consumer key here'
			self.CONSUMER_SECRET = 'your consumer secret here'
			self.opUrlKey = 'image_url'
			# oauth details
			self.handler = OAuthHandler(self.CONSUMER_KEY,self.CONSUMER_SECRET)
			self.requestToken = self.handler.get_request_token()
			self.handler.set_request_token(self.requestToken.key,self.requestToken.secret)
			username = raw_input("Input your username: "******"Press Enter")
			self.api.get_token_part_two((self.token,self.frob))
			# self.cc_licenses = '1, 2, 3, 4, 5, 6, 7' for cc license search
			self.cc_licenses = ''
Beispiel #5
0
from fivehundredpx.client import FiveHundredPXAPI
from os import environ
import numpy as np
import csv

CONSUMER_KEY = environ['PX_CONSUMER_KEY']
api = FiveHundredPXAPI()

feature_list = ['fresh_today']
maxlimit = 1000

allurls = np.chararray((maxlimit * len(feature_list), ), itemsize=300)
allratings = np.zeros((maxlimit * len(feature_list), ))

for idx, feature_type in enumerate(feature_list):
    photos = api.photos(consumer_key=CONSUMER_KEY,
                        feature=feature_type,
                        image_size=21,
                        sort_direction='asc',
                        page=1,
                        rpp=maxlimit)

    urls = map(lambda x: x['image_url'], photos['photos'])
    ratings = map(lambda x: x['highest_rating'], photos['photos'])
    allurls[idx * maxlimit:(idx + 1) * maxlimit] = urls
    allratings[idx * maxlimit:(idx + 1) * maxlimit] = ratings

_, idx = np.unique(allurls, return_index=True)

img = allurls[idx]
rat = allratings[idx]
    def get_land_mark(self):
        '''
        Get a list of images based pre-defined locations.
        Land marks and Images are accessed via the foursquare and 500px apis respectively.
        https://github.com/500px/api-documentation/
        https://developer.foursquare.com/docs/
        run python manage.py get_land_mark
        to import this data.
        '''
        default_locations = ['New York', 'Durban', 'Sydney']
        client_id = 'FJ3DPZHYKN2DWSGBFQFCTYZSO0QQFQWENMPG041GC1HMHN5R'
        client_secret = 'CQ2LADABJOEI4R5UTKUNXSCF0VT4GBQEZBJVY4OCLLV5CY1W'
        redirect_uri = 'http://fondu.com/oauth/authorize'
        CONSUMER_KEY = 'RWABV8oGpEnZff17T3J7FM417m5l0NrO5zeQfrrF'
        CONSUMER_SECRET = 'C2ppB7O2NKXhzAZgK7N6Gd0rQL6aJI5OvQimysXG'

        handler = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
        api = FiveHundredPXAPI(handler)
        client = foursquare.Foursquare(client_id=client_id,
                                       client_secret=client_secret,
                                       redirect_uri=redirect_uri)
        for location in default_locations:
            print "Getting Location Data For %s" % location
            data = client.venues.search(params={'near': location, 'limit': 1})
            name = data['venues'][0]['name']
            contact = data['venues'][0]['contact']
            data = data['venues'][0]['location']

            country = data['country'] if 'iNingizimu Afrika' != data[
                'country'] else 'South Africa'
            province = data['state'] if 'state' in data else 'Unknown'
            region = data['city'] if 'city' in data else location
            country_code = data['cc'] if 'cc' in data else 'Unknown'
            latitude = data['lat'] if 'lat' in data else 'Unknown'
            longitude = data['lng'] if 'lng' in data else 'Unknown'

            location_obj, created = Location.objects.get_or_create(
                country=country,
                province=province,
                region=region,
                cc=country_code,
                latitude=latitude,
                longitude=longitude)

            address = data['formattedAddress']
            latitude = data['lat']
            longitude = data['lng']

            if 'formattedPhone' in contact:
                number = contact['formattedPhone']
            else:
                number = None

            print "Getting Land Mark Data For %s" % location
            land_mark, created = LandMark.objects.get_or_create(
                name=name,
                address=address[0],
                latitude=latitude,
                longitude=longitude,
                phone_number=number,
                location=location_obj)

            print "Getting Image Data For %s" % location
            json = api.photos_search(
                only=
                "City and Architecture,Landscapes,Nature,Travel,Urban Exploration,Street, Commercial",
                rpp=10,
                term=land_mark.name,
                geo='%s,%s,5km' % (land_mark.latitude, land_mark.longitude),
                consumer_key=CONSUMER_KEY)

            if json['photos']:
                for data in json['photos']:
                    images = data['images'][0]
                    image_url = images['url']
                    image_format = images['format']
                    description = data['description']
                    date_created = data['created_at']
                    owner = data['user']['fullname']
                    Image.objects.get_or_create(date_added=date_created,
                                                land_mark=land_mark,
                                                image=image_url,
                                                image_type=image_format,
                                                description=description,
                                                owner=owner)
Beispiel #7
0
_CONSUMER_KEY = 'LvUFQHMQgSlaWe3aRQot6Ct5ZC2pdTMyTLS0GMfF'
_RPP = int(xbmcplugin.getSetting(fivehundredpxutils.xbmc.addon_handle, 'rpp'))
_LIMITP = str(
    xbmcplugin.getSetting(fivehundredpxutils.xbmc.addon_handle, 'limitpages'))
_MAXP = int(
    xbmcplugin.getSetting(fivehundredpxutils.xbmc.addon_handle, 'maxpages'))
_IMGSIZE = int(
    xbmcplugin.getSetting(fivehundredpxutils.xbmc.addon_handle, 'imgsize'))
_TMBSIZE = int(
    xbmcplugin.getSetting(fivehundredpxutils.xbmc.addon_handle, 'tmbsize'))
_USERNAME = str(
    xbmcplugin.getSetting(fivehundredpxutils.xbmc.addon_handle, 'username'))
_TMBFOLDERS = str(
    xbmcplugin.getSetting(fivehundredpxutils.xbmc.addon_handle, 'tmbfolders'))

API = FiveHundredPXAPI()


class Image(object):
    """ Holds information about a single image """
    def __init__(self, photo_json):
        self.name = photo_json['name']
        self.thumb_url = photo_json['images'][0]['url']
        self.url = photo_json['images'][1]['url']
        self.username = photo_json['user']['username']
        self.userfullname = photo_json['user']['fullname']

    def __repr__(self):
        return str(self.__dict__)