コード例 #1
0
# Temporary until real install is setup
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../lib'))

import eyefi

logging.basicConfig(level=logging.INFO)

eyefi.set_token(eyefi.get_home_token())

###
### First search all the user's files for the 'APITestFile' file so we have an object to work with
###
### A good sequence to run this example is to do files_create.py first
###

page_params = {'page': 1, 'per_page': 100}
fileitems = eyefi.Files().get(params=page_params)['items']

for fileitem in fileitems:
    if (fileitem['name'] == 'APITestFile.jpg'):
        fileid = fileitem['id']
        break

if (fileid == None):
    print 'Please add a file named APITestFile.jpg to your library first'
    exit(-1)

eyefi.Files().delete(fileid)

コード例 #2
0
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../lib'))

import eyefi

logging.basicConfig(level=logging.INFO)

eyefi.set_token(eyefi.get_home_token())

###
### First search all the user's files for the 'APITestFile' file so we have an object to work with
###
### A good sequence to run this example is to do files_create.py first
###

page_params = {'page': 1, 'per_page': 100}
fileitems = eyefi.Files().get(params=page_params)['items']

for fileitem in fileitems:
    if (fileitem['name'] == 'APITestFile.jpg'):
        fileid = fileitem['id']
        break

if (fileid == None):
    print 'Please add a file named APITestFile.jpg to your library first'
    exit(-1)

###
### Add a tag called APITestTag to the file
###

eyefi.Files().add_tags(fileid, {'name': 'APITestTag'})
コード例 #3
0
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../lib'))

import eyefi

logging.basicConfig(level=logging.INFO)

eyefi.set_token(eyefi.get_home_token())

###
### First search all the user's files for the 'APITestFile' file so we have an object to work with
###
### A good sequence to run this example is to do files_create.py first
###

page_params = {'page': 1, 'per_page': 100}
fileitems = eyefi.Files().get(params=page_params)['items']

for fileitem in fileitems:
    if (fileitem['name'] == 'APITestFile.jpg'):
        fileid = fileitem['id']
        break

if (fileid == None):
    print 'Please add a file named APITestFile.jpg to your library first'
    exit(-1)

###
### List tags on this file
###

tagitems = eyefi.Files().get_tags(fileid)
コード例 #4
0
albumresponse = eyefi.Albums().create({'name': albumname})
albumid = albumresponse['id']
if (albumid == None):
    print 'Album ' + albumname + ' failed to create.'
    exit(-1)

print 'Created Album ' + albumname

### Upload the photos and attach them to the album

for fileitem in fileitems:
    ### Get the file modified time and use as date_time_taken..
    datetimestampformatted = time.strftime('%Y-%m-%dT%H:%M:%S', time.localtime(os.path.getmtime(fileitem)))
    data = {'date_time_taken': datetimestampformatted}

    files = {fileitem: open(fileitem,'rb')}

    fileresponse = eyefi.Files().create(data, files)

    fileid = fileresponse['id']
    if (fileid == None):
        print 'File ' + fileitem + ' failed to upload properly.'
        exit(-1)
    else:
        ### add_files expects an array of files
        eyefi.Albums().add_files(albumid, [ {'id': fileid} ])

        print 'Uploaded ' + fileitem

コード例 #5
0
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../lib'))

import eyefi

logging.basicConfig(level=logging.INFO)

eyefi.set_token(eyefi.get_home_token())

###
### First search all the user's files for the 'APITestFile' file so we have an object to work with
###
### A good sequence to run this example is to do files_create.py first
###

page_params = {'page': 1, 'per_page': 100}
fileitems = eyefi.Files().get(params=page_params)['items']

for fileitem in fileitems:
    if (fileitem['name'] == 'APITestFile.jpg'):
        fileid = fileitem['id']

if (fileid == None):
    print 'Please add a file named APITestFile.jpg to your library first'
    exit(-1)

###
### List tags on this file
###

tagitems = eyefi.Files().get_tags(fileid)
コード例 #6
0
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../lib'))

import eyefi

logging.basicConfig(level=logging.INFO)

eyefi.set_token(eyefi.get_home_token())

