forked from seeebek/EliteOCR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
threadworker.py
75 lines (59 loc) · 2.18 KB
/
threadworker.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
# -*- coding: utf-8 -*-
import requests
import re
from bs4 import BeautifulSoup
from PyQt4.QtCore import QThread, SIGNAL
class Worker(QThread):
def __init__(self, parent = None):
QThread.__init__(self, parent)
self.ver = 0
def check(self, version):
self.ver = version
self.start()
def versioncmp(self, version1, version2):
def normalize(v):
try:
return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]
except:
return 0
return cmp(normalize(version1), normalize(version2))
def run(self):
try:
r = requests.get('http://sourceforge.net/projects/eliteocr/files/')
except:
return
#print r.status_code
result = r.text.encode('utf-8')
versions = []
soup = BeautifulSoup(result)
try:
for line in soup.findAll("table", { "id" : "files_list" }):
for row in line.findAll("tr", { "class" : "folder" }):
if re.search("[0-9]$", row['title'].strip()):
versions.append(row['title'].strip())
versions.sort(reverse=True)
except:
return
try:
r2 = requests.get('http://sourceforge.net/projects/eliteocr/files/'+versions[0]+"/")
except:
return
#print "got files"
result2 = r2.text.encode('utf-8')
files = []
soup = BeautifulSoup(result2)
for line in soup.findAll("table", { "id" : "files_list" }):
for row in line.findAll("tr", { "class" : "file" }):
match = re.search(r"EliteOCR\.([0-9\.]+)\.zip$", row['title'].strip())
if match:
files.append(match.group(1))
files.sort(reverse=True)
newerfile = ""
for file in files:
if self.versioncmp(self.ver, file) < 0:
newerfile = file
break
if newerfile != "":
self.emit(SIGNAL("output(QString,QString)"), versions[0], newerfile)
return
self.emit(SIGNAL("end()"))