/
content.py
68 lines (50 loc) · 1.92 KB
/
content.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
# -*- coding: UTF-8 -*-
#This file is part of dmoz2db.
#dmoz2db is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#dmoz2db is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with dmoz2db. If not, see <http://www.gnu.org/licenses/>.
"""
Object representation for dmoz content data
Able to store its contents in a database
"""
from __future__ import unicode_literals
__version__ = '0.1'
__author__ = 'Johannes Knopp <johannes@informatik.uni-mannheim.de>'
__copyright__ = '© Copyright 2010 Johannes Knopp'
import sys
import logging
from sqlalchemy.sql.expression import bindparam
from sqlalchemy.exceptions import IntegrityError
from prepared_statements import *
_log = logging.getLogger(__name__)
class Link(object):
def __init__(self, link, catid):
self.catid = catid
self.link = link
self.title = ''
self.description = ''
def __str__(self):
return self.__unicode__.encode('utf8')
def __unicode__(self):
return self.link
def store_in_db(self, engine):
"""
Inserts the values into the externalpage Table
"""
conn = engine.connect()
try:
conn.execute(ins_externalpage,
cid=self.catid,
lnk=self.link,
lnktitle=self.title,
descr=self.description
)
except IntegrityError:
_log.debug('IntegrityError: catid({0}) already has link({1})'.format(self.catid, self.link))