def main(): # Setup riotapi riotapi.set_region("NA") riotapi.print_calls(True) key = os.environ["DEV_KEY"] # You can create an env var called "DEV_KEY" that holds your developer key. It will be loaded here. riotapi.set_api_key(key) riotapi.set_load_policy(LoadPolicy.eager) # Load and connect to your database. (Comment this code to use local memory. Don't forget to comment db.close() below too.) db = SQLAlchemyDB("mysql+mysqlconnector", "databse_hostname", "database_name", "username", "password") riotapi.set_data_store(db) master = [entry.summoner for entry in riotapi.get_master()] print("Pulled Master tier. Got {0} summoners.".format(len(master))) gather_start = datetime(2015, 7, 23) # 1 day after patch 5.14 for summoner in master: for match in summoner.match_list(begin_time=gather_start): # If you are connected to a database, the match will automatically be stored in it without you having to do anything. # Simply pull the match, and it's in your database for whenever you need it again! # If you pull a match twice, the second time it will be loaded from the database rather than pulled from Riot # and therefore will not count against your rate limit. This is true of all datatypes, not just Match. match = get_match(match) print("Stored {0} in my database".format(match)) db.close()
def setup_cass(): riotapi.set_load_policy("lazy") riotapi.set_rate_limit(25000, 10) riotapi.set_data_store(None) riotapi.set_api_key(os.environ["API_KEY"]) riotapi.set_region("NA") riotapi.print_calls(True)
def main(): # Setup riotapi riotapi.set_region(REGION) riotapi.print_calls(True) key = #redacted # You can create an env var called "DEV_KEY" that holds your developer key. It will be loaded here. riotapi.set_api_key(key) riotapi.set_load_policy(LoadPolicy.lazy) # Load and connect to your database. (Comment this code to use local memory. Don't forget to comment db.close() below too.) db = SQLAlchemyDB("sqlite", host="", database=OUTFILE, username="", password="") riotapi.set_data_store(db) # We will seed with all the summoners in Master's tier unpulled_summoners = deque(entry.summoner for entry in riotapi.get_master()) print("Pulled Master tier for seeding. Got {0} summoners.".format(len(unpulled_summoners))) # We need this so that we don't get a recursive loop of summoners pulled_summoners = deque() gather_start = datetime(2015, 1, 1) # since we have data for all of 2015 times_crashed = 0 #store number of times we've had the NoneType error times_looped = 0 #store number of times we've made a call as a rough proxy for when to stop the script while len(unpulled_summoners) > 0: summoner = unpulled_summoners.popleft() for match_reference in summoner.match_list(begin_time=gather_start): # If you are connected to a database, the match will automatically be stored in it without you having to do anything. # Simply pull the match, and it's in your database for whenever you need it again! # If you pull a match twice, the second time it will be loaded from the database rather than pulled from Riot # and therefore will not count against your rate limit. This is true of all datatypes, include Summoner. match = riotapi.get_match(match_reference) if match is None: # If the match still fails to load, continue on to the next one continue print("Stored {0} in my database".format(match)) for participant in match.participants: try: if participant.summoner not in unpulled_summoners and participant.summoner not in pulled_summoners: unpulled_summoners.append(participant.summoner) except TypeError: times_crashed += 1 print("I've run into the NoneType error {} times so far!".format(times_crashed)) pass times_looped += 1 print("I have now looped {} times.".format(times_looped)) if times_looped > LOOPS: exit("I have looped {} times and am done now.".format(times_looped)) pulled_summoners.append(summoner) db.close()
def main(): riotapi.set_region("kr") riotapi.print_calls(True) riotapi.set_load_policy(LoadPolicy.lazy) riotapi.set_api_key("d045c326-dc9f-4de4-a463-793944aa6984") db = SQLAlchemyDB("mysql+mysqlconnector", "localhost", "kr_challenger_522", "root", "0123") riotapi.set_data_store(db) challenger = [entry.summoner for entry in list(riotapi.get_challenger()[1:10])] gather_start = datetime(2015, 11, 12) # 1 day after patch 5.19 for summoner in challenger: for match in summoner.match_list(begin_time=gather_start): get_match(match) db.close()
def main(): # Setup riotapi riotapi.set_region("NA") riotapi.print_calls(True) key = os.environ[ "DEV_KEY"] # You can create an env var called "DEV_KEY" that holds your developer key. It will be loaded here. riotapi.set_api_key(key) riotapi.set_load_policy(LoadPolicy.lazy) # Load and connect to your database. (Comment this code to use local memory. Don't forget to comment db.close() below too.) db = SQLAlchemyDB("mysql+mysqlconnector", "databse_hostname", "database_name", "username", "password") riotapi.set_data_store(db) # We will seed with all the summoners in Master's tier unpulled_summoners = deque(entry.summoner for entry in riotapi.get_master()) print("Pulled Master tier for seeding. Got {0} summoners.".format( len(unpulled_summoners))) # We need this so that we don't get a recursive loop of summoners pulled_summoners = deque() gather_start = datetime(2015, 7, 23) # 1 day after patch 5.14 while len(unpulled_summoners) > 0: summoner = unpulled_summoners.popleft() for match_reference in summoner.match_list(begin_time=gather_start): # If you are connected to a database, the match will automatically be stored in it without you having to do anything. # Simply pull the match, and it's in your database for whenever you need it again! # If you pull a match twice, the second time it will be loaded from the database rather than pulled from Riot # and therefore will not count against your rate limit. This is true of all datatypes, include Summoner. match = riotapi.get_match(match_reference) if match is None: # If the match still fails to load, continue on to the next one continue print("Stored {0} in my database".format(match)) for participant in match.participants: if participant.summoner not in unpulled_summoners and participant.summoner not in pulled_summoners: unpulled_summoners.append(participant.summoner) pulled_summoners.append(summoner) db.close()
def main(): riotapi.set_region("kr") riotapi.print_calls(True) riotapi.set_load_policy(LoadPolicy.lazy) riotapi.set_api_key("d045c326-dc9f-4de4-a463-793944aa6984") db = SQLAlchemyDB("mysql+mysqlconnector", "localhost", "kr_challenger_522", "root", "0123") riotapi.set_data_store(db) challenger = [ entry.summoner for entry in list(riotapi.get_challenger()[1:10]) ] gather_start = datetime(2015, 11, 12) # 1 day after patch 5.19 for summoner in challenger: for match in summoner.match_list(begin_time=gather_start): get_match(match) db.close()
def main(): # Setup riotapi riotapi.set_region("KR") riotapi.print_calls(True) key = os.environ["DEV_KEY1"] # You can create an env var called "DEV_KEY" that holds your developer key. It will be loaded here. riotapi.set_api_key(key) riotapi.set_load_policy(LoadPolicy.lazy) # Load and connect to your database. (Comment this code to use local memory. Don't forget to comment db.close() below too.) db = SQLAlchemyDB("mysql+mysqlconnector", "localhost", "lol", "root", "1234") riotapi.set_data_store(db) #riotapi.get_masteries() #riotapi.get_champions() #riotapi.get_runes() #riotapi.get_summoner_spells() # We will seed with all the summoners in Master's tier unpulled_summoners = deque(entry.summoner for entry in riotapi.get_master()) print("Pulled Master tier for seeding. Got {0} summoners.".format(len(unpulled_summoners))) # We need this so that we don't get a recursive loop of summoners pulled_summoners = deque() gather_start = datetime(2017, 1, 12) # 1 day after patch 7.1 while len(unpulled_summoners) > 0: summoner = unpulled_summoners.popleft() for match_reference in summoner.match_list(begin_time=gather_start): match = riotapi.get_match(match_reference) if match is None: # If the match still fails to load, continue on to the next one continue print("Stored {0} in my database".format(match)) for participant in match.participants: # cm = riotapi.get_champion_mastery(participant.summoner, participant.champion) if participant.summoner not in unpulled_summoners and participant.summoner not in pulled_summoners: unpulled_summoners.append(participant.summoner) pulled_summoners.append(summoner) db.close()
def main(): # Setup riotapi riotapi.set_region("NA") riotapi.print_calls(True) key = os.environ[ "DEV_KEY" ] # You can create an env var called "DEV_KEY" that holds your developer key. It will be loaded here. riotapi.set_api_key(key) riotapi.set_load_policy(LoadPolicy.lazy) # Load and connect to your database. (Comment this code to use local memory. Don't forget to comment db.close() below too.) db = SQLAlchemyDB("mysql+mysqlconnector", "databse_hostname", "database_name", "username", "password") riotapi.set_data_store(db) # We will seed with all the summoners in Master's tier unpulled_summoners = deque(entry.summoner for entry in riotapi.get_master()) print("Pulled Master tier for seeding. Got {0} summoners.".format(len(unpulled_summoners))) # We need this so that we don't get a recursive loop of summoners pulled_summoners = deque() gather_start = datetime(2015, 7, 23) # 1 day after patch 5.14 while len(unpulled_summoners) > 0: summoner = unpulled_summoners.popleft() for match_reference in summoner.match_list(begin_time=gather_start): # If you are connected to a database, the match will automatically be stored in it without you having to do anything. # Simply pull the match, and it's in your database for whenever you need it again! # If you pull a match twice, the second time it will be loaded from the database rather than pulled from Riot # and therefore will not count against your rate limit. This is true of all datatypes, include Summoner. match = riotapi.get_match(match_reference) print("Stored {0} in my database".format(match)) for participant in match.participants: if participant.summoner not in unpulled_summoners and participant.summoner not in pulled_summoners: unpulled_summoners.append(participant.summoner) pulled_summoners.append(summoner) db.close()
def summoner(summ): summ = summ.replace(" ", "") # regionlist = [zone.value for zone in Region] regionlist = ['na', 'kr', 'euw', 'eune'] zone_summoners = [] # Try to speed this up by using pure riot json requests simultaneously for all regions? for r in regionlist: cassdb = SQLAlchemyDB(connector, host, dbnames[r]+"?charset=utf8", user, passwd) riotapi.set_data_store(cassdb) riotapi.set_region(r) try: s = riotapi.get_summoner_by_name(summ) if s is not None: zone_summoners.append((r, s)) print("{} from {} appended".format(s.name, r)) except APIError as error: print(error) print(error.error_code) cassdb.close() # attempt to avoid mysql went away if len(zone_summoners) == 0: error = "Summoner with that name not found. Try another one." return render_template('index.html', error=error) patch = riotapi.get_versions()[0] return render_template('zone.html', zone_summoners = zone_summoners, summname = summ, patch = patch)
def matchlistpage(zone, name): # Set region and after region is set, fetch latest API version, maybe move the version to a scheduled task if it uses a call. riotapi.set_region(zone) if zone in ['na', 'kr', 'euw', 'eune']: cassdb = SQLAlchemyDB(connector, host, dbnames[zone]+"?charset=utf8", user, passwd) riotapi.set_data_store(cassdb) print("======================") print(zone) print(name) print("======================") patch = riotapi.get_versions()[0] # Used to convert numerals to/from numbers romans = { 'I': 1, 'II': 2, 'III': 3, 'IV': 4, 'V': 5 } print("========== DB MADE Trying to get summoner by name ===========") # Get summoner s = riotapi.get_summoner_by_name(name) print("Summoner object:") print(s) print("id:{} name:{} level:{}".format(s.id, s.name, s.level)) print("========== GOT S, trying to get league entries ===========") try: le = riotapi.get_league_entries_by_summoner(s)[0] entry = le.entries[0] print("Got league entries for ranked") except: print("Couldnt fetch le/entry. Perhaps unranked.") le = None entry = None print("========== Trying to get ranked stats ===========") try: stats = riotapi.get_ranked_stats(s, season=None)[None] except: print("Couldnt fetch ranked stats. Maybe not lv30/never did ranked.") stats = None print("========== Trying to get matches ===========") ml = riotapi.get_match_list(s, seasons=[x.value for x in Season][-1], num_matches=10) if ml is not None: matches = [][-10:] for x in ml: try: m_to_add = riotapi.get_match(x) matches.append(m_to_add) except exc.IntegrityError as ie: print("==SQL ERROR ---> {}".format(ie)) print("==Python traceback==") print(traceback.print_exc()) cassdb.session.rollback() else: matches = [] print("========== Trying to render template ===========") return render_template('matchlist.html', s = s, entry = entry, le = le, matches = matches, patch = patch, stats = stats, zone = zone, round = round, len = len, romans = romans)
1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.conf.urls import url, include 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import include, url from django.contrib import admin from django.conf import settings from cassiopeia import riotapi #from chillhome.RecommenderWrapper import RecommenderWrapper from chillhome.current_game_checks import Check_Current_Games riotapi.set_load_policy("lazy") riotapi.set_rate_limit(25000, 10) riotapi.set_data_store(None) riotapi.set_api_key(settings.APIKEY) ccg = Check_Current_Games.Instance() # Start a non-blocking call ccg.checkAllGames() #recommender = RecommenderWrapper.Instance() urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^', include('chillhome.urls')), ]