Commit 97efa2ff by Serbaf

changed prints for logs and sys.exit for exceptions

parent 90680e39
# -*- coding: utf-8 -*-
"""Main module."""
import logging
import sys
from tweet_manager.lib import format_csv
# Configure logger
LOG_FORMAT = '[%(asctime)-15s] %(levelname)s: %(message)s'
logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
logger = logging.getLogger("logger")
class Tweet():
"""
......@@ -358,6 +364,10 @@ class Tweet():
return getattr(self, key)
class NotValidTweetError(Exception):
pass
def get_tweets_from_csv(csv_file):
"""
Take one argument: a path pointing to a valid CSV file.
......@@ -385,9 +395,11 @@ def get_tweets_from_csv(csv_file):
for component in field_components:
error_string += component
if (checking_dict is None) or (component not in checking_dict):
print('The field in the header "' + error_string + '" is ' +
'not a valid element of a Tweet')
sys.exit(1)
logger.error('The field in the header "{error_string}" ' +
'is not a valid element of a Tweet')
raise NotValidTweetError("Header contains field which doesn't"
+ " belong to tweet specification: "
+ error_string)
checking_dict = checking_dict[component]
error_string += "."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment