-
Notifications
You must be signed in to change notification settings - Fork 0
/
osrs_stats.py
70 lines (61 loc) · 1.69 KB
/
osrs_stats.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import sys
print(sys.version)
from PIL import Image, ImageFont, ImageDraw
from OSRSBytes import Hiscores
FONT_SIZE = 18
OFFSET = (21, 16)
ROW1 = 6
ROW2 = 52
ROW3 = 98
ROW4 = 144
ROW5 = 190
ROW6 = 236
ROW7 = 282
ROW8 = 328
COL1 = 56
COL2 = 162
COL3 = 268
TOTAL_3 = (248,343)
TOTAL_4 = (248,343)
coordinates = {
'attack': (COL1, ROW1),
'strength': (COL1, ROW2),
'defense': (COL1, ROW3),
'ranged': (COL1, ROW4),
'prayer': (COL1, ROW5),
'magic': (COL1, ROW6),
'runecrafting': (COL1, ROW7),
'construction': (COL1, ROW8),
'hitpoints': (COL2, ROW1),
'agility': (COL2, ROW2),
'herblore': (COL2, ROW3),
'thieving': (COL2, ROW4),
'crafting': (COL2, ROW5),
'fletching': (COL2, ROW6),
'slayer': (COL2, ROW7),
'hunter': (COL2, ROW8),
'mining': (COL3, ROW1),
'smithing': (COL3, ROW2),
'fishing': (COL3, ROW3),
'cooking': (COL3, ROW4),
'firemaking': (COL3, ROW5),
'woodcutting': (COL3, ROW6),
'farming': (COL3, ROW7)
}
def sum_tuple(a,b):
return tuple(map(sum, zip(a, b)))
def create_stats(rsn, out):
user = Hiscores(rsn)
total = int(user.skill('total'))
img = Image.open('static/blank.png')
draw = ImageDraw.Draw(img)
font = ImageFont.truetype('static/osrs.ttf', FONT_SIZE)
for skill in coordinates:
draw.text(coordinates[skill], str(user.skill(skill, 'level')), (255,255,0), font=font)
draw.text(sum_tuple(coordinates[skill], OFFSET), str(user.skill(skill, 'level')), (255,255,0), font=font)
if total < 1000:
draw.text(TOTAL_3, str(total), (255,255,0), font=font)
else:
draw.text(TOTAL_4, str(total), (255,255,0), font=font)
img.save(out, format='PNG')
out.seek(0)