-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbrowserparser.py
179 lines (131 loc) · 4.01 KB
/
browserparser.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import sys
from agedata import AgeData
import re
from datetime import *
class BrowserParser(object):
""" Get Version Elements and return age results """
def __init__(self):
self.ageData = None
def getParseOrder(self):
return sys.maxint
def doesMatch(self, ua):
return False
def getReleaseDate(self):
return 0
def getBrowser(self):
return ''
def getAge(self, ua):
rd = self.getReleaseDate(ua)
if not rd:
return None
return datetime.now().date() - rd
class BrpChrome(BrowserParser):
def __init__(self):
super(BrpChrome, self).__init__()
self.ageData = AgeData('age-chrome.json', propLimit=0)
def getParseOrder(self):
return 1
def doesMatch(self, ua):
return ua and 'chrome' in ua
def getBrowser(self):
return 'chrome'
def getReleaseDate(self, ua):
# http://www.oldapps.com/google_chrome.php
# http://googlechromereleases.blogspot.com/search/label/Stable%20updates
matches = re.compile('chrome/[a-z0-9\.]*').search(ua)
if not matches:
return None
self.verfull = matches.group().split('/')
self.vernums = self.verfull[1].split('.')
return self.ageData.getDate(self.vernums)
class BrpFirefox(BrowserParser):
def __init__(self):
super(BrpFirefox, self).__init__()
self.ageData = AgeData('age-firefox.json')
def getParseOrder(self):
return 2
def doesMatch(self, ua):
return ua and 'firefox' in ua
def getBrowser(self):
return 'firefox'
def getReleaseDate(self, ua):
# https://wiki.mozilla.org/Releases/Old/2011
matches = re.compile('firefox/[a-z0-9\.]*').search(ua)
if not matches:
return None
self.verfull = matches.group().split('/')
self.vernums = self.verfull[1].split('.')
return self.ageData.getDate(self.vernums)
class BrpMsie(BrowserParser):
def __init__(self):
super(BrpMsie, self).__init__()
self.ageData = AgeData('age-msie.json')
def getParseOrder(self):
return 3
def doesMatch(self, ua):
return ua and 'msie' in ua
def getBrowser(self):
return 'msie'
def getReleaseDate(self, ua):
"""http://en.wikipedia.org/wiki/Timeline_of_web_browsers"""
matches = re.compile('msie [a-z0-9\.]*').search(ua)
if not matches:
return None
self.verfull = matches.group().split(' ')
self.vernums = self.verfull[1].split('.')
return self.ageData.getDate(self.vernums)
class BrpOpera(BrowserParser):
def __init__(self):
super(BrpOpera, self).__init__()
self.ageData = AgeData('age-opera.json')
def getParseOrder(self):
return 4
def doesMatch(self, ua):
return ua and 'opera' in ua
def getBrowser(self):
return 'opera'
def getReleaseDate(self, ua):
""" http://www.opera.com/docs/history/#o1202 """
matches = re.compile('version/[a-z0-9\.]*').search(ua)
if not matches:
return None
self.verfull = matches.group().split('/')
self.vernums = self.verfull[1].split('.')
return self.ageData.getDate(self.vernums)
class BrpSafari(BrowserParser):
def __init__(self):
super(BrpSafari, self).__init__()
self.ageData = AgeData('age-safari.json')
def getParseOrder(self):
return 5
def doesMatch(self, ua):
return ua and 'safari' in ua
def getBrowser(self):
return 'safari'
def getReleaseDate(self, ua):
""" http://en.wikipedia.org/wiki/Safari_version_history """
#matches = re.compile('safari/[a-z0-9\.]*').search(ua)
matches = re.compile('version/[a-z0-9\.]*').search(ua)
if not matches:
return None
self.verfull = matches.group().split('/')
self.vernums = self.verfull[1].split('.')
return self.ageData.getDate(self.vernums)
class BrpWebkit(BrowserParser):
def __init__(self):
super(BrpWebkit, self).__init__()
self.ageData = AgeData('age-webkit.json')
def getParseOrder(self):
return 6
def doesMatch(self, ua):
return ua and 'webkit' in ua
def getBrowser(self):
return 'webkit'
def getReleaseDate(self, ua):
""" http://en.wikipedia.org/wiki/Safari_version_history """
matches = re.compile('safari/[a-z0-9\.]*').search(ua)
if not matches:
return None
self.verfull = matches.group().split('/')
self.vernums = self.verfull[1].split('.')
return self.ageData.getDate(self.vernums)