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
/
wowinterface.py
executable file
·142 lines (115 loc) · 3.71 KB
/
wowinterface.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/python
'''
Plugin for updating from www.wowinterface.com
'''
__author__ = "Patrick Butler <pbutler@killertux.org>"
__version__ = "$Revision: 31 $"
__copyright__ = "Copyright 2005,2006 Patrick Butler"
__license__ = "GPL Version 2"
import wowaddon
import urllib
import re
import os
import shutil
class Plugin(wowaddon.Plugin):
def __init__(self, updater, args):
wowaddon.Plugin.__init__(self, updater, args)
if (id == ""):
raise "Need id"
self.id = args[0]
self.type = "WoWInterface"
def getinfo(self):
if self.timemutex(60):
return
self.out("Checking mod WOWIF:%s" % (self.id))
try:
data = urllib.urlopen("http://www.wowinterface.com/downloads/fileinfo.php?id=" + self.id).read()
#name = re.compile("(?is)<td[^>]*><b>Name:</b></td>[^<]*<td[^>]*>([^<]+)</td>").search(data).group(1)
name = re.compile("(?is)<td[^>]*><b>Name:</b></td>[^<]*<td[^>]*><a href=[^>]+>([^<]+)</a>").search(data).group(1)
#print name
version = re.compile("(?is)<td[^>]*><b>Version:</b></td>[^<]*<td[^>]*>([^<]+)</td>").search(data).group(1)
#print version
except IOError:
raise wowaddon.DownloadError
self.name = wowaddon.cleanuphtml(name) + " " + wowaddon.cleanuphtml(version)
self.link = 'http://www.wowinterface.com/downloads/dl.php?id=' + str(self.id)
self.newversion = version
self.zipfilename = re.sub('[^-_a-zA-Z0-9]', '', self.name.strip().replace(' ', '_')) + ".zip"
return self.link, self.newversion, self.zipfilename
def postcopy(self):
ifacedir = os.path.join(self.getoption('wowdir'), "Interface")
wowaddon.nopatch(ifacedir, self.outfiles);
def help():
return ""
def search(text):
go = True
ret = []
datere = re.compile("(\d+-\d+-\d+)");
comped = re.compile("(?is)[\r\n]+<a href=\"fileinfo.php?[^\"]*id=(\d+)[^\"]*\"[^>]*>([^<]+)</a>(.*?)</tr>")
filesre = re.compile("Showing files (\d+) to (\d+) of (\d+)");
page = 1
searchid = None
while go:
go = False
textq = urllib.quote_plus(text)
posta = { "s" : '',
"searchcat" : "all",
"searchdate" : "-1",
"sb" : "filename",
"so" : "asc",
"showdetails" : "0",
"action" : "search",
"searchtext" : textq }
if page > 1:
posta['action'] = 'showresults'
posta['page'] = page
posta['searchid'] = searchid
posta['sb'] = ''
posta['so'] = ''
post = urllib.urlencode(posta)
try:
data = urllib.urlopen("http://www.wowinterface.com/downloads/search.php", post).read()
except IOError:
raise wowaddon.DownloadError
print data
match = comped.search(data, 0)
while match != None:
id = match.group(1)
name = match.group(2)
rest = match.group(3)
date = ""
delim = "</a>"
try:
date = datere.search(rest).group(1)
except AttributeError:
raise wowaddon.ParseError
name = wowaddon.cleanuphtml(name)
ret.append( (id, name + " -- " + date) )
match = comped.search(data, match.end() )
go = False
match = filesre.search(data)
if match != None:
(start, stop, end) = match.groups()
if int(stop) < int(end):
go = True
page += 1
searchid = re.search('searchid=(\d+)', data).group(1)
#print (start, stop, end), page, searchid
return ret
def argdesc():
return [ { 'title' : 'WoW Interface.com',
'desc' : 'Please enter the search string for the mod',
'type' : 'func',
'type1' : 'str',
'desc2' : 'Choose your mod',
'func' : Plugin.search } ]
help = staticmethod(help)
search = staticmethod(search)
argdesc = staticmethod(argdesc)
wowaddon.addModType("WoWInterface.com", Plugin)
if __name__ == "__main__":
list = Plugin.search('lootlink')
print len(list)
print list
p = Plugin(None, [ list[-1][0] ] )
print p.getinfo()