-
Notifications
You must be signed in to change notification settings - Fork 0
/
medal_mashup.py
86 lines (69 loc) · 2.8 KB
/
medal_mashup.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from lib import lib
import pandas as pd
from PIL import Image
import requests
from io import BytesIO
import os.path
import sys
if len(sys.argv) < 2:
print("Please provide a gamertag")
sys.exit(1)
lib = lib({
'token': "insert your token here"
})
version = "@1.4.0"
gamertag = sys.argv[1]
def getAllMedals(gamertag, season=None):
medals = pd.DataFrame(lib.halo.infinite[version].metadata.multiplayer.medals()['data'])
medals['image_urls'] = medals['image_urls'].apply(lambda x: x['large'])
medals['count'] = 0
result = lib.halo.infinite[version].stats.players['service-record'].multiplayer.matchmade.all({
'gamertag': gamertag,
'season': season,
})
medal_count = pd.DataFrame(result['data']['core']['breakdowns']['medals'])
for i in range(len(medal_count)):
medals.loc[medals['id'] == medal_count['id'][i], 'count'] = medal_count['count'][i]
return medals
medals = getAllMedals(gamertag)
print(medals)
if len(sys.argv) == 3 and sys.argv[2] == "--save-images":
for i in range(len(medals)):
response = requests.get(medals['image_urls'][i])
img = Image.open(BytesIO(response.content))
img.save('.\images\\' + medals['name'][i] + '.png')
path = ".\images"
dirs = os.listdir(path)
def crop():
for item in dirs:
if item not in ['Killing Spree.png']:
fullpath = os.path.join(path, item)
if os.path.isfile(fullpath):
im = Image.open(fullpath)
f, e = os.path.splitext(fullpath)
imCrop = im.crop((20, 20, 236, 236))
imCrop.save(f + 'Cropped.png', "png")
crop()
# delete all images but the cropped ones
for item in dirs:
if item not in ['Killing Spree.png']:
fullpath = os.path.join(path, item)
if os.path.isfile(fullpath):
f, e = os.path.splitext(fullpath)
if f + 'Cropped.png' not in os.listdir(path):
os.remove(fullpath)
else:
# rename the image by adding Cropped
fullpath = os.path.join(path, item)
f, e = os.path.splitext(fullpath)
os.rename(fullpath, f + 'Cropped.png')
gephi = pd.DataFrame(columns=['source', 'weight', 'type', 'image'])
gephi['source'] = medals[medals['count'] != 0]['name']
gephi['weight'] = medals[medals['count'] != 0]['count']
gephi['type'] = medals[medals['count'] != 0]['type']
gephi['image'] = medals[medals['count'] != 0]['name']
gephi['image'] = gephi['image'].apply(lambda x: x + 'Cropped.png')
with open('halo.csv', 'w') as f:
f.write('id')
gephi.to_csv('halo.csv', mode='a')
print("Done! Go to gephi and follow the rest of the tutorial.")