Skip to content

Commit

Permalink
Merge pull request #178 from mdhaman/1.5
Browse files Browse the repository at this point in the history
[SDESK-411] set genre for PMF racing and PDA Results
  • Loading branch information
Mayur Dhamanwala authored Dec 6, 2016
2 parents a5ac643 + ee680a9 commit 61931c1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
7 changes: 6 additions & 1 deletion server/aap/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
class AAPParserError(ParserError):

ParserError._codes.update({1100: 'ZCZC input could not be processed',
1101: 'News Bites input could not be processed'})
1101: 'News Bites input could not be processed',
1102: 'PDA Results input could not be processed'})

@classmethod
def ZCZCParserError(cls, exception=None, provider=None):
Expand All @@ -23,3 +24,7 @@ def ZCZCParserError(cls, exception=None, provider=None):
@classmethod
def NewsBitesParserError(cls, exception=None, provider=None):
return ParserError(1101, exception, provider)

@classmethod
def PDAResulstParserError(cls, exception=None, provider=None):
return ParserError(1102, exception, provider)
12 changes: 10 additions & 2 deletions server/aap/io/feed_parsers/pdaresults.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from superdesk.errors import AlreadyExistsError
from superdesk.utc import utcnow
from superdesk.metadata.item import ITEM_TYPE, CONTENT_TYPE, FORMAT, FORMATS
from aap.errors import AAPParserError
import superdesk
import logging
import re
import uuid
Expand Down Expand Up @@ -57,7 +59,7 @@ def parse(self, filename, provider=None):
b'\x1f([Y|N])' +
b'\x1f([Y|N])' +
b'\x1f(.*)' +
b'\x1f(Monday|Tuesday|Wednesday|Thursday|Friday)', lines[0], flags=re.I)
b'\x1f(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday)', lines[0], flags=re.I)
if m:
state = m.group(5).decode('ascii')
item['slugline'] = m.group(1).decode('ascii') + ' Gallop'
Expand Down Expand Up @@ -88,6 +90,8 @@ def parse(self, filename, provider=None):
if abandoned == 'Y':
item['anpa_take_key'] = item.get('anpa_take_key', '') + ' ABANDONED'
item['headline'] = item.get('headline', '') + ' ABANDONED'
else:
raise AAPParserError.PDAResulstParserError()

item['body_html'] = '<pre>' + b'\n'.join(lines[1:]).decode('ascii') + '</pre>'
# remove the sign off as recieved, it will get put back on when published
Expand All @@ -97,7 +101,11 @@ def parse(self, filename, provider=None):

item['subject'] = [{'qcode': '15030001'}]
item['anpa_category'] = [{'qcode': 'r'}]
return item
genre_map = superdesk.get_resource_service('vocabularies').find_one(req=None, _id='genre')
if genre_map:
item['genre'] = [x for x in genre_map.get('items', []) if
x['qcode'] == 'Results (sport)' and x['is_active']]
return item
except Exception as ex:
logging.exception(ex)

Expand Down
11 changes: 7 additions & 4 deletions server/aap/io/feed_parsers/zczc_pmf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def set_item_defaults(self, item, provider):
self.header_map = {self.KEYWORD: self.ITEM_SLUGLINE, self.TAKEKEY: self.ITEM_TAKE_KEY,
self.HEADLINE: self.ITEM_HEADLINE}

def _set_results_genre(self, item):
genre_map = superdesk.get_resource_service('vocabularies').find_one(req=None, _id='genre')
item['genre'] = [x for x in genre_map.get('items', []) if
x['qcode'] == 'Results (sport)' and x['is_active']]

def post_process_item(self, item, provider):
try:
# is it a horse or dog racing item
Expand Down Expand Up @@ -67,14 +72,12 @@ def post_process_item(self, item, provider):
item[self.ITEM_SUBJECT] = [{'qcode': '15030003', 'name': subject_codes['15030003']}]
if item.get(self.ITEM_SLUGLINE, '').find('Gallop') != -1:
item[self.ITEM_SUBJECT] = [{'qcode': '15030001', 'name': subject_codes['15030001']}]

item[self.ITEM_ANPA_CATEGORY] = [{'qcode': 'r'}]
self._set_results_genre(item)
elif item.get(self.ITEM_SLUGLINE, '').find('AFL') != -1:
item[self.ITEM_ANPA_CATEGORY] = [{'qcode': 't'}]
item[self.ITEM_SUBJECT] = [{'qcode': '15084000', 'name': subject_codes['15084000']}]
genre_map = superdesk.get_resource_service('vocabularies').find_one(req=None, _id='genre')
item['genre'] = [x for x in genre_map.get('items', []) if
x['qcode'] == 'Results (sport)' and x['is_active']]
self._set_results_genre(item)
else:
item[self.ITEM_ANPA_CATEGORY] = [{'qcode': 'f'}]
item[self.ITEM_SUBJECT] = [{'qcode': '04000000', 'name': subject_codes['04000000']}]
Expand Down
10 changes: 10 additions & 0 deletions server/aap/tests/io/feed_parsers/pdaresults_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
class PDAResultsTestCase(TestCase):
provider = {'name': 'test provder', 'provider': {}}

vocab = [{'_id': 'genre',
'items': [{
"name": "Results (sport)",
"is_active": True,
"qcode": "Results (sport)"}]}]

def setUp(self):
self.app.data.insert('vocabularies', self.vocab)

def test_default_format(self):
filename = 'RR_20161025_CRANBOURNE_6.tst'
dirname = os.path.dirname(os.path.realpath(__file__))
Expand All @@ -26,6 +35,7 @@ def test_default_format(self):
self.assertEqual(self.items.get('anpa_category')[0]['qcode'], 'r')
self.assertEqual(self.items.get('subject')[0]['qcode'], '15030001')
self.assertEqual(self.items.get('slugline'), 'CRANBOURNE Gallop')
self.assertEqual(self.items.get('genre')[0]['name'], 'Results (sport)')
self.assertIn('versioncreated', self.items)

def test_news_format(self):
Expand Down
3 changes: 3 additions & 0 deletions server/aap/tests/io/feed_parsers/zczc_parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def test_pagemasters_format(self):
self.assertEqual(self.items.get('slugline'), 'Darwin Grey')
self.assertEqual(self.items.get('anpa_category')[0]['qcode'], 'r')
self.assertEqual(self.items.get('subject')[0]['qcode'], '15082000')
self.assertEqual(self.items.get('genre')[0]['name'], 'Results (sport)')

def test_racing_format(self):
filename = 'viflda004_7257.tst'
Expand Down Expand Up @@ -168,6 +169,7 @@ def test_trot_tab_divs(self):
self.assertEqual(self.items.get('slugline'), 'Wagga Trot')
self.assertEqual(self.items.get('anpa_category')[0]['qcode'], 'r')
self.assertEqual(self.items.get('subject')[0]['qcode'], '15030003')
self.assertEqual(self.items.get('genre')[0]['name'], 'Results (sport)')

def test_leading_jockeys(self):
filename = 'vinlpt_8390.tst'
Expand Down Expand Up @@ -229,3 +231,4 @@ def test_greyhound_divs(self):
self.assertEqual(self.items.get('headline'), 'Warragul Greyhound NSW TAB DIVS 1-11 Thursday')
self.assertEqual(self.items.get('slugline'), 'Warragul Greys')
self.assertEqual(self.items.get('anpa_take_key'), 'NSW TAB DIVS 1-11')
self.assertEqual(self.items.get('genre')[0]['name'], 'Results (sport)')

0 comments on commit 61931c1

Please sign in to comment.