Skip to content

Commit

Permalink
get_data_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
yatan committed Nov 18, 2017
1 parent df812a5 commit cfb91a7
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions get_data_from_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,42 @@

db = sqlite3.connect('./web/data/crawler')

def check_existed_link_id(link_id):
cursor = db.cursor()
cursor.execute('SELECT COUNT(*) FROM data WHERE link_id="' + link_id + '"')
if cursor.fetchone()[0] == 0:
return False
else:
return True

def get_API(photo_url):
app = ClarifaiApp(api_key='f607cf42c8b64ff499931bdf6a5a53a6')
# get the general model
model = app.models.get("general-v1.3")
# predict with the model
response = model.predict_by_url(url=photo_url)

concepts = response['outputs'][0]['data']['concepts']
return concepts

''' for concept in concepts:
print(concept['name'], concept['value']) '''

cursor = db.cursor()
cursor.execute('SELECT * FROM links')
for row in cursor:
# row['name'] returns the name column in the query, row['email'] returns email column.
print "Geting: " + str(row[0]) + " " + row[2]
print "Geting info id: " + str(row[0]) + " url: " + row[2]

#print('Getting info link id {0} = {1}'.format(row["id"], row["link"]))

url1 = row[2]

app = ClarifaiApp(api_key='f607cf42c8b64ff499931bdf6a5a53a6')
# get the general model
model = app.models.get("general-v1.3")
# predict with the model
response = model.predict_by_url(url=url1)

concepts = response['outputs'][0]['data']['concepts']
# Get API info to DB
# for concept in concepts:
# print(concept['name'], concept['value'])
concepts = get_API(row[2])
for concept in concepts:
print(concept['name'], concept['value'])


db.close()


Expand Down

0 comments on commit cfb91a7

Please sign in to comment.