예제 #1
0
def test_request_passes_params():
    with mock.patch('requests.get') as fake_requests_get:
        client = Client(app_id=5678)
        client.request('thing', {'hello': 'there'})
        url = client.API_BASE_URL + '/thing.json'
        params = client.params.copy()
        params['hello'] = 'there'
        fake_requests_get.assert_called_with(url, params=params)
    def test_raises_error_for_bad_api_key(self, mock_requests_get):
        mock_result = {'message': 'Missing required request parameters: [app_id]'}
        mock_response = mock.MagicMock()
        mock_response.json.return_value = mock_result
        mock_requests_get.return_value = mock_response

        client = Client('')

        with self.assertRaises(BandsintownInvalidAppIdError):
            client.request('stuff')
예제 #3
0
    def test_raises_error_for_bad_api_key(self, mock_requests_get):
        mock_result = {
            'message': 'Missing required request parameters: [app_id]'
        }
        mock_response = mock.MagicMock()
        mock_response.json.return_value = mock_result
        mock_requests_get.return_value = mock_response

        client = Client('')

        with self.assertRaises(BandsintownInvalidAppIdError):
            client.request('stuff')
예제 #4
0
    def test_takes_date_param(self, mock_requests_get):
        data = [{'id': '1234'}]
        mock_requests_get.return_value = data

        client = Client('my-app-id')
        artist = 'Every Time I Die'
        date = '2018-01-15,2018-02-15'
        result = client.artists_events(artist, date)

        mock_requests_get.assert_called_with(
            'artists/Every%20Time%20I%20Die/events', {'date': date})
        self.assertEqual(result, data)
예제 #5
0
 def test_merges_passed_in_params(self, mock_requests_get):
     app_id = 5678
     date = '2018-01-01'
     client = Client(app_id)
     client.request('more/things', {'date': date})
     url = client.api_base_url + '/more/things'
     mock_requests_get.assert_called_with(
         url,
         headers={'Accept': 'application/json'},
         params={
             'app_id': app_id,
             'date': date
         })
    def test_takes_date_param(self, mock_requests_get):
        data = [{'id': '1234'}]
        mock_requests_get.return_value = data

        client = Client('my-app-id')
        artist = 'Every Time I Die'
        date = '2018-01-15,2018-02-15'
        result = client.artists_events(artist, date)

        mock_requests_get.assert_called_with(
            'artists/Every%20Time%20I%20Die/events',
            {'date': date}
        )
        self.assertEqual(result, data)
 def test_merges_passed_in_params(self, mock_requests_get):
     app_id = 5678
     date = '2018-01-01'
     client = Client(app_id)
     client.request('more/things', {'date': date})
     url = client.api_base_url + '/more/things'
     mock_requests_get.assert_called_with(
         url,
         headers={'Accept': 'application/json'},
         params={
             'app_id': app_id,
             'date': date
         }
     )
예제 #8
0
    def test_builds_and_executes_request(self, mock_requests_get):
        mock_result = {'name': 'Bad Religion'}
        mock_response = mock.MagicMock()
        mock_response.json.return_value = mock_result
        mock_requests_get.return_value = mock_response

        app_id = 5678
        client = Client(app_id)
        result = client.request('things')
        url = client.api_base_url + '/things'
        mock_requests_get.assert_called_with(
            url,
            headers={'Accept': 'application/json'},
            params=client.default_params)
        self.assertEqual(mock_result, result)
예제 #9
0
    def test_init_stores_properties(self):
        app_id = 1234
        client = Client(app_id)

        self.assertEqual(client.api_base_url, 'https://rest.bandsintown.com')
        self.assertEqual(client.app_id, app_id)
        self.assertEqual(client.default_params, {'app_id': app_id})
