Last active
March 30, 2016 11:12
-
-
Save shidarin/3f5963449a9c2d29e021 to your computer and use it in GitHub Desktop.
Imgur Album to phpbb forum thumbnail link markdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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