Skip to content

Commit

Permalink
Merge pull request #20 from kamidipreetham/develop
Browse files Browse the repository at this point in the history
Hotfix: Exception Handling for Controller
  • Loading branch information
Preetham Kamidi committed Jul 11, 2019
2 parents 6ee1cf6 + a048c38 commit 443cf00
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion verifytweet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
from .util import validator
from .util import common

__version__ = "0.5.1"
__version__ = "0.5.2"
20 changes: 10 additions & 10 deletions verifytweet/services/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ def exec(self, file_path):
return (None, ResultStatus.MODULE_FAILURE)
if search_status != ResultStatus.ALL_OKAY:
return (None, search_status)
if not entities['date']:
same_day_tweets = list()
for tweet_obj in search_results:
same_day_tweets.append(tweet_obj.tweet)
validity, match_index, validator_status = common.calculate_and_validate(
entities=entities, same_day_tweets=same_day_tweets)
if validator_status != ResultStatus.ALL_OKAY:
return (None, ResultStatus.MODULE_FAILURE)
return (search_results[match_index], ResultStatus.ALL_OKAY)
return (search_results[0], ResultStatus.ALL_OKAY)
tweet_text_list = list()
for tweet_obj in search_results:
tweet_text_list.append(tweet_obj.tweet)
validity, match_index, validator_status = common.calculate_and_validate(
entities=entities, tweet_text_list=tweet_text_list)
if validator_status == ResultStatus.MODULE_FAILURE:
return (None, ResultStatus.MODULE_FAILURE)
if not validity:
return (None, ResultStatus.NO_RESULT)
return (search_results[match_index], ResultStatus.ALL_OKAY)
3 changes: 2 additions & 1 deletion verifytweet/services/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def rescale(file_path):
cmd = [
'convert', file_path, '-resample', app_config.UPSCALE_RESOLUTION,
'-alpha', 'off', '-colorspace', 'Gray', '-threshold', '75%',
new_file_path
'-density', '300x300', '-units', 'PixelsPerCentimeter', '-blur',
'1x65000', '-level', '50x100%', new_file_path
]
completed_process = subprocess.run(cmd)
completed_process.check_returncode()
Expand Down
10 changes: 6 additions & 4 deletions verifytweet/util/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def extract_and_parse(file_path: str):
return (entities, parser_status)


def calculate_and_validate(entities: dict, same_day_tweets: list):
def calculate_and_validate(entities: dict, tweet_text_list: list):
"""Calculates similarity matrix and validates tweet
Calculates a similarity matrix from same day tweet
Expand All @@ -74,7 +74,7 @@ def calculate_and_validate(entities: dict, same_day_tweets: list):
Args:
entities: represents dictionary of entities extracted from text
same_day_tweets: list of strings representing same day tweets
tweet_text_list: list of strings representing same day tweets
Returns:
valid_tweet: Validity status of tweet
Expand All @@ -84,7 +84,7 @@ def calculate_and_validate(entities: dict, same_day_tweets: list):
try:
text_processor = text_service.TextProcessor()
similarity_matrix, processor_status = text_processor.get_similarity(
entities['tweet'], same_day_tweets)
entities['tweet'], tweet_text_list)
except Exception as e:
logger.exception(e)
return (None, None, ResultStatus.MODULE_FAILURE)
Expand All @@ -97,7 +97,9 @@ def calculate_and_validate(entities: dict, same_day_tweets: list):
except Exception as e:
logger.exception(e)
return (None, None, ResultStatus.MODULE_FAILURE)
if validator_status != ResultStatus.ALL_OKAY:
if validator_status == ResultStatus.MODULE_FAILURE:
return (None, None, validator_status)
logger.debug('Tweet Validity: ' + str(valid_tweet))
if not valid_tweet:
return (False, None, ResultStatus.NO_RESULT)
return (valid_tweet, match_index-1, ResultStatus.ALL_OKAY)

0 comments on commit 443cf00

Please sign in to comment.