Created
October 11, 2012 20:35
-
-
Save petrushev/3875302 to your computer and use it in GitHub Desktop.
Get large thumbnails from imgur album
This file contains 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
# Get name and image of mps from sobranie.mk and put them in `PATH` | |
import requests as rq | |
from lxml.html import fromstring | |
PATH = 'target' | |
base = 'http://www.sobranie.mk/' | |
start = base+'?ItemID=C5223B907BD9D247A9245C0C30C2E6AE' | |
def main(): | |
q = rq.get(start) | |
doc = fromstring(q.content) | |
links = doc.cssselect("table.DetalnoTabelaTopHome a.WB_SOBRANIE_TocItem[href]") | |
for l in links: | |
crawl_party(base+ l.attrib['href']) | |
def crawl_party(link): | |
#print '===============' | |
q = rq.get(link) | |
doc = fromstring(q.content) | |
links = doc.cssselect("table.DetalnoTabelaTopHome a.WB_SOBRANIE_ArticleTitle[href]") | |
for l in links: | |
crawl_person(base + l.attrib['href'], l.text_content() ) | |
def crawl_person(link, name): | |
name = name.strip() | |
if name=='': return | |
q = rq.get(link) | |
doc = fromstring(q.content) | |
imgs = doc.cssselect("table.DetalnoTabelaTop table p img[src]") | |
if len(imgs) != 1: | |
print 'Problem with ' + name.encode('utf-8') | |
return | |
q = rq.get(base + imgs[0].attrib['src']) | |
print name.encode('utf-8') | |
with open(PATH + '/' +name+'.jpg', 'wb') as f: | |
f.write( q.content) | |
if __name__=='__main__': | |
main() | |
This file contains 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
# Create meme of all names in a given list `names_path` | |
names_path = 'pratenici.txt' # path of list of names to process (za/protiv/neglasal) | |
img_path = 'source_plain_imgs' | |
target_path = 'target_meme_imgs' | |
import putquote | |
def main(): | |
all_p = [] | |
with open(names_path, 'r') as f: | |
for line in f: | |
all_p.append(line.decode('utf-8').strip()) | |
for p in all_p: | |
try: | |
f = open(img_path + '/' + p + '.jpg') | |
except Exception, exc: | |
print p | |
#print exc | |
putquote.create(img_path, target_path, p) | |
if __name__=='__main__': | |
main() |
This file contains 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
# -*- coding: utf-8 -*- | |
"""Create meme of a single image""" | |
"""Text hardcoded in function (sorry)""" | |
import PIL | |
from PIL import ImageFont | |
from PIL import Image | |
from PIL import ImageDraw | |
font = ImageFont.truetype("/usr/share/fonts/TTF/LiberationSans-Bold.ttf",25) | |
text_left_start = 180 | |
text_color = (117, 44, 29) | |
bkg_color = (214,214,214) | |
#bkg_color = (173, 242, 34) | |
#text_color = (89, 89, 89) | |
def create(source_path, target_path, name): | |
img=Image.new("RGBA", (600,211), bkg_color) | |
draw = ImageDraw.Draw(img) | |
draw.text((text_left_start, 50), u'Здраво, јас сум ',text_color, font=font) | |
draw.text((text_left_start, 80), name , text_color, font=font) | |
draw.text((text_left_start, 110), u'и гласав „ЗА“', text_color, font=font) | |
draw.text((text_left_start, 140), u'цензура на Интернет.', text_color, font=font) | |
draw = ImageDraw.Draw(img) | |
icon = Image.open(source_path + '/' + name + ".jpg") | |
x, y = icon.size | |
img.paste(icon, (10,10,x+10,y+10)) | |
img.save(target_path + "/" + name + ".png") |
This file contains 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
# Get large thumbnails from imgur album with album_id `album_id` | |
import requests as rq | |
from lxml.html import fromstring | |
album_id = "qPOcT" | |
def main(): | |
q = rq.get("http://api.imgur.com/2/album/"+album_id) | |
doc = fromstring(q.content) | |
for l in doc.cssselect("large_thumbnail"): | |
print l.text_content() | |
if __name__=='__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment