Skip to content

Instantly share code, notes, and snippets.

@shidarin
Last active March 30, 2016 11:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shidarin/3f5963449a9c2d29e021 to your computer and use it in GitHub Desktop.
Save shidarin/3f5963449a9c2d29e021 to your computer and use it in GitHub Desktop.
Imgur Album to phpbb forum thumbnail link markdown
import requests
import bs4
def _trim(string, trim_extra=False):
if trim_extra:
trim_length = -5
else:
trim_length = -4
return string[:trim_length]
url = raw_input('imgur url: ').strip()
url = url.split('#')[0]
request = requests.get(url)
main_soup = bs4.BeautifulSoup(request.text)
pictures = main_soup.find_all('a', text='View full resolution')
attr = 'href'
trim_extra = False
if len(pictures) <= 1:
pictures = main_soup.find_all('img', {'class': 'thumb-title'})
attr = 'data-src'
trim_extra = True
print '\n\n'
for picture in pictures:
url = _trim(picture[attr], trim_extra)
print '[url=http:{url}.jpg][img]http:{url_large}.jpg[/img][/url]'.format(
url=url,
url_large=url + 'l'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment