-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_link.py
56 lines (41 loc) · 1.48 KB
/
get_link.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
47
48
49
50
51
52
53
54
55
56
import json
import requests
def getRegionAndMode(): # this gets the desired region and gamemode from the user
# then puts it in a format we care about
userregion = input("input the region ")
userregion = "vultr-" + userregion
usergamemode = input("enter the gamemode")
if usergamemode == "4tdm":
usergamemode = "4teams"
elif usergamemode == "2tdm":
usergamemode = "teams"
elif usergamemode == "sbx":
usergamemode = "sandbox"
return userregion, usergamemode
def idToListedHex(diepid): # this converts the server ID into a list of hex bytes (with the individual bytes reversed)
listed = []
for char in diepid:
string = (hex(ord(char))[2:])
listed.append(string[::-1])
return listed
def toLink(diepid): # converts the reversed bytes into a usable link
return f"https://diep.io/#{diepid}"
def getData(usergamemode):
url = f"https://api.n.m28.io/endpoint/diepio-{usergamemode}/findEach"
r = requests.get(url=url)
diepdata = r.json()
return diepdata
def stripQuotes(stripper):
stripped = ""
for character in stripper:
if character != '"':
stripped += character
return stripped
def getIDforRegion(reg, jsondata):
return json.dumps(jsondata['servers'][f'{reg}']['id'])
region, gamemode = getRegionAndMode()
data = getData(gamemode)
nothex = stripQuotes(getIDforRegion(region, data))
linkEnd = idToListedHex(nothex)
linkEnd = "".join(linkEnd)
return(toLink(linkEnd))