###
### First search all the user's albums for the 'APITestAlbum' album so we have an object to work with
###
### A good sequence to run this example is to do albums_create.py first
###

albumitems = eyefi.Albums().get()

for albumitem in albumitems:
    if (albumitem['name'] == 'APITestAlbum'):
        selected_album = albumitem['id']
        break

###
### Now grab 3 files to add to the album.  A list of files is stored under the 'items' key returned
### from Files().get()
###

fileitems = eyefi.Files().get()['items']
del fileitems[3:]

eyefi.Albums().add_files(selected_album, fileitems)
コード例 #7
0
# Temporary until real install is setup
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../lib'))

import eyefi

logging.basicConfig(level=logging.INFO)

eyefi.set_token(eyefi.get_home_token())

###
### API Call is Files().get() - list all files for user
### Note that Files().get() supports paging and so will return an 'items' dictionary entry with the array of files.
###

page_params = {'page': 1, 'per_page': 100}
fileitems = eyefi.Files().get(params=page_params)['items']

for fileitem in fileitems:
    if (fileitem['name'] == 'APITestFile.jpg'):
        fileurl = fileitem['media']
        break

###
### The 'media' url on a file object is sufficient to download the file
###

urllib.urlretrieve(fileurl, 'APITestFileDownloaded.jpg')



コード例 #8
0
import sys
import os
import logging

# Temporary until real install is setup
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '../lib'))

import eyefi

logging.basicConfig(level=logging.INFO)

eyefi.set_token(eyefi.get_home_token())

###
### API Call is Files().create() - upload a new .jpg file
###

### A timestamp for the photo is required as a data element

data = {'date_time_taken': '2014-12-31T12:00:00+00:00'}

### The SDK requires that a files dictionary be created with the filename as the key and a filehandle to the file
### as the value.  The API has a 100MB limit and the implementation will read the entire file into memory before
### upload.

files = {'APITestFile.jpg': open('APITestFile.jpg', 'rb')}

fileitem = eyefi.Files().create(data, files)
コード例 #9
0
###
### Tag everything near Disneyland with the tag 'Disneyland'
###

url = 'https://maps.googleapis.com/maps/api/geocode/json?address=Disneyland'
response = urllib2.urlopen(url)
result = json.loads(response.read())['results'][0]

lat_param = result['geometry']['location']['lat']
lon_param = result['geometry']['location']['lng']

###
### Execute ad-hoc search within 10 miles of this location.  Note that Search().get() is also paged similarly
### to Files().get()
###

page_params = {'page': 1, 'per_page': 100}
search_data = {
    'has_geodata': True,
    'geo_lat': lat_param,
    'geo_lon': lon_param,
    'geo_distance': '10mi'
}

fileitems = eyefi.Search().get(data=search_data, params=page_params)['items']

### Add the tag 'Disneyland' to the files.  Note that we didn't have to create the Disneyland tag first
### and can refer to it by name instead of id.
for fileitem in fileitems:
    eyefi.Files().add_tags(fileitem['id'], {'name': 'Disneyland'})
コード例 #10
0
###
### Search for a file named 'warholme.jpg', download it, crop it square, turn it grayscale, colorize it,
### create a mosaic, and upload it as 'warholized.jpg'.
###
### Note that this example uses the Pillow fork of the Python Imaging Library (PIL).
### For instructions (including installation) see: https://pillow.readthedocs.org/
###

### Get the 'warholizeme.jpg' photo
#page_params = {'page': 1, 'per_page': 100}
#search_data = { 'name': 'warholizeme.jpg' }
#fileitems = eyefi.Search().get(data=search_data, params=page_params)['items']

page_params = {'page': 1, 'per_page': 1000}
fileitems = eyefi.Files().get(params=page_params)['items']

for fileitem in fileitems:
    if (fileitem['name'] == 'warholizeme.jpg'):
        url = fileitem['media']
        break

response = urllib2.urlopen(url)
im = Image.open(StringIO(response.read()))

### Crop the photo to a square
width = im.size[0]
height = im.size[1]

box = (0, 0, 0, 0)
if width < height: