mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Upgrade syntax using `pyupgrade --py36-plus` . Manually drop several `six` imports. Also: - Remove broken pr_cache in scripts/bootstrap_history.py - Fix broken prefix removal in lib/galaxy/tool_util/deps/mulled/mulled_build.py
49 lines
1.5 KiB
Python
49 lines
1.5 KiB
Python
import logging
|
|
import random
|
|
import re
|
|
from urllib.request import urlopen
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
def main(trans, webhook, params):
|
|
error = ''
|
|
comic_src = ''
|
|
|
|
try:
|
|
# Third-party dependencies
|
|
try:
|
|
from bs4 import BeautifulSoup
|
|
except ImportError as e:
|
|
log.exception(e)
|
|
return {'success': False, 'error': str(e)}
|
|
|
|
# Get latest id
|
|
if 'latest_id' not in webhook.config.keys():
|
|
url = 'http://phdcomics.com/gradfeed.php'
|
|
content = urlopen(url).read()
|
|
soap = BeautifulSoup(content, 'html.parser')
|
|
pattern = r'(?: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' % \
|
|
random_id
|
|
content = urlopen(url).read()
|
|
soup = BeautifulSoup(content, 'html.parser')
|
|
comic_img = soup.find_all('img', id='comic2')
|
|
|
|
try:
|
|
comic_src = comic_img[0].attrs.get('src')
|
|
except IndexError:
|
|
pattern = r'<img id=comic2 name=comic2 src=([\w:\/\.]+)'
|
|
comic_src = re.search(pattern, content).group(1)
|
|
|
|
except Exception as e:
|
|
error = str(e)
|
|
|
|
return {'success': not error, 'error': error, 'src': comic_src}
|