def _fetch_email_count(self, conn, config_setting):
   count = 0
   try:
     conf_set = ConfigSettings(self.acct_set_path)
     from_search_criteria = ''
     subject_search_criteria = ''
     search_criteria = ''
     self.email_poll_interval = int(conf_set.get_value('general', 'email_poll_interval'))
     # Check emails sent from list of senders
     config_from = conf_set.get_value(config_setting, 'from').split('; ')
     config_subject = conf_set.get_value(config_setting, 'subject').split('; ')
     # Compile list of FROM search criteria
     from_search_criteria = self._compile_search_criteria('FROM', config_from)
     # Compile list of FROM search criteria
     subject_search_criteria = self._compile_search_criteria('SUBJECT', config_subject)
     search_criteria = from_search_criteria + subject_search_criteria
     if search_criteria != '':
       # Show only unread emails
       search_criteria = search_criteria + '(UNSEEN)'
       # Search using defined criteria
       typ, msg_ids = conn.search(None, search_criteria)
       # Set email counts
       if msg_ids[0] != '':
         count = len(msg_ids[0].split(' '))
       else:
         count = 0
       if self.verbose == True: print 'INBOX has %d email(s) matching %s' % (count, search_criteria)
     else:
       count = 0
   except:
     pass
   return count
 def test_intializing_writes_defaults(self):
     key = self.__class__._gconf_base + 'remove_whitespace'
     gconf.client_get_default().unset(key)
     self.assertRaises(Exception,
                       self._config.get_bool, 'remove_whitespace')
     config = ConfigSettings()
     self.assertTrue(config.get_bool('remove_whitespace'))
def open_connection(verbose=False):
  # Read the config file
  conf = ConfigSettings('account_settings.ini')

  # Connect to the server
  hostname = conf.get_value('server', 'hostname')
  if verbose: print 'Connecting to', hostname
  connection = imaplib.IMAP4_SSL(hostname)

  # Login to our account
  username = conf.get_value('account', 'username')
  password = conf.get_value('account', 'password')
  if verbose: print 'Logging in as', username
  connection.login(username, password)
  return connection
class ConfigSettingsTest(unittest.TestCase):

    _gconf_base = '/apps/gedit-2/plugins/whitespace-remover/'

    def setUp(self):
        self._config = ConfigSettings()

    def test_return_type(self):
        self.assertTrue(isinstance(self._config.get_bool('remove_whitespace'),
                                   bool))

    def test_write_read_with_true(self):
        self._config.set_bool('remove_whitespace', True)
        self.assertTrue(self._config.get_bool('remove_whitespace'))

    def test_write_read_with_false(self):
        self._config.set_bool('remove_whitespace', False)
        self.assertFalse(self._config.get_bool('remove_whitespace'))

    def test_reading_unknown_key_fails(self):
        self.assertRaises(Exception, self._config.get_bool, 'unknown')

    def test_writing_unknown_key_fails(self):
        self.assertRaises(Exception, self._config.set_bool, 'unknown', True)

    def test_intializing_writes_defaults(self):
        key = self.__class__._gconf_base + 'remove_whitespace'
        gconf.client_get_default().unset(key)
        self.assertRaises(Exception,
                          self._config.get_bool, 'remove_whitespace')
        config = ConfigSettings()
        self.assertTrue(config.get_bool('remove_whitespace'))
 def _fetch_email_count(self, conn, config_setting):
     count = 0
     try:
         conf_set = ConfigSettings(self.acct_set_path)
         from_search_criteria = ''
         subject_search_criteria = ''
         search_criteria = ''
         self.email_poll_interval = int(
             conf_set.get_value('general', 'email_poll_interval'))
         # Check emails sent from list of senders
         config_from = conf_set.get_value(config_setting,
                                          'from').split('; ')
         config_subject = conf_set.get_value(config_setting,
                                             'subject').split('; ')
         # Compile list of FROM search criteria
         from_search_criteria = self._compile_search_criteria(
             'FROM', config_from)
         # Compile list of FROM search criteria
         subject_search_criteria = self._compile_search_criteria(
             'SUBJECT', config_subject)
         search_criteria = from_search_criteria + subject_search_criteria
         if search_criteria != '':
             # Show only unread emails
             search_criteria = search_criteria + '(UNSEEN)'
             # Search using defined criteria
             typ, msg_ids = conn.search(None, search_criteria)
             # Set email counts
             if msg_ids[0] != '':
                 count = len(msg_ids[0].split(' '))
             else:
                 count = 0
             if self.verbose == True:
                 print 'INBOX has %d email(s) matching %s' % (
                     count, search_criteria)
         else:
             count = 0
     except:
         pass
     return count
