This repository has been archived by the owner on May 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uiwownet.py
106 lines (81 loc) · 2.57 KB
/
uiwownet.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/python
'''
Plugin for updating from http://ui.worldofwar.net
'''
__author__ = "Patrick Butler <pbutler@killertux.org>"
__version__ = "$Revision: 31 $"
__copyright__ = "Copyright 2005,2006 Patrick Butler"
__license__ = "GPL Version 2"
import wowaddon
import os
import urllib
import re
class Plugin(wowaddon.Plugin):
def __init__(self, updater, args):
wowaddon.Plugin.__init__(self, updater, args)
if (args[0] == ""):
raise "Need id"
self.id = args[0]
self.type = "uiwownet"
self.link = ""
def getinfo(self):
if self.timemutex(60):
return
self.out("Checking mod %s" % self.id)
try:
data = urllib.urlopen("http://ui.worldofwar.net/download.php?dbtable=maps&id="+str(self.id)+"&g=1").read()
except IOError, e:
raise wowaddon.DownloadError, e
#print "ha"
match = re.search("<!--MET5A HTTP-EQUI5V5=\"Refresh\" CONTENT=\"\d+; URL=(.*?)\"-->", data, re.I and re.S)
if match == None:
self.out("Failed to parse download URL for mod %s" % self.id)
raise wowaddon.ParseError
link = match.group(1)
zname = re.search(r".*/\d*(.*?)\.zip$", link).group(1)
zname = zname.replace("%20", "_")
name = zname
name = name.replace("_", " ")
self.name = name
self.newversion = link
self.link = link
self.zipfilename = zname+".zip"
return self.name, self.link, self.zipfilename
def postcopy(self):
ifacedir = os.path.join(self.getoption('wowdir'), "Interface")
wowaddon.nopatch(ifacedir, self.outfiles);
def help():
return """
"""
def search(text):
ret = []
textq = urllib.quote_plus(text)
try:
data = urllib.urlopen("http://ui.worldofwar.net/listuis.php?searchtext=" +textq).read()
except IOError, e:
raise wowaddon.DownloadError, e
datere = re.compile("(\d+/\d+/\d+)")
comped = re.compile("(?is)<a href=\"[./]*ui.php\?id=(\d+)\">(.*?)</a>(.*?)</tr>")
match = comped.search(data, 0)
while match != None:
(id, name, rest) = match.groups()
date = datere.search(rest).group(1)
ret.append( (id, name + " -- " + date) )
match = comped.search(data, match.end() )
return ret
def argdesc():
return [ { 'title' : 'UI.WorldOfWar.net',
'desc' : 'Please enter the search string for the mod',
'type' : 'func',
'type1' : 'str',
'desc2' : 'Choose your mod',
'func' : Plugin.search } ]
argdesc = staticmethod(argdesc)
help = staticmethod(help)
search = staticmethod(search)
wowaddon.addModType("UI.WorldofWar.Net", Plugin);
if __name__ == "__main__":
list = Plugin.search('sw stats')
print list
p = Plugin(None, [ list[0][0] ] )
print p.getinfo()