2 from urllib
import request
,parse
3 import xml
.etree
.ElementTree
as ET
6 Gets a gameart for selected game
11 print(get("heroes of might and magic iii"))
14 """Changes name of the game so it matches the database"""
15 name_url
= "http://thegamesdb.net/api/GetGame.php?name={}".format(name
)
16 data
= openurl(name_url
)
17 xmldoc
= ET
.parse(data
)
19 game
= xmldoc
.findall('Game')[0]
23 title
= game
.find('GameTitle')
28 req
= request
.Request(
32 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) ' \
33 ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
36 return request
.urlopen(req
)
39 """Opens freaking XML"""
42 game_id
= "http://thegamesdb.net/api/GetGame.php?exactname={}".format(parse
.quote(title
))
43 data
= openurl(game_id
)
44 xmldoc
= ET
.parse(data
)
45 url
= xmldoc
.find('baseImgUrl').text
46 game
= xmldoc
.findall('Game')[0]
47 id_game
= game
.find('Images')
48 boxart
= id_game
.findall('boxart')
51 title
= exact_name(title
)
53 if i
.get('side') == 'front':
57 #It could have been so simple with JSON...
58 if __name__
== '__main__':