Created
September 20, 2013 22:20
-
-
Save jackbillstrom/6644679 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Import | |
import urllib.request as urllib, simplejson as json, requests | |
################### | |
##REKOGNITION API## | |
################### | |
api_key = "J6Ae2VVVGb1cyAbg" #Rekognition API | |
api_secret = "hffKwlkifKuhTTAG" #Rekognition Secret | |
file_path = "https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-ash3/526864_633402230024779_1245785159_n.jpg" #Identify this face | |
namespace = "multify" #Rekognition namespace | |
user = "demo" #Rekognition user | |
url = 'http://rekognition.com/func/api/?api_key='+api_key+'&api_secret='+api_secret+'&jobs=face_recognize&urls='+file_path+'&name_space='+namespace+'&user_id='+user | |
response = urllib.urlopen(url) #Load response from this URL above | |
data = json.load(response) #Load the JSON to our module | |
shorty = data['face_detection'][0]['name'] #Gets bestmatch | |
head, sep, tail = shorty.partition(':') #Grabs users Facebook ID | |
################## | |
###FACEBOOK API### | |
################## | |
grabAT = requests.get('https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=1416237755258873&client_secret=cce5fe7de3a2eeaaa6e425d12f190a17') | |
access_token = "CAACEdEose0cBAGRVqnS4VlJ2WUJGeHDiRafE0D6bioZAK56OLqPm8pjFnYyEtURushnU5zqy1I3pJ4qWG5fZCXVmGIIaXZApxRTsdB2wxFOYurvp2zKq0kouV9YCpJdK22UJgtTSvJA6eJ8a0NhDFmQDUKZAWAZBLpFcabwYiI32jkkjr4yhK5hdhDaDb38AZD" | |
graphUrl = "https://graph.facebook.com/"+head+"/music?fields=name&limit=10000&offset=0&access_token="+access_token #Gets identified users music | |
responseFB = urllib.urlopen(graphUrl) #Open the URL | |
dataFB = json.load(responseFB) #Load the JSON to our module | |
antalArtister = len(dataFB['data']) #Count number of artists | |
#print (graphUrl) | |
################## | |
###LAST.FM API#### | |
musicTaste = "" | |
musicTasteArray = [] | |
musicTasteLength = "" | |
lastFM_api = "762c907e80910cf2653c74aead0ed728" | |
################## | |
################## | |
###COUNT ARTISTS## | |
################## | |
for i in range(0, antalArtister): | |
try: | |
musicTaste = dataFB['data'][i]['name'] | |
lastFM_url = "http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist="+musicTaste+"&api_key="+lastFM_api+"&format=json" | |
r = requests.get(lastFM_url) | |
print (r.json()['toptracks']['track'][i]['name']) | |
except: | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment