-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdetect_names.py
47 lines (30 loc) · 1.01 KB
/
detect_names.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import requests
def get_score(player_name: str):
hs_api = 'https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player='
response = requests.get(f'{hs_api}{player_name}')
## 200 is the response for an existing player
## 404 is no response / missing
if response.status_code == 404:
print(response.status_code)
return None
elif response.status_code == 200:
print(response.content)
return response.content
# if high scores are down, or something else, ignore for now
else:
print(response.status_code)
return None
def exists_player(player_name: str, ignore_char = "|") -> bool:
if player_name is None:
return False
player_name = player_name.split(ignore_char)[0]
print(player_name)
score = get_score(player_name)
## 200 is the response for an existing player
## 404 is no response / missing
if score:
return True
## For future:
# log response code
# log scores
return False