Skip to content

Commit

Permalink
#PRS-10 Fixes errors [Finishes #organizations/belorusneft_by #112786823]
Browse files Browse the repository at this point in the history
  • Loading branch information
muhtar05 committed Apr 6, 2016
1 parent 8374348 commit 5ba4b04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 16 additions & 5 deletions organizations/belorusneft_by/belorusneft/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,12 @@ def validate_phones(self, phone):
else:
phns = phone.split(',')

phone_code = ''
phone_type = u'phone'
for ph in phns:
if ph.strip():

if u"факс" in ph:
phone_type = u"fax"
ph = ph.strip()
ph = re.sub('^\+375','',ph)
ph = re.sub('\D', '', ph)
Expand All @@ -220,9 +223,14 @@ def validate_phones(self, phone):
if len(ph)>9:
ph = re.sub('^0','',ph)

if len(ph)<7:
ph = phone_code + ph
ph = re.sub('\D','',ph)

for code in BY_TYL_CODES:
if ph.find(code) == 0:
phones.append(u"+375" + u" (" + code + u") " + re.sub("^%s" % code, '', ph))
phones.append([u"+375" + u" (" + code + u") " + re.sub("^%s" % code, '', ph), phone_type])
phone_code = code
break

return phones
Expand All @@ -249,7 +257,7 @@ def process_item(self, item, spider):
longitude = item['longitude']

if not phones:
phones = u"(232) 793333"
phones = [u"(232) 793333", u'phone']

self.count_item += 1
xml_item = etree.SubElement(self.xml, 'company')
Expand All @@ -274,6 +282,9 @@ def process_item(self, item, spider):
address = self.get_result_cc(address)
xml_address.text = address

xml_phones_raw = etree.SubElement(xml_item, 'phones_raw')
xml_phones_raw.text = ''.join(item['phone'])

xml_country = etree.SubElement(xml_item, 'country', lang=u'ru')
xml_country.text = u"Беларусь"

Expand All @@ -288,9 +299,9 @@ def process_item(self, item, spider):
for phone in self.validate_phones(phones):
xml_phone = etree.SubElement(xml_item, 'phone')
xml_phone_number = etree.SubElement(xml_phone, 'number')
xml_phone_number.text = phone
xml_phone_number.text = phone[0]
xml_phone_type = etree.SubElement(xml_phone, 'type')
xml_phone_type.text = u'phone'
xml_phone_type.text = phone[1]
xml_phone_ext = etree.SubElement(xml_phone, 'ext')
xml_phone_info = etree.SubElement(xml_phone, 'info')

Expand Down
2 changes: 1 addition & 1 deletion organizations/belorusneft_by/belorusneft/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@
1633,
1651,
1713,
2222,
222,
2222,
2351,
1773,
1515,
Expand Down

0 comments on commit 5ba4b04

Please sign in to comment.