Skip to content

Commit 443cf00

Browse files
author
Preetham Kamidi
authored
Merge pull request #20 from kamidipreetham/develop
Hotfix: Exception Handling for Controller
2 parents 6ee1cf6 + a048c38 commit 443cf00

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

verifytweet/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
from .util import validator
3030
from .util import common
3131

32-
__version__ = "0.5.1"
32+
__version__ = "0.5.2"

verifytweet/services/controller.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ def exec(self, file_path):
127127
return (None, ResultStatus.MODULE_FAILURE)
128128
if search_status != ResultStatus.ALL_OKAY:
129129
return (None, search_status)
130-
if not entities['date']:
131-
same_day_tweets = list()
132-
for tweet_obj in search_results:
133-
same_day_tweets.append(tweet_obj.tweet)
134-
validity, match_index, validator_status = common.calculate_and_validate(
135-
entities=entities, same_day_tweets=same_day_tweets)
136-
if validator_status != ResultStatus.ALL_OKAY:
137-
return (None, ResultStatus.MODULE_FAILURE)
138-
return (search_results[match_index], ResultStatus.ALL_OKAY)
139-
return (search_results[0], ResultStatus.ALL_OKAY)
130+
tweet_text_list = list()
131+
for tweet_obj in search_results:
132+
tweet_text_list.append(tweet_obj.tweet)
133+
validity, match_index, validator_status = common.calculate_and_validate(
134+
entities=entities, tweet_text_list=tweet_text_list)
135+
if validator_status == ResultStatus.MODULE_FAILURE:
136+
return (None, ResultStatus.MODULE_FAILURE)
137+
if not validity:
138+
return (None, ResultStatus.NO_RESULT)
139+
return (search_results[match_index], ResultStatus.ALL_OKAY)

verifytweet/services/image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ def rescale(file_path):
7676
cmd = [
7777
'convert', file_path, '-resample', app_config.UPSCALE_RESOLUTION,
7878
'-alpha', 'off', '-colorspace', 'Gray', '-threshold', '75%',
79-
new_file_path
79+
'-density', '300x300', '-units', 'PixelsPerCentimeter', '-blur',
80+
'1x65000', '-level', '50x100%', new_file_path
8081
]
8182
completed_process = subprocess.run(cmd)
8283
completed_process.check_returncode()

verifytweet/util/common.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def extract_and_parse(file_path: str):
6565
return (entities, parser_status)
6666

6767

68-
def calculate_and_validate(entities: dict, same_day_tweets: list):
68+
def calculate_and_validate(entities: dict, tweet_text_list: list):
6969
"""Calculates similarity matrix and validates tweet
7070
7171
Calculates a similarity matrix from same day tweet
@@ -74,7 +74,7 @@ def calculate_and_validate(entities: dict, same_day_tweets: list):
7474
7575
Args:
7676
entities: represents dictionary of entities extracted from text
77-
same_day_tweets: list of strings representing same day tweets
77+
tweet_text_list: list of strings representing same day tweets
7878
7979
Returns:
8080
valid_tweet: Validity status of tweet
@@ -84,7 +84,7 @@ def calculate_and_validate(entities: dict, same_day_tweets: list):
8484
try:
8585
text_processor = text_service.TextProcessor()
8686
similarity_matrix, processor_status = text_processor.get_similarity(
87-
entities['tweet'], same_day_tweets)
87+
entities['tweet'], tweet_text_list)
8888
except Exception as e:
8989
logger.exception(e)
9090
return (None, None, ResultStatus.MODULE_FAILURE)
@@ -97,7 +97,9 @@ def calculate_and_validate(entities: dict, same_day_tweets: list):
9797
except Exception as e:
9898
logger.exception(e)
9999
return (None, None, ResultStatus.MODULE_FAILURE)
100-
if validator_status != ResultStatus.ALL_OKAY:
100+
if validator_status == ResultStatus.MODULE_FAILURE:
101101
return (None, None, validator_status)
102102
logger.debug('Tweet Validity: ' + str(valid_tweet))
103+
if not valid_tweet:
104+
return (False, None, ResultStatus.NO_RESULT)
103105
return (valid_tweet, match_index-1, ResultStatus.ALL_OKAY)

0 commit comments

Comments
 (0)