예제 #1
0
def api_warning(api_name, message, request=None):
    if request is not None:
        client = get_ip(request)
        log_warning("API", "%s (%s): %s" % (api_name.upper(), client, message))
        del client
    else:
        log_warning("API", "%s (NO-IP): %s" % (api_name.upper(), message))
예제 #2
0
 def __init__(self):
     self.games = dict()
     try:
         self.twitter = twitter.Api(
             consumer_key=settings.TWITTER_API['CONSUMER_KEY'],
             consumer_secret=settings.TWITTER_API['CONSUMER_SECRET'],
             access_token_key=settings.TWITTER_API['ACCESS_TOKEN'],
             access_token_secret=settings.TWITTER_API['ACCESS_TOKEN_SECRET']
         )
     except twitter.TwitterError:
         log_warning(
             'EVENT',
             'Error authenticating the Twitter API! Posts will be unavailable!'
         )
         self.twitter = None
예제 #3
0
 def load_daemons(self, daemon_dir):
     if not os.path.isdir(daemon_dir):
         return
     daemon_list = os.listdir(daemon_dir)
     if len(daemon_list) > 0:
         for daemon_file in daemon_list:
             if ".py" in daemon_file and not (
                 " " in daemon_file or "-" in daemon_file or "-" in daemon_file
             ):
                 try:
                     daemon_loader = importlib.util.spec_from_file_location(
                         daemon_file.replace(".py", ""),
                         os.path.join(daemon_dir, daemon_file),
                     )
                     if daemon_loader is None:
                         continue
                     daemon_class = importlib.util.module_from_spec(daemon_loader)
                     if daemon_class is None:
                         continue
                     daemon_loader.loader.exec_module(daemon_class)
                     try:
                         daemon_class_def = getattr(daemon_class, "init_daemon")
                         if daemon_class_def is not None and callable(
                             daemon_class_def
                         ):
                             daemon_entry = daemon_class_def()
                             if daemon_entry is not None:
                                 self.daemons.append(daemon_entry)
                                 log_debug(
                                     "DAEMON",
                                     'Loaded Daemon "%s"!' % daemon_class.__name__,
                                 )
                         del daemon_class
                         del daemon_loader
                     except AttributeError:
                         log_warning(
                             "DAEMON",
                             'Daemon class for "%s" does not have the "init_daemon" method, ignoring!'
                             % daemon_class.__name__,
                         )
                 except Exception as loadError:
                     log_error(
                         "DAEMON",
                         'An error ocured when attempting to load Daemon "%s"! Exception: "%s'
                         % (daemon_file, str(loadError)),
                     )
     del daemon_list
예제 #4
0
 def post_tweet(self, status):
     if not settings.TWITTER_API['ENABLED']:
         log_debug('EVENT-TWITTER',
                   'Twitter not enabled.  Post: "%s"' % status)
         return
     if self.twitter is None:
         log_warning(
             'EVENT',
             'Twitter API in not available! Posts will be unavailable!')
         return
     try:
         self.twitter.PostUpdate(status)
     except twitter.TwitterError as twitterError:
         if 'Status is a duplicate' in str(twitterError.message):
             log_debug('EVENT', 'Posted a duplicate status! "%s"' % status)
         else:
             self.twitter = None
예제 #5
0
 def post_tweet(self, status):
     if not settings.TWITTER_API["ENABLED"]:
         log_debug("EVENT-TWITTER",
                   'Twitter not enabled.  Post: "%s"' % status)
         return
     if self.twitter is None:
         log_warning(
             "EVENT",
             "Twitter API in not available! Posts will be unavailable!")
         return
     try:
         self.twitter.PostUpdate(
             "%s %s" % (status, " ".join(settings.TWITTER_API["HASHTAGS"])))
     except twitter.TwitterError as twitterError:
         if "Status is a duplicate" in str(twitterError.message):
             log_debug("EVENT", 'Posted a duplicate status! "%s"' % status)
         else:
             self.twitter = None