Source

DailyPromptBot / minibot.py

Full commit
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
# The Daily Prompt Mini-Bot - A Shut Up and Write Project
# Version 0.0.1a
# Author: Marc-Alexandre Chan <laogeodritt at arenthil.net>
#-------------------------------------------------------------------------------
#
# Copyright (c) 2012 Marc-Alexandre Chan. Licensed under the GNU GPL version 3
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#-------------------------------------------------------------------------------

""" The Daily Prompt: Minibot (daemon mode) bootstrap script. Use this script to
run the Minibot as a console application. Run this script without arguments. """

from minibot import DailyPromptMinibot
from minibot.errors import InvalidRedditError, ConfigValueError,\
    InvalidUserPass, HTTPError, SQLAlchemyError, DBAPIError,\
    ConfigFileError, LogFileError
import sys

def main():
    try:
        minibot_app = DailyPromptMinibot('minibot.ini')
        minibot_app.init_resources()
    except (ConfigFileError, LogFileError) as e:
        sys.exit(str(e))
    except (IOError, OSError) as e:
        sys.exit("IOError: " + str(e))
    except (ConfigValueError, ValueError) as e:
        sys.exit("Invalid configuration value: " + str(e))
    except InvalidUserPass as e:
        sys.exit("Error logging into Reddit account: " + str(e))
    except HTTPError as e:
        sys.exit("An error occurred accessing Reddit: " + str(e))
    except (SQLAlchemyError, DBAPIError):
        raise # let Python handle it. This line just documents the possibility

    minibot_app.run()

if __name__ == '__main__':
    main()