class ConfigSettingsTest(unittest.TestCase):
    def setUp(self):
        self._config = ConfigSettings()

    def test_return_type(self):
        self.assertTrue(isinstance(self._config.get_bool("remove-whitespace"), bool))

    def test_write_read_with_true(self):
        self._config.set_bool("remove-whitespace", True)
        self.assertTrue(self._config.get_bool("remove-whitespace"))

    def test_write_read_with_false(self):
        self._config.set_bool("remove-whitespace", False)
        self.assertFalse(self._config.get_bool("remove-whitespace"))

    def test_reading_unknown_key_fails(self):
        self.assertRaises(Exception, self._config.get_bool, "unknown")

    def test_writing_unknown_key_fails(self):
        self.assertRaises(Exception, self._config.set_bool, "unknown", True)
Beispiel #7
0
class ConfigSettingsTest(unittest.TestCase):
    def setUp(self):
        self._config = ConfigSettings()

    def test_return_type(self):
        self.assertTrue(
            isinstance(self._config.get_bool('remove-whitespace'), bool))

    def test_write_read_with_true(self):
        self._config.set_bool('remove-whitespace', True)
        self.assertTrue(self._config.get_bool('remove-whitespace'))

    def test_write_read_with_false(self):
        self._config.set_bool('remove-whitespace', False)
        self.assertFalse(self._config.get_bool('remove-whitespace'))

    def test_reading_unknown_key_fails(self):
        self.assertRaises(Exception, self._config.get_bool, 'unknown')

    def test_writing_unknown_key_fails(self):
        self.assertRaises(Exception, self._config.set_bool, 'unknown', True)
 def setUp(self):
     self._config = ConfigSettings()
 def update_kodi_user_settings(self, kodi_path, settings_path):
   kodi_settings_tup = get_kodi_user_settings(kodi_path)
   conf_set = ConfigSettings(settings_path)
   conf_set.set_value('general', 'email_notifications', kodi_settings_tup[0])
   conf_set.set_value('server', 'hostname', kodi_settings_tup[1])
   conf_set.set_value('general', 'email_poll_interval', kodi_settings_tup[2])
   conf_set.set_value('account', 'username', kodi_settings_tup[3])
   conf_set.set_value('account', 'password', kodi_settings_tup[4])
   conf_set.set_value('red_senders', 'from', kodi_settings_tup[5])
   conf_set.set_value('red_senders', 'subject', kodi_settings_tup[6])
   conf_set.set_value('green_senders', 'from', kodi_settings_tup[7])
   conf_set.set_value('green_senders', 'subject', kodi_settings_tup[8])
   conf_set.set_value('blue_senders', 'from', kodi_settings_tup[9])
   conf_set.set_value('blue_senders', 'subject', kodi_settings_tup[10])
   conf_set.set_value('orange_senders', 'from', kodi_settings_tup[11])
   conf_set.set_value('orange_senders', 'subject', kodi_settings_tup[12])
   conf_set.set_value('pink_senders', 'from', kodi_settings_tup[13])
   conf_set.set_value('pink_senders', 'subject', kodi_settings_tup[14])
   conf_set.set_value('sky_senders', 'from', kodi_settings_tup[15])
   conf_set.set_value('sky_senders', 'subject', kodi_settings_tup[16])
   conf_set.set_value('white_senders', 'from', kodi_settings_tup[17])
   conf_set.set_value('white_senders', 'subject', kodi_settings_tup[18])
Beispiel #10
0
from config_settings import ConfigSettings
from data_access_layer import DataAccessLayer
from permission import Permission
from telegram_bot_response_wrapper import TelegramBotResponseWrapper

__all__ = ['main']

logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    level=logging.INFO)
logger = logging.getLogger(__name__)

# data_access_layer = None
lichess = LichessAPI()

config = ConfigSettings()
dal = DataAccessLayer(database=config.db_name,
                      login=config.db_login,
                      password=config.db_password,
                      address=config.db_address,
                      port=config.db_port)

core = Core(dal)


def start(bot, update):
    core.create_user(update)
    update.message.reply_text(
        'You added in bot database. Send /help for see avalible commands')

Beispiel #11
0
 def setUp(self):
     self._config = ConfigSettings()