예제 #10
0
def event_form():
	if request.method == 'GET':
		return redirect(url_for('index_form'))
	name = request.form['artist'].lstrip()

	#Bandsintown API 
	client = Client('bitapp')
	events = client.events(name)
	
	event_list = {}
	if events != []:
		for event in events:
			event_list[event['formatted_location']] = event['formatted_datetime'] 
		return render_template('events.html', name=name, events=event_list)
	else:
		return render_template('nothing.html')
    def test_builds_and_executes_request(self, mock_requests_get):
        mock_result = {'name': 'Bad Religion'}
        mock_response = mock.MagicMock()
        mock_response.json.return_value = mock_result
        mock_requests_get.return_value = mock_response

        app_id = 5678
        client = Client(app_id)
        result = client.request('things')
        url = client.api_base_url + '/things'
        mock_requests_get.assert_called_with(
            url,
            headers={'Accept': 'application/json'},
            params=client.default_params
        )
        self.assertEqual(mock_result, result)
예제 #12
0
    def test_requests_artist_events(self, mock_requests_get):
        data = [{
            'id': '20590797',
            'datetime': '2018-05-04T13:00:00'
        }, {
            'id': '21752009',
            'datetime': '2018-05-05T19:00:00'
        }]
        mock_requests_get.return_value = data

        client = Client('my-app-id')
        artist = 'Every Time I Die'
        result = client.artists_events(artist)

        mock_requests_get.assert_called_with(
            'artists/Every%20Time%20I%20Die/events', {})
        self.assertEqual(result, data)
    def test_requests_artist_events(self, mock_requests_get):
        data = [
            {
                'id': '20590797',
                'datetime': '2018-05-04T13:00:00'
            },
            {
                'id': '21752009',
                'datetime': '2018-05-05T19:00:00'
            }
        ]
        mock_requests_get.return_value = data

        client = Client('my-app-id')
        artist = 'Every Time I Die'
        result = client.artists_events(artist)

        mock_requests_get.assert_called_with('artists/Every%20Time%20I%20Die/events', {})
        self.assertEqual(result, data)
    def test_requests_artist(self, mock_request):
        artist = 'Bad Religion'
        data = {
            'facebook_page_url': 'https://www.facebook.com/badreligion',
            'upcoming_event_count': 8,
            'name': 'Bad Religion',
            'url': 'https://www.bandsintown.com/a/658?came_from=267&app_id=bandsintown-test-client',
            'tracker_count': 476952,
            'mbid': '149e6720-4e4a-41a4-afca-6d29083fc091',
            'image_url': 'https://s3.amazonaws.com/bit-photos/large/6277078.jpeg',
            'thumb_url': 'https://s3.amazonaws.com/bit-photos/thumb/6277078.jpeg',
            'id': '658'
        }
        mock_request.return_value = data

        client = Client(1234)
        result = client.artists(artist)

        self.assertEqual(result, data)
        mock_request.assert_called_once_with('artists/Bad%20Religion')
예제 #15
0
    def test_requests_artist(self, mock_request):
        artist = 'Bad Religion'
        data = {
            'facebook_page_url': 'https://www.facebook.com/badreligion',
            'upcoming_event_count': 8,
            'name': 'Bad Religion',
            'url':
            'https://www.bandsintown.com/a/658?came_from=267&app_id=bandsintown-test-client',
            'tracker_count': 476952,
            'mbid': '149e6720-4e4a-41a4-afca-6d29083fc091',
            'image_url':
            'https://s3.amazonaws.com/bit-photos/large/6277078.jpeg',
            'thumb_url':
            'https://s3.amazonaws.com/bit-photos/thumb/6277078.jpeg',
            'id': '658'
        }
        mock_request.return_value = data

        client = Client(1234)
        result = client.artists(artist)

        self.assertEqual(result, data)
        mock_request.assert_called_once_with('artists/Bad%20Religion')
예제 #16
0
def test_artists_get_artist_id_mbid():
    client = Client('epitaph')
    assert client._get_artist_identifier(mbid=1234) == 'mbid_1234'
