-
Notifications
You must be signed in to change notification settings - Fork 4
/
test7.py
47 lines (40 loc) · 1.6 KB
/
test7.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
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
class Inteum(object):
def __init__(self, dsn):
engine = create_engine(dsn)
self.Base = declarative_base()
self.Base.metadata.reflect(engine)
self.db = sessionmaker(engine)()
self.tables = self.Base.metadata.tables
def get_technologies(self):
class Technology(self.Base):
__table__ = self.tables['TECHNOL']
technologies = []
for technology in self.db.query(Technology):
technologies.append({
'id': int(technology.PRIMARYKEY),
'case': strip(technology.TECHID),
'title': strip(technology.NAME),
})
return technologies
def get_patents(self):
class Patent(self.Base):
__table__ = self.tables['PATENTS']
patents = []
for patent in self.db.query(Patent):
patents.append({
'id': int(patent.PRIMARYKEY),
'technologyID': int(patent.TECHNOLFK),
'title': strip(patent.NAME),
'lawFirmID': int(patent.LAWFIRMFK),
'lawFirmCase': strip(patent.LEGALREFNO),
'filingDate': patent.FILEDATE.strftime('%Y%m%d') if patent.FILEDATE.year != 1899 else '',
'patentStatusID': int(patent.PATSTATFK),
'patentTypeID': int(patent.PAPPTYPEFK),
'countryID': int(patent.COUNTRYFK),
})
return patents
def strip(text):
return text.strip() if text else ''