2
from flexget.plugin import register_plugin, register_parser_option
4
log = logging.getLogger('try_regexp')
9
This plugin allows user to test regexps for a feed.
15
def matches(self, entry, regexp):
16
"""Return True if any of the entry string fields match given regexp"""
18
for field, value in entry.iteritems():
19
if not isinstance(value, basestring):
21
if re.search(regexp, value, re.IGNORECASE | re.UNICODE):
25
def on_feed_filter(self, feed):
26
if not feed.manager.options.try_regexp:
32
print 'Hi there, welcome to try regexps in realtime!'
33
print 'Press ^D or type \'exit\' to continue. Type \'continue\' to continue non-interactive execution.'
34
print 'Feed \'%s\' has %s entries, enter regexp to see what matches it.' % (feed.name, len(feed.entries))
40
if s == 'abort' or s == 'continue':
47
for entry in feed.entries:
49
match, field = self.matches(entry, s)
51
print 'Title: %-40s URL: %-30s From: %s' % (entry['title'], entry['url'], field)
54
print 'Invalid regular expression'
56
print '%s of %s entries matched' % (count, len(feed.entries))
59
register_plugin(PluginTryRegexp, '--try-regexp', builtin=True)
60
register_parser_option('--try-regexp', action='store_true', dest='try_regexp', default=False,
61
help='Try regular expressions interactively.')