예제 #17
0
key = "bd482854c87eb7bc0c93d51#5ec3bbc29:236745327645sjd374"

from bandsintown import Client
from math import asin, sqrt, sin, cos, pi

client = Client(key.split(":")[0].replace("#", ""))


def prune_concerts(concert_list):

    pruned_concerts = []

    try:

        first_item = concert_list[0]

        artist_name = first_item['artist']["name"]
        artist_photo = first_item['artist']["thumb_url"]
        artist_bit_id = first_item['artist']["id"]
        first_item_datetime = first_item["datetime"]
        first_item_artist_description = first_item["description"]
        first_item_concert_id = first_item["id"]
        first_item_offers = first_item["offers"]
        first_item_venue = first_item["venue"]

        pruned_concerts.append({
            "name": artist_name,
            "photo": artist_photo,
            "artist_id": artist_bit_id,
            "date": first_item_datetime,
            "description": first_item_artist_description,
예제 #18
0
"""
    A series of examples for using the bandsintown api wrapper
"""
from bandsintown import Client

# create the client
b = Client(app_id="Your APP_ID")


# lookup an artist by name
artist = b.lookup_artist(artist_name="Skrillex")
print artist.url

    # http://www.bandsintown.com/Skrillex


# lookup artist by mbid
artist = b.lookup_artist(mbid="65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab")
print artist.name 

    # Metallica


# lookup single artist's events by name
events = b.get_artist_events(artist_name="Skrillex")
for event in events:
    print event.venue.name.encode('utf-8')

    # Dog Blood @ Lollapalooza Berlin
    # Bestival
    # RTU Ultra
예제 #19
0
from bandsintown import Client
import json
from get_liked_tracks import get_liked_tracks



client = Client('mybandapp')


artists_names = get_liked_tracks()
concert_list = []

for artist in artists_names:
    try:
        concert = client.artists_events(artist)
    except json.JSONDecodeError : 
        pass
    for i in concert:
        try:
            if i['venue']['location'] == 'Moscow, Russia':
                moscow =  i['venue']['location']
                date = i['datetime']
                club = i['venue']['name']
                concert_list.append(f'{artist} ---- {moscow} ----- {date} ---- {club}')
        except (TypeError):
            pass


for i in concert_list:
    print(i)
예제 #20
0
 def test_returns_none_for_artist_not_found(self, mock_request):
     mock_request.side_effect = ValueError(
         'No JSON object could be decoded')
     client = Client(1234)
     self.assertIsNone(client.artists('foo'))
예제 #21
0
def test_artists_recommended_with_radius(fake_request):
    client = Client('epitaph')
    client.recommended('Bad Religion', location='Portland,OR', radius=125)
    fake_request.assert_called_with('artists/Bad%20Religion/events/recommended', {'location': 'Portland,OR', 'radius': 125})
예제 #22
0
def test_artists_get_artist_id_string():
    client = Client('epitaph')
    assert client._get_artist_identifier('Bad Religion') == 'Bad%20Religion'
 def test_raises_error_for_invalid_date(self, mock_requests_get):
     mock_requests_get.return_value = {'errors': ['Invalid date format']}
     client = Client('my-app-id')
     with self.assertRaises(BandsintownInvalidDateFormatError):
         client.artists_events('bar', 'florp')
 def test_returns_none_when_artist_not_found(self, mock_requests_get):
     mock_requests_get.return_value = {'errors': ['Unknown Artist']}
     client = Client('my-app-id')
     self.assertIsNone(client.artists_events('foo'))
예제 #25
0
 def test_returns_none_when_artist_not_found(self, mock_requests_get):
     mock_requests_get.return_value = {'errors': ['Unknown Artist']}
     client = Client('my-app-id')
     self.assertIsNone(client.artists_events('foo'))
예제 #26
0
def test_artists_search(fake_request):
    client = Client('epitaph')
    client.search('Bad Religion', location='Portland,OR')
    fake_request.assert_called_with('artists/Bad%20Religion/events/search', {'location': 'Portland,OR'})
예제 #27
0
"""
    A series of examples for using the bandsintown api wrapper
"""
from bandsintown import Client

# create the client
b = Client(app_id="Your APP_ID")


# lookup an artist by name
artist = b.lookup_artist(artist_name="Skrillex")
print artist.url

# http://www.bandsintown.com/Skrillex


# lookup artist by mbid
artist = b.lookup_artist(mbid="65f4f0c5-ef9e-490c-aee3-909e7ae6b2ab")
print artist.name

# Metallica


# lookup single artist's events by name
events = b.get_artist_events(artist_name="Skrillex")
for event in events:
    print event.venue.name.encode("utf-8")

    # Dog Blood @ Lollapalooza Berlin
    # Bestival
    # RTU Ultra
 def test_returns_none_when_no_events_found(self, mock_requests_get):
     mock_requests_get.return_value = []
     client = Client('my-app-id')
     self.assertEqual(client.artists_events('bar'), [])
예제 #29
0
def test_request_generates_url():
    with mock.patch('requests.get') as fake_requests_get:
        client = Client(app_id=5678)
        client.request('thing')
        url = client.API_BASE_URL + '/thing.json'
        fake_requests_get.assert_called_with(url, params=client.params)
예제 #30
0
def test_artists_events_with_date(fake_request):
    client = Client('epitaph')
    client.events('Bad Religion', date='2015-01-01')
    fake_request.assert_called_with('artists/Bad%20Religion/events', {'date': '2015-01-01'})
예제 #31
0
def test_artists_events(fake_request):
    client = Client('epitaph')
    client.events('Bad Religion')
    fake_request.assert_called_with('artists/Bad%20Religion/events', {})
예제 #32
0
 def test_returns_none_when_no_events_found(self, mock_requests_get):
     mock_requests_get.return_value = []
     client = Client('my-app-id')
     self.assertEqual(client.artists_events('bar'), [])
예제 #33
0
def test_artists_search_with_date(fake_request):
    client = Client('epitaph')
    client.search('Bad Religion', location='Portland,OR', radius=100, date='2015-02-03')
    fake_request.assert_called_with('artists/Bad%20Religion/events/search', {'location': 'Portland,OR', 'radius': 100, 'date': '2015-02-03'})
 def test_returns_none_for_artist_not_found(self, mock_request):
     mock_request.side_effect = ValueError('No JSON object could be decoded')
     client = Client(1234)
     self.assertIsNone(client.artists('foo'))
예제 #35
0
 def test_raises_error_for_invalid_date(self, mock_requests_get):
     mock_requests_get.return_value = {'errors': ['Invalid date format']}
     client = Client('my-app-id')
     with self.assertRaises(BandsintownInvalidDateFormatError):
         client.artists_events('bar', 'florp')
예제 #36
0
import requests
import random
from bandsintown import Client
import logging

client = Client('technopark_ruliiiit')

URL = 'http://api.musicgraph.com/api/v2/artist/search?'

API = 'a64bda6196fb21ac8bfdca756803a746'

#itunes:
#"https://itunes.apple.com/search?term=music&genreId"

def get_by_genre(genre):
    default = {
        'api_key': API,
        'genre': genre,
        'limit': 100
    }

    data = requests.get(URL, params=default).json()
    artists = data['data']
    artists_name = []
    for i in range(5):
        artists_name.append(random.choice(artists)['name'])
    return artists_name


def get_similar_artists(artist):
    default = {
예제 #37
0
def test_artists_recommended_with_only_recs_false(fake_request):
    client = Client('epitaph')
    client.recommended('Bad Religion', location='Portland,OR', radius=125, date='2015-10-10', only_recs=False)
    fake_request.assert_called_with('artists/Bad%20Religion/events/recommended', {'location': 'Portland,OR', 'radius': 125, 'date': '2015-10-10', 'only_recs': 'false'})