3
from flexget.plugin import *
5
log = logging.getLogger('try_regexp')
10
This plugin allows user to test regexps for a feed.
17
# this is not meant to be configured .. :)
18
from flexget import validator
19
return validator.factory('any')
21
def matches(self, entry, regexp):
22
"""Return True if any of the entry string fields match given regexp"""
23
for field, value in entry.iteritems():
24
if not isinstance(value, basestring):
26
if re.search(regexp, value, re.IGNORECASE | re.UNICODE):
30
def on_feed_filter(self, feed):
31
if not feed.manager.options.try_regexp and not 'try_regexp' in feed.config:
37
print 'Hi there, welcome to try regexps in realtime!'
38
print 'Press ^D or type \'exit\' to continue. Type \'continue\' to continue non-interactive execution.'
39
print 'Feed \'%s\' has %s entries, enter regexp to see what matches it.' % (feed.name, len(feed.entries))
45
if s == 'abort' or s == 'continue':
52
for entry in feed.entries:
54
match, field = self.matches(entry, s)
56
print 'Title: %-40s URL: %-30s From: %s' % (entry['title'], entry['url'], field)
59
print 'Invalid regular expression'
61
print '%s of %s entries matched' % (count, len(feed.entries))
64
register_plugin(PluginTryRegexp, '--try-regexp', builtin=True)
65
register_parser_option('--try-regexp', action='store_true', dest='try_regexp', default=False,
66
help='Try regular expressions interactively.')