· 5 years ago · May 18, 2020, 01:30 PM
1import requests as rq
2import sbmath as sbm
3import math, skyblock
4import sys
5
6with open('api-key','r') as f:
7 key = f.read()
8# key = ''
9
10def connectHypixelAPI():
11 global hdata, player, sb
12 hdata = rq.get(url=f"https://api.hypixel.net/player?key={key}&name={name}").json()
13 player = hdata['player']
14 sb = player['stats']['SkyBlock']
15
16# if hdata['success'] == True:
17# print("Request to Hypixel API succeeded!\n")
18# else:
19# print("Request to API failed, max request is 120 per minute.\n")
20
21def uuid():
22 return player['uuid']
23
24# return list [{id:name},{id:name}]
25def listProfiles():
26 sbd = sb['profiles']
27 profs = {}
28 for pr in sbd:
29 profs[sbd[pr]['profile_id'].lower()] = sbd[pr]['cute_name']
30 return profs
31
32# print(listProfiles())
33
34def getActiveProfile():
35 return list(listProfiles().keys())[0]
36
37# print(getActiveProfile())
38
39# id = getProfileID('!')
40
41def connectHypixelSkyblockAPI():
42 global sbdt, obj, statobj
43 sbdt = rq.get(url=f"https://api.hypixel.net/skyblock/profile?key={key}&profile={getActiveProfile()}").json()
44 obj = sbdt['profile']['members'][uuid()]
45 statobj = obj['stats']
46
47# if sbdt['success'] == True:
48# print("Request to Hypixel Skyblock API succeeded!\n")
49# else:
50# print("Request to API failed, max request is 120 per minute.\n")
51
52def printStatsStartsWith(ch):
53 st = {}
54 for x in statobj:
55 if x.startswith(ch):
56 st[x] = statobj[x]
57 std = dict(sorted(st.items(), key=lambda x: x[1], reverse=True))
58 for i in std:
59 print(f"{i.replace('_', ' ').title()}: {format(int(std[i]),',d')}")
60
61# printStatsStartsWith('auc')
62
63def getPurse():
64 return sbm.formatd(obj['coin_purse'])
65
66def getSouls():
67 return obj['fairy_souls_collected']
68
69def getSkills():
70 skills = ['mining','alchemy','farming','taming','enchanting','fishing','foraging','combat']
71 lvl = {}
72 print('xxx')
73 for sk in skills:
74 lvl[sk] = sbm.getSkillLevel(obj[f'experience_skill_{sk}'])
75 return lvl
76
77# !!!!!!!!!
78def getSkillAvg():
79 pass
80 # print('--------------')
81 # return sum(list(getSkills().values()))/8
82
83def getMinionSlots():
84 pass
85
86def getSlayerXP(stype,string=False):
87 return obj['slayer_bosses'][stype]['xp'] if string == False else sbm.formatd(obj['slayer_bosses'][stype]['xp'])
88
89def getTotalSlayerXP():
90 total = 0
91 for i in ['zombie','spider','wolf']:
92 total += getSlayerXP(i)
93 return sbm.formatd(total)
94
95def printSlayers():
96 pass
97
98# def printSkills():
99# sk = getSkills()
100# print(sk)
101
102def printDeath():
103 printStatsStartsWith('death')
104
105def printKill():
106 printStatsStartsWith('kills')
107
108def printAuction():
109 printStatsStartsWith('auc')
110
111def help():
112 print(f"""
113Usage: python skyblock.py ![opt] -[mode] .[arg]
114
115Parameter:
116 ![opt] can be one of these below.
117 -mode and .arg only available for !player
118
119 !api Set up API key
120 !help Print this help message
121 !player Player name for stats check.
122
123 -[mode] available mods
124
125 -st Print stats. Only this can have .arg options
126 -inv Investigate if a player plays the game normally or not
127 Will print out important stats like skills, slayers, auctions, etc
128 -ch Check if player has Skyblock profile or not.
129 Good for banwave check
130
131 .[arg] available arguments:
132
133 .a Auction
134 .d Deaths
135 .k Kills
136 .sl Slayer
137 .sk Skills
138
139
140 """)
141
142
143name = 'MinhPerry'
144connectHypixelAPI()
145connectHypixelSkyblockAPI()
146print(getSkills())
147
148#inp = sys.argv[1:]
149#print(inp)