Skip to content

Commit 0b39676

Browse files
committed
Added twitter plugin.
1 parent 56d5846 commit 0b39676

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

imageresolver/plugins/flickr.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ def get_image(self, url, **kwargs):
1313
if r.status_code == 200:
1414
soup = BeautifulSoup(r.text)
1515
tag = soup.find('img', {'class':'main-photo'})
16-
return 'https:' + tag['src']
16+
if tag:
17+
return 'https:' + tag['src']
1718
return None

imageresolver/plugins/twitter.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import re
2+
import os
3+
import requests
4+
import logging
5+
from urlparse import urlparse
6+
from bs4 import BeautifulSoup
7+
8+
class Plugin:
9+
def get_image(self, url, **kwargs):
10+
if re.search('http(s*):\/\/(mobile\.|m\.)*twitter.com\/[a-zA-z0-9]*\/status\/\d+', url):
11+
logger = logging.getLogger('ImageResolver')
12+
logger.debug('Resolving using plugin ' + str(os.path.basename(__file__)) + ' ' + str(url))
13+
parsed = urlparse(parsed)
14+
r = requests.get(url)
15+
if r.status_code == 200:
16+
soup = BeautifulSoup(r.text)
17+
if parsed.netloc.split('.')[0] == 'mobile':
18+
tag = soup.find('img',{'class':'CroppedPhoto-img u-block'})
19+
if tag:
20+
return tag['src']
21+
22+
else:
23+
tag = soup.find('meta',{'property':'og:image'})
24+
if tag:
25+
return return tag['content']
26+

0 commit comments

Comments
 (0)