-
-
Notifications
You must be signed in to change notification settings - Fork 416
/
Copy pathsection_parsing.py
31 lines (25 loc) · 1.08 KB
/
section_parsing.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
from database import PARSABLE_TERRITORIES
from database.models import BiddingExemption
from gazette import locations
class SectionParsing:
def __init__(self, session):
self.session = session
def condition(self):
return 'is_parsed = FALSE'
def update(self, gazettes):
for gazette in gazettes:
territory = PARSABLE_TERRITORIES.get(gazette.territory_id)
if territory:
parsing_cls = getattr(locations, territory)
parser = parsing_cls(gazette.source_text)
self.update_bidding_exemptions(gazette, parser)
gazette.is_parsed = True
def update_bidding_exemptions(self, gazette, parser):
parsed_exemptions = parser.bidding_exemptions()
if parsed_exemptions:
for record in gazette.bidding_exemptions:
self.session.delete(record)
for attributes in parsed_exemptions:
record = BiddingExemption(**attributes)
record.date = gazette.date
gazette.bidding_exemptions.append(record)