<commit_before>""" OutputTwitter - Produces a twitter post for each entry

    MIT Licensed, derrivative work of Flexget module OutputEmail """

import logging
from flexget.plugin import *

__pychecker__ = 'unusednames=parser'

log = logging.getLogger('twitter')

class OutputTwitter:

    """
        Send a Twitter for each (downloaded) entries.

        Config:
            username	: twitter username (required)
            password	: <PASSWORD> (required)
            to          : the recipients
            apiurl      : API URL 
            active      : is this plugin active or not ?

        Config basic example:

            twitter:
                username: mythbox
                password: <PASSWORD>

    """
    def validator(self):
        from flexget import validator
        twitter = validator.factory('dict')
        twitter.accept('boolean', key='active')
        twitter.accept('text', key='to')
        twitter.accept('text', key='username', required=True)
        twitter.accept('text', key='password', required=True)
        twitter.accept('text', key='apiurl')
        return twitter

    def get_config(self, feed):
        config = feed.config['twitter']
        config.setdefault('active', True)
        config.setdefault('apiurl', 'http://twitter.com/')
        return config

    def feed_exit(self, feed):
        """Send email at exit."""
        config = self.get_config(feed)

        if not config['active']:
            return

        # don't send twits when learning
        if feed.manager.options.learn:
            return

        api = twitter.Api(username=config['username'], password=config['password'])

        if not api.GetFriends():
            log.warn("Invalid twitter username or password")
            return

        entries_count = len(feed.accepted)
        if entries_count == 0:
            return # don't send empty twits

        for entry in feed.accepted:
            if len(entry['title']) > 103:
                content = "%s... found and queued" % entry['title'][:104]
            else:
                content = "%s found and queued" % entry['title']
            log.debug("Sending Twitter: %s", content)
            api.PostUpdate(content)

try:
    import twitter
except ImportError:
    raise PluginError('Unable to import module twitter, python-twitter is required to use output_twitter')
else:
    register_plugin(OutputTwitter, 'twitter')<commit_msg>Fixed output_twitter.py to call correctly<commit_after>""" OutputTwitter - Produces a twitter post for each entry

    MIT Licensed, derrivative work of Flexget module OutputEmail """

import logging
from flexget.plugin import *

__pychecker__ = 'unusednames=parser'

log = logging.getLogger('twitter')

class OutputTwitter:

    """
        Send a Twitter for each (downloaded) entries.

        Config:
            username	: twitter username (required)
            password	: <PASSWORD> (required)
            to          : the recipients
            apiurl      : API URL 
            active      : is this plugin active or not ?

        Config basic example:

            twitter:
                username: mythbox
                password: <PASSWORD>

    """
    def validator(self):
        from flexget import validator
        twitter = validator.factory('dict')
        twitter.accept('boolean', key='active')
        twitter.accept('text', key='to')
        twitter.accept('text', key='username', required=True)
        twitter.accept('text', key='password', required=True)
        twitter.accept('text', key='apiurl')
        return twitter

    def get_config(self, feed):
        config = feed.config['twitter']
        config.setdefault('active', False)
        config.setdefault('apiurl', 'http://twitter.com/')
        return config

    def on_feed_exit(self, feed):
        """Send email at exit."""
        config = self.get_config(feed)

        if not config['active']:
            log.debug("twitter plugin not active")
            return

        # don't send twits when learning
        if feed.manager.options.learn:
            log.debug("learn mode, skipping")
            return

        log.debug("Loading twitter api")
        api = twitter.Api(username=config['username'], password=config['password'])

        if not api.GetFriends():
            log.warn("Invalid twitter username or password")
            return

        entries_count = len(feed.accepted)
        if entries_count == 0:
            return # don't send empty twits

        for entry in feed.accepted:
            if len(entry['title']) > 103:
                content = "%s... found and queued" % entry['title'][:104]
            else:
                content = "%s found and queued" % entry['title']
            log.debug("Sending Twitter: %s", content)
            api.PostUpdate(content)

try:
    import twitter
except ImportError:
    raise PluginError('Unable to import module twitter, python-twitter is required to use output_twitter')
else:
    log.debug("Registering plugin: twitter")
    register_plugin(OutputTwitter, 'twitter')
{'fraction_non_alphanumeric': 0.10629067245119306, 'fraction_numerical': 0.0027607966870439754, 'mean_word_length': 2.204042956411876, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '462176', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1276, 'n_words': 386}