Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
secret.py
*__pycache__/*
.idea/*
.idea/*
Pipfile
Pipfile.lock
.vscode/settings.json
19 changes: 0 additions & 19 deletions find_hero_test.py

This file was deleted.

39 changes: 39 additions & 0 deletions opendota.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,42 @@

# def find_matches_by_hero():

def make_query(hero1, hero2):
query = f"""SELECT player_matches.hero_id AS hero1,
player_matches1.hero_id AS hero2,
player_matches.player_slot AS ps1,
player_matches1.player_slot AS ps2,
matches.match_id,
leagues.name leaguename
FROM player_matches
JOIN player_matches AS player_matches1
ON player_matches.match_id = player_matches1.match_id
JOIN matches
ON player_matches.match_id = matches.match_id
JOIN leagues using(leagueid)
WHERE player_matches.hero_id = {get_hero_id(hero1)}
AND player_matches1.hero_id = {get_hero_id(hero2)}
AND matches.start_time >= extract(epoch
FROM timestamp '2020-10-23T06:53:44.537Z')
AND abs(player_matches.player_slot - player_matches1.player_slot) > 123
ORDER BY matches.match_id NULLS LAST LIMIT 200"""

response = requests.get(
f"{API_ROOT}/explorer", params=dict(api_key=secret.OPENDOTA_API_KEY, sql = query)
)
return response.json()

##returns list of pro match ids played between two opposing heroes
def get_matches(hero1, hero2):
query_response = make_query(hero1, hero2)
match_list = query_response['rows'] ##list of dictionaries for some reason
result = []

for match in match_list:
result.append(match['match_id'])

return result


def find_hero(heroname):
for hero in load_hero_list():
Expand Down Expand Up @@ -46,3 +82,6 @@ def load_hero_list():

if __name__ == "__main__":
main()



7 changes: 7 additions & 0 deletions tests/test_find_hero.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,10 @@ def test_find_juggernaut():
def test_hero_id():
juggernaut_id = opendota.get_hero_id("Juggernaut")
assert juggernaut_id == 8

def test_query():
print(opendota.make_query("Bloodseeker", "Crystal Maiden"))


def test_get_matches():
print(opendota.get_matches("Bloodseeker", "Crystal Maiden"))