From ebaffa2e0d6a030dfc3c78a3b9515093b14f7103 Mon Sep 17 00:00:00 2001 From: Evgeny Anatskiy Date: Fri, 14 Oct 2016 22:29:55 +0200 Subject: [PATCH] fix failing Travis tests #2 (TOX_ENV=py27-lint) and #6 (TOX_ENV=py27-lint-imports) --- .../demo/phdcomics/helper/__init__.py | 21 ++++++++----------- lib/galaxy/webapps/galaxy/api/webhooks.py | 4 ++-- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/config/plugins/webhooks/demo/phdcomics/helper/__init__.py b/config/plugins/webhooks/demo/phdcomics/helper/__init__.py index a7175b132971..94073b9c6eec 100644 --- a/config/plugins/webhooks/demo/phdcomics/helper/__init__.py +++ b/config/plugins/webhooks/demo/phdcomics/helper/__init__.py @@ -6,17 +6,6 @@ log = logging.getLogger(__name__) -def get_latest_id(): - url = 'http://phdcomics.com/gradfeed.php' - content = urllib.urlopen(url).read() - soap = BeautifulSoup(content, 'html.parser') - pattern = '(?:http://www\.phdcomics\.com/comics\.php\?f=)(\d+)' - return max([ - int(re.search(pattern, link.text).group(1)) - for link in soap.find_all('link', text=re.compile(pattern)) - ]) - - def main(trans, webhook): error = '' data = {} @@ -29,8 +18,16 @@ def main(trans, webhook): log.exception(e) return {} + # Get latest id if 'latest_id' not in webhook.config.keys(): - webhook.config['latest_id'] = get_latest_id() + url = 'http://phdcomics.com/gradfeed.php' + content = urllib.urlopen(url).read() + soap = BeautifulSoup(content, 'html.parser') + pattern = '(?:http://www\.phdcomics\.com/comics\.php\?f=)(\d+)' + webhook.config['latest_id'] = max([ + int(re.search(pattern, link.text).group(1)) + for link in soap.find_all('link', text=re.compile(pattern)) + ]) random_id = random.randint(1, webhook.config['latest_id']) url = 'http://www.phdcomics.com/comics/archive.php?comicid=%d' % \ diff --git a/lib/galaxy/webapps/galaxy/api/webhooks.py b/lib/galaxy/webapps/galaxy/api/webhooks.py index 5865c2c844e3..ec0bbdaa0e9b 100644 --- a/lib/galaxy/webapps/galaxy/api/webhooks.py +++ b/lib/galaxy/webapps/galaxy/api/webhooks.py @@ -37,8 +37,8 @@ def get_random(self, trans, webhook_type, **kwd): webhooks = [ webhook for webhook in self.app.webhooks_registry.webhooks - if webhook_type in webhook.type \ - and webhook.activate == True + if webhook_type in webhook.type and + webhook.activate is True ] return random.choice(webhooks).to_dict() if webhooks else {}