- import simplejson
- import urllib2
-
-
- # Create a new app and copy the credentials it creates
- CLIENT_ID = # This is given to you when you create/register your app
- CLIENT_SECRET_KEY = # This is also given to you create/register your app
- BASE_URL = "https://www.leaguevine.com"
- BASE_API_URL = "https://api.leaguevine.com"
-
- # Make a request for an access_token
- access_token_url = ('{0}/oauth2/token/?client_id={1}&'
- 'client_secret={2}&grant_type=client_credentials&'
- 'scope=universal'.format(BASE_URL,
- CLIENT_ID,
- CLIENT_SECRET_KEY))
- response_data = urllib2.urlopen(access_token_url)
-
- # parse string into Python dictionary
- response_dict = simplejson.loads(response_data.read())
- response_data.close()
- access_token = response_dict.get('access_token')
-
- # Create a JSON object for the new team you want to create
- team_data_dict = {"name": "Test Team",
- "season_id": 5,
- "info": "Test info."}
- team_data = simplejson.dumps(team_data_dict)
-
- # Make a request to create a new team
- request = urllib2.Request(url='{0}/v1/teams/'.format(BASE_API_URL),
- data=team_data)
- request.add_header('Content-Type', 'application/json')
- request.add_header('Accept', 'application/json')
- request.add_header('Authorization', 'bearer {0}'.format(access_token))
-
- response_data = urllib2.urlopen(request)
- response_dict = simplejson.loads(response_data.read())
- request.data = "{'name': 'Test Team', 'info': 'Some invalid JSON'}"
- try:
- response_data = urllib2.urlopen(request)
- except urllib2.HTTPError, e:
- error_response = e.read()
- # error_response should contain something like:
- # '{"error_message": "The data passed in is not properly formatted JSON."}'
- import logging
- import requests # To install this library: pip install requests
- import simplejson # To install this library: pip install simplejson
- import sys
-
- # Create a new app and copy the credentials it creates into these variables:
- CLIENT_ID = 'a18d62e40f4d269996b01f7cf462a9'
- CLIENT_PWD = '93dbb28011a5224303074b3deebaf6'
- BASE_URL = "https://www.leaguevine.com"
- BASE_API_URL = "https://api.leaguevine.com"
-
- # ID of the tournament we want to delete games from
- tournament_id = 0
-
- # Get an instance of a logger
- logger = logging.getLogger('leaguevine.addons')
-
- # Make a request for an access_token
- r=requests.get(('{0}/oauth2/token/?client_id={1}&'
- 'client_secret={2}&grant_type=client_credentials&'
- 'scope=universal'.format(BASE_URL, CLIENT_ID, CLIENT_PWD)))
- # parse string into Python dictionary
- r_dict = simplejson.loads(r.content)
- access_token = r_dict.get('access_token')
- logger.info(access_token)
-
- # Save headers for this session
- my_headers={'Content-Type': 'application/json',
- 'Accept': 'application/json',
- 'Authorization': 'bearer {0}'.format(access_token)}
- my_config={'verbose': sys.stderr}
-
- # Retrieve all teams of a particular tournament
- url='{0}/v1/tournament_teams/?tournament_ids=[{1}]'.format(BASE_API_URL,tournament_id)
- next=True
- while next:
- # We do not use the next-url, but the original one because
- # we have removed some teams in the meantime
- response = requests.get(url=url,headers=my_headers,config=my_config)
- response_dict = simplejson.loads(response.content)
- logger.info(response_dict)
-
- for team in response_dict.get('objects'):
- # Remove this team from tournament.
- # Only teams created by the user who created the app will be removed
- remove_url='{0}/v1/tournament_teams/{1}/{2}/'.format(BASE_API_URL,tournament_id, team.get('team_id'))
- response = requests.delete(url=remove_url,headers=my_headers,config=my_config)
- if response.status_code == 204:
- logger.info('removed team with id {0}'.format(team.get('team_id')))
- else:
- response.raise_for_status()
-
- # Check if there are more teams
- next=response_dict.get('meta').get('next')
- <script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>
- <script type="text/javascript">
- $(function() {
- $.ajax({
- url: "https://api.leaguevine.com/v1/leagues/?" +
- "organization_id=2" +
- "&sport=ultimate" +
- "&access_token=ACCESS_TOKEN",
- dataType: "json",
- contentType: "application/json",
- beforeSend: function(jqXHR, settings) {
- settings.accepts['json'] = "application/json";
- },
- success: function(data){
- for (i=0; i < data.objects.length; i++) {
- var obj = data.objects[i];
- // Do something with the objects
- }
- },
- });
- });
- </script>