Skip to content

Commit

Permalink
Merge pull request #13 from jatsakthi/Version-5
Browse files Browse the repository at this point in the history
Version 5
  • Loading branch information
the-sakthi authored May 4, 2017
2 parents aa45e93 + e12a68e commit dbedb5b
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Foodie Friend/res/Process.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,25 @@ def __init__(self, bucket, filename, filetype, project_id):
def getFirstImage(self,query):
print "FUNCTION: getFirstImage"
Logger.log_writer("FUNCTION: getFirstImage")
resultFound = False
types = ('jpg','JPG','png')
current = 0
while current<=2 and resultFound == False:
res = self.cse_client.cse().list(
q=str(query),
cx='002657803801302330803:gatc1h4ugpi',
num=1,
searchType="image",
imgSize="medium",
imgType="photo",
fileType=types[current],
).execute()
#resultFound = False
#types = ('jpg')
#current = 0
#while current<=0 and resultFound == False:
res = self.cse_client.cse().list(
q=str(query),
cx='002657803801302330803:gatc1h4ugpi',
num=1,
searchType="image",
imgSize="medium",
imgType="photo",
fileType="jpg",
).execute()
'''
if len(res['items'])==1:
resultFound = True
else:
current += 1
'''
first_image_link = res['items'][0]['link']
print first_image_link
Logger.log_writer("Image Link:{}".format(first_image_link))
Expand All @@ -92,7 +94,7 @@ def upload_image(self,link):
}

stream = cStringIO.StringIO(urllib.urlopen(link).read())
req = self.gcs_client.objects().insert(bucket=self.bucket,body=body,media_body=e.MediaIoBaseUpload(stream, "image/"+str(ext)))
req = self.gcs_client.objects().insert(bucket=self.bucket,body=body,media_body=e.MediaIoBaseUpload(stream, "image/jpeg"))
resp = req.execute()
#Logger.log_writer("Response:{}".format(resp))
return resp
Expand Down

0 comments on commit dbedb5b

Please sign in to comment.