-
Notifications
You must be signed in to change notification settings - Fork 1
/
newsTodayClasses.py
110 lines (75 loc) · 2.06 KB
/
newsTodayClasses.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
# Replaces strings in Latin extended with ASCII equivalents.
#
# This is for handling web servers with FUCKED UP encodings.
#
# Oh yeah, this is a big fat hack.
def ReplaceLatinExtended(s):
s = s.replace("–", "-")
s = s.replace("—", "-")
s = s.replace("‘", "\'")
s = s.replace("’", "\'")
s = s.replace("‚", ",")
s = s.replace("“", "\"")
s = s.replace("”", "\"")
s = s.replace("„", "\"")
s = s.replace("•", "•")
s = s.replace("…", "...")
s = s.replace("€", "€")
# TODO: http://www.ascii.cl/htmlcodes.htm
# †
# ‡
# ‰
# ™
return s
class BlogLink:
def __init__(self, url, post):
self.url = url
self.posts = []
self.categories = []
self.posts.append(post)
def addPost(self, post):
self.posts.append(post)
def size(self):
return len(self.posts)
class BlogPost:
def __init__(self, url, title, channelTitle, channelURL, date, htmlBlock):
self.url = url
try:
self.title = ReplaceLatinExtended(title)
except:
self.title = title.encode('utf8', 'ignore')
self.channelTitle = channelTitle
self.channelURL = channelURL
self.date = date
try:
self.htmlBlock = ReplaceLatinExtended(htmlBlock)
except:
self.htmlBlock = htmlBlock.encode('utf8', 'ignore')
self.categories = []
def GetCategoriesString(self):
try:
s = ""
for c in self.categories:
s += c + " "
return s
except:
return ""
def GetCategoriesList(self):
try:
return self.categories
except:
return []
def HasCategory(self, catName):
for c in self.categories:
if c.lower() == catName.lower(): return True
return False
def hasCategories(self):
return len(self.GetCategoriesList()) > 0
def addCategory(self, category):
try:
self.categories.append(category)
except:
self.categories = []
self.addCategory(category)
def removeAllCategories(self):
self.categories = []