Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import hypixel
from time import time
from random import shuffle
print("Test \"{}\" is now running...\n".format(os.path.basename(__file__)))
API_KEY = os.environ['apikey']
hypixel.setKeys([API_KEY])
start = time() # Start timer.
for i in range(0, Repeats-1):
shuffle(ActualData) # Randomize the order of the data
for InputUUID in ActualData:
Player = hypixel.Player(InputUUID)
print(Player.getPlayerInfo())
end = time()
totalTime = start-end
print("\nDone! Speed test finished. Time taken: {}".format(end-start))
""" Travis Ci Tests """
import os
import hypixel
import time
API_KEY = os.environ['apikey']
start = time.time()
hypixel.setKeys([API_KEY])
Snuggle = hypixel.Player('8998bcff9765438bb6089ab93bfad4d3')
SnuggleLevel = Snuggle.getLevel()
if SnuggleLevel > 0:
print("Snuggle's is level {}.".format(SnuggleLevel))
else:
raise ValueError(SnuggleLevel)
SnuggleRank = Snuggle.getRank()
if SnuggleRank['rank'] == "Moderator":
print("Snuggle's is a {}.".format(SnuggleRank))
else:
raise ValueError(SnuggleRank)
SnuggleKarma = Snuggle.JSON['karma']
if SnuggleKarma > 0:
print("Snuggle has {} karma.".format(SnuggleKarma))
import os
import sys
sys.path.insert(1, os.path.join(sys.path[0], '..'))
import hypixel
import time
print("Test \"{}\" is now running...\n".format(os.path.basename(__file__)))
API_KEY = os.environ['apikey']
hypixel.setKeys([API_KEY])
TestFailed = False
for player in ActualData:
TestPlayer = hypixel.Player(player['Name'])
for test in player:
method_to_call = getattr(TestPlayer, 'get' + test)
testdata = method_to_call()
if testdata == player[test]:
print("\U00002714 {}".format(testdata))
else:
print("\U0000274C {}, Expected: {} [FAILED]".format(testdata, player[test]))
TestFailed = True
print("UUID: {}\n".format(TestPlayer.UUID))
if TestFailed is True:
raise ValueError
print("\nDone! All tests finished.")
'b80a30a6d6d7472490c0c6081684b769']
Repeats = 5
import os
import sys
sys.path.insert(1, os.path.join(sys.path[0], '..'))
import hypixel
from time import time
from random import shuffle
print("Test \"{}\" is now running...\n".format(os.path.basename(__file__)))
API_KEY = os.environ['apikey']
hypixel.setKeys([API_KEY])
start = time() # Start timer.
for i in range(0, Repeats-1):
shuffle(ActualData) # Randomize the order of the data
for InputUUID in ActualData:
Player = hypixel.Player(InputUUID)
print(Player.getPlayerInfo())
end = time()
totalTime = start-end
print("\nDone! Speed test finished. Time taken: {}".format(end-start))
'Level': 5.1,
'GuildID': None,
'Session': None}
]
import os
import sys
sys.path.insert(1, os.path.join(sys.path[0], '..'))
import hypixel
import time
print("Test \"{}\" is now running...\n".format(os.path.basename(__file__)))
API_KEY = os.environ['apikey']
hypixel.setKeys([API_KEY])
TestFailed = False
for player in ActualData:
TestPlayer = hypixel.Player(player['Name'])
for test in player:
method_to_call = getattr(TestPlayer, 'get' + test)
testdata = method_to_call()
if testdata == player[test]:
print("\U00002714 {}".format(testdata))
else:
print("\U0000274C {}, Expected: {} [FAILED]".format(testdata, player[test]))
TestFailed = True
print("UUID: {}\n".format(TestPlayer.UUID))
if TestFailed is True:
""" Travis Ci Tests """
import os
import hypixel
import time
API_KEY = os.environ['apikey']
start = time.time()
hypixel.setKeys([API_KEY])
Snuggle = hypixel.Player('8998bcff9765438bb6089ab93bfad4d3')
SnuggleLevel = Snuggle.getLevel()
if SnuggleLevel > 0:
print("Snuggle's is level {}.".format(SnuggleLevel))
else:
raise ValueError(SnuggleLevel)
SnuggleRank = Snuggle.getRank()
if SnuggleRank['rank'] == "Moderator":
print("Snuggle's is a {}.".format(SnuggleRank))
else:
raise ValueError(SnuggleRank)
SnuggleKarma = Snuggle.JSON['karma']
if SnuggleKarma > 0:
raise ValueError(SnuggleLevel)
SnuggleRank = Snuggle.getRank()
if SnuggleRank['rank'] == "Moderator":
print("Snuggle's is a {}.".format(SnuggleRank))
else:
raise ValueError(SnuggleRank)
SnuggleKarma = Snuggle.JSON['karma']
if SnuggleKarma > 0:
print("Snuggle has {} karma.".format(SnuggleKarma))
else:
raise ValueError(SnuggleKarma)
SnuggleGuildID = Snuggle.getGuildID()
SnuggleGuild = hypixel.Guild(SnuggleGuildID)
print("Snuggle's guild is called {}.".format(SnuggleGuild.JSON['name']))
end = time.time()
totalTime=end-start
print("\nDone! All tests finished successfully. Time taken: {}".format(totalTime))
def getPlayerInfo(self):
""" This is a simple function to return a bunch of common data about a player. """
JSON = self.JSON
playerInfo = {}
playerInfo['uuid'] = self.UUID
playerInfo['displayName'] = Player.getName(self)
playerInfo['rank'] = Player.getRank(self)
playerInfo['networkLevel'] = Player.getLevel(self)
JSONKeys = ['karma', 'firstLogin', 'lastLogin',
'mcVersionRp', 'networkExp', 'socialMedia', 'prefix']
for item in JSONKeys:
try:
playerInfo[item] = JSON[item]
except KeyError:
pass
return playerInfo
def getPlayerInfo(self):
""" This is a simple function to return a bunch of common data about a player. """
JSON = self.JSON
playerInfo = {}
playerInfo['uuid'] = self.UUID
playerInfo['displayName'] = Player.getName(self)
playerInfo['rank'] = Player.getRank(self)
playerInfo['networkLevel'] = Player.getLevel(self)
JSONKeys = ['karma', 'firstLogin', 'lastLogin',
'mcVersionRp', 'networkExp', 'socialMedia', 'prefix']
for item in JSONKeys:
try:
playerInfo[item] = JSON[item]
except KeyError:
pass
return playerInfo
""" This is an example of how you can use this API to create cool things.
Just run this and you should see cool stuff. c:"""
import hypixel
API_KEYS = ['API_KEY_HERE_PLS']
hypixel.setKeys(API_KEYS) # This sets the API keys that are going to be used.
Player = hypixel.Player('Snuggle') # This creates a Player-object and puts it to a variable called "Player".
PlayerName = Player.getName() # This gets the player's name and puts it in a variable called "PlayerName". :3
print("Player is called ", end='')
print(PlayerName)
PlayerLevel = Player.getLevel()
print(PlayerName + " is level: ", end='')
print(PlayerLevel) # This prints the level that we got, two lines up!
PlayerRank = Player.getRank()
print(PlayerName + " is rank: ", end='')
print(PlayerRank['rank'])