-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsteam-screenshot-sort - user folder.py
48 lines (37 loc) · 1.49 KB
/
steam-screenshot-sort - user folder.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
#!/usr/bin/env python
import urllib2
import os
import json
import sys
import shutil
import re
def getSteamName(steamID):
try:
steamID = int(steamID)
if steamID > 0 and steamID < 9223372036854775807:
r = urllib2.urlopen('https://store.steampowered.com/api/appdetails/?appids='+str(steamID))
data = json.load(r)
if (data[unicode(steamID)]['success']):
return unicode(data[unicode(steamID)]['data']['name'])
except:
pass
def main():
root = os.getcwd()
for img in os.listdir(root):
if img.endswith('.png'):
img_splt = img.split('_')
if len(img_splt) > 1:
game_id = img_splt[0]
game_name = None
try:
game_name = getSteamName(game_id)
game_name = re.sub(ur'[^a-zA-Z0-9-_]', ' ', game_name).strip()
except:
pass
if (game_name):
new_folder = os.path.join(root, game_name)
if not os.path.isdir(new_folder):
os.mkdir(new_folder)
shutil.move(os.path.join(root, img), os.path.join(new_folder, img))
if __name__ == '__main__':
main()