def services_list_test(): global failed global passed api = API("nbsmobile") resp = json.loads(api.servicesList()) if resp["1"]["name"] == "MYSPACE" and resp["36"]["name"] == "PANDORA": passed += 1 else: failed += ["artist_add_test( )"]
def artist_view_test(): global failed global passed api = API("nbsmobile") resp = json.loads(api.artistView("356")) if resp["music_brainz_id"] == "164f0d73-1234-4e2c-8743-d77bf2191051": passed += 1 else: failed += ["artist_view_test_( )"]
def metrics_profile_test(): global failed global passed api = API("nbsmobile") resp = json.loads(api.metricsProfile("388")) if resp["plays"] and resp["fans"] and resp["views"]: passed += 1 else: failed += ["metrics_profile_test( )"]
def metrics_artist_test(): global failed global passed api = API("nbsmobile") resp = json.loads(api.metricsArtist("356")) if resp[0]["Service"]["name"] == "MySpace": passed += 1 else: failed += ["metrics_artist_test( )"]
def genres_artist_test(): global failed global passed api = API("nbsmobile") resp = json.loads(api.genresArtist("356")) if resp["2"]["name"] == "HipHop": passed += 1 else: failed += ["genres_artist_test( )"]
def profiles_search_test(): global failed global passed api = API("nbsmobile"); resp = json.loads(api.profilesSearch("http://www.myspace.com/kanyewest")) if resp["356"]["music_brainz_id"] == "164f0d73-1234-4e2c-8743-d77bf2191051": passed += 1 else: failed += ["profiles_search_test( )"]
def profiles_artist_test(): global failed global passed api = API("nbsmobile") resp = json.loads(api.profilesArtist("356")) if resp["388"]["name"] == "MySpace": passed += 1 else: failed += ["profiles_artist_test( )"]
def artist_search_test(): global failed global passed api = API("nbsmobile"); resp = json.loads(api.artistSearch("Kanye")) if resp["356"]["music_brainz_id"] == "164f0d73-1234-4e2c-8743-d77bf2191051": passed += 1 else: failed += ["artist_search_test( )"]
def metrics_artist_test(): global failed global passed api = API("nbsmobile", "", ".xml") resp = xml.dom.minidom.parseString(api.metricsArtist("388")) service = resp.getElementsByTagName("service")[0].childNodes[0].data if service == "MySpace": passed += 1 else: failed.append("metrics_artist_test( )")
def profiles_search_test(): global failed global passed api = API("nbsmobile") resp = json.loads(api.profilesSearch("http://www.myspace.com/kanyewest")) if resp["356"][ "music_brainz_id"] == "164f0d73-1234-4e2c-8743-d77bf2191051": passed += 1 else: failed += ["profiles_search_test( )"]
def profiles_artist_test(): global failed global passed api = API("nbsmobile", "", ".xml") resp = xml.dom.minidom.parseString(api.profilesArtist("356")) service = resp.getElementsByTagName("service")[9].childNodes[0].data if(service == "MySpace"): passed += 1 else: failed.append("profiles_artist_test()")
def metrics_profile_test(): global failed global passed api = API("nbsmobile", "", ".xml") resp = xml.dom.minidom.parseString(api.metricsProfile("388")) metrics = len(resp.getElementsByTagName("metric")) if(metrics==4): passed += 1 else: failed.append("metrics_profile_test( )")
def genres_artist_test(): global failed global passed api = API("nbsmobile","", ".xml") resp = xml.dom.minidom.parseString(api.genresArtist("356")) genre = resp.getElementsByTagName("name")[1].childNodes[0].data if(genre == "HipHop"): passed += 1 else: failed.append("artist_ranking_test( )")
def genres_artist_test(): global failed global passed api = API("nbsmobile", "", ".xml") resp = xml.dom.minidom.parseString(api.genresArtist("356")) genre = resp.getElementsByTagName("name")[1].childNodes[0].data if genre == "HipHop": passed += 1 else: failed.append("artist_ranking_test( )")
def metrics_profile_test(): global failed global passed api = API("nbsmobile", "", ".xml") resp = xml.dom.minidom.parseString(api.metricsProfile("388")) metrics = len(resp.getElementsByTagName("metric")) if metrics == 4: passed += 1 else: failed.append("metrics_profile_test( )")
def profiles_search_test(): global failed global passed api = API("nbsmobile","", ".xml") resp = xml.dom.minidom.parseString(api.profilesSearch("http://www.myspace.com/kanyewest")) music_id = resp.getElementsByTagName("music_brainz_id")[0].childNodes[0].data if(music_id == "164f0d73-1234-4e2c-8743-d77bf2191051"): passed += 1 else: failed.append("profile_search_test( )")
def profiles_search_test(): global failed global passed api = API("nbsmobile", "", ".xml") resp = xml.dom.minidom.parseString(api.profilesSearch("http://www.myspace.com/kanyewest")) music_id = resp.getElementsByTagName("music_brainz_id")[0].childNodes[0].data if music_id == "164f0d73-1234-4e2c-8743-d77bf2191051": passed += 1 else: failed.append("profile_search_test( )")
def artist_search_test(): global failed global passed api = API("nbsmobile", "", ".xml") resp = xml.dom.minidom.parseString(api.artistSearch("Kanye")) music_id = resp.getElementsByTagName("music_brainz_id")[0].childNodes[0].data if music_id == "164f0d73-1234-4e2c-8743-d77bf2191051": passed += 1 else: failed.append("artist_search_test( )")
def artist_view_test(): global failed global passed api = API("nbsmobile", "", ".xml") resp = xml.dom.minidom.parseString(api.artistView("356")) music_id = resp.getElementsByTagName("music_brainz_id")[0].childNodes[0].data if(music_id == "164f0d73-1234-4e2c-8743-d77bf2191051"): passed += 1 else: failed.append("artist_view_test( )")
def artist_add_test(): global failed global passed api = API("nbsmobile", "ad644d582c7dcf7dc29479ff2d4df1ef") name = "Long Miles" profiles = ["http://www.facebook.com/longmiles"] resp = json.loads(api.artistAdd(name, profiles)) if resp['message'] == "That Artist already exists in our system [#324157]": passed += 1 else: failed += ["artist_add_test( )"]
def artist_ranking_test(): global failed global passed api = API("nbsmobile") ids = [356, 659, 8309] type = "nominal" resp = json.loads(api.artistRanking(type, ids)) if (resp[0]["name"] == "Lady Gaga"): passed += 1 else: failed += ["artist_ranking_test( )"]
def profiles_add_test(): global failed global passed api = API("nbsmobile", "ad644d582c7dcf7dc29479ff2d4df1ef", ".xml") profiles = ["http://www.myspace.com/longmiles"] resp = xml.dom.minidom.parseString(api.profilesAdd("324157", profiles)) name = resp.getElementsByTagName("name")[0].childNodes[0].data if(name == "Long Miles"): passed += 1 else: failed.append("profiles_add_test( )")
def profiles_add_test(): global failed global passed api = API("nbsmobile", "ad644d582c7dcf7dc29479ff2d4df1ef", ".xml") profiles = ["http://www.myspace.com/longmiles"] resp = xml.dom.minidom.parseString(api.profilesAdd("324157", profiles)) name = resp.getElementsByTagName("name")[0].childNodes[0].data if name == "Long Miles": passed += 1 else: failed.append("profiles_add_test( )")
def profiles_add_test(): global failed global passed api = API("nbsmobile", "ad644d582c7dcf7dc29479ff2d4df1ef") name = "Long Miles" profiles = ["http://www.myspace.com/longmiles"] resp = json.loads(api.profilesAdd("324157", profiles)) if resp['name'] == "Long Miles": passed += 1 else: failed += ["artist_add_test( )"]
def artist_add_test(): global failed global passed api = API("nbsmobile", "ad644d582c7dcf7dc29479ff2d4df1ef", ".xml") profiles = ["http://www.myspace.com/longmiles"] name = "Long Miles" resp = xml.dom.minidom.parseString(api.artistAdd(name , profiles)) message = resp.getElementsByTagName("message")[0].childNodes[0].data if(message == "That Artist already exists in our system [#324157]"): passed += 1 else: failed.append("artist_ranking_test( )")
def artist_add_test(): global failed global passed api = API("nbsmobile", "ad644d582c7dcf7dc29479ff2d4df1ef", ".xml") profiles = ["http://www.myspace.com/longmiles"] name = "Long Miles" resp = xml.dom.minidom.parseString(api.artistAdd(name, profiles)) message = resp.getElementsByTagName("message")[0].childNodes[0].data if message == "That Artist already exists in our system [#324157]": passed += 1 else: failed.append("artist_ranking_test( )")
def services_list_test(): global failed global passed api = API("nbsmobile", "", ".xml") resp = xml.dom.minidom.parseString(api.servicesList()) elements = resp.getElementsByTagName("name") names = [] for i in elements: names.append(i.childNodes[0].data) if(names[0] == "MYSPACE" and names[12] == "PANDORA"): passed += 1 else: failed.append("services_list_test( )")
def services_list_test(): global failed global passed api = API("nbsmobile", "", ".xml") resp = xml.dom.minidom.parseString(api.servicesList()) elements = resp.getElementsByTagName("name") names = [] for i in elements: names.append(i.childNodes[0].data) if names[0] == "MYSPACE" and names[12] == "PANDORA": passed += 1 else: failed.append("services_list_test( )")
def artist_ranking_test(): global failed global passed api = API("nbsmobile", "", ".xml") ids = [356, 659, 8309] type = "nominal" resp = xml.dom.minidom.parseString(api.artistRanking(type, ids)) elements = resp.getElementsByTagName("name") names = [] for i in elements: names.append(i.childNodes[0].data) if(names[0] == "Lady Gaga" and names[1] == "Kanye West" and names[2] == "Chiddy Bang"): passed += 1 else: failed.append("artist_ranking_test( )")
def artist_ranking_test(): global failed global passed api = API("nbsmobile", "", ".xml") ids = [356, 659, 8309] type = "nominal" resp = xml.dom.minidom.parseString(api.artistRanking(type, ids)) elements = resp.getElementsByTagName("name") names = [] for i in elements: names.append(i.childNodes[0].data) if names[0] == "Lady Gaga" and names[1] == "Kanye West" and names[2] == "Chiddy Bang": passed += 1 else: failed.append("artist_ranking_test( )")
from urllib2 import urlopen # python 2.7 version #import urlopen from json import load #import sqlite3 #import csv #import codecs #import cStringIO #import sys import hashlib # nbs api python wrapper from nbs_api import API import json #api = API("nbsmobile") api = API("swahl") # In[4]: # basic musicbrainz search import musicbrainzngs import sys musicbrainzngs.set_useragent( "cdips-music-data-project", "0.1", 'https://github.com/trxw/CDIPS_PandoraTeam', ) # In[6]:
artistFile = open("artists2.csv") artistReader = csv.reader( artistFile, delimiter=',', ) # Count rows in file, initialize data structure artistCount = sum(1 for row in artistReader) - 1 summary = [] followers = [] mentions = [] artistFile.seek(0) # Get artist names from second column in file i = 0 api = API("nbsmobile") for artist in artistReader: # Get chart date, tracking start and end dates, artist name startDate = datetime.strptime('2018-08-14', '%Y-%m-%d') endDate = datetime.strptime('2018-11-09', '%Y-%m-%d') #startDate = datetime.strptime(sys.argv[2], '%Y-%m-%d') #endDate = datetime.strptime(sys.argv[3], '%Y-%m-%d') name = str(artist[0]) # Get artist info try: artistInfo = json.loads(api.artistSearch(name.replace("_", ","))) nbsId = list(artistInfo.keys())[0] except: # If artist doesn't exist in NBS print(datetime.now().strftime("%H:%M:%S") + "> artist " + str(i + 1) +