User:Eleanorg/2.1/Placard Generator: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 34: Line 34:
slogans.append(slogan)
slogans.append(slogan)
print slogans
print slogans
</source>
==making PDFs==
Anyone know a good way of making nice looking pdfs?
The internets suggested making a .ps file and using Ghostscript's ps2pdf function to convert to .pdf.
===generate a .ps file===
This contains instructions on fonts etc.
<source>
%!
/Helvetica findfont 300 scalefont setfont
300 300 moveto
(Hello, world!) show
showpage
</source>
===convert to .pdf===
In bash, do something like this:
<source lang="bash">
find . -type f -name "*.ps" | while read ONELINE; do ps2pdf "$ONELINE" "$(echo "$ONELINE" | sed 's/.ps/.pdf/g')"; done
</source>
</source>

Revision as of 03:52, 11 November 2012

No time to make a placard for that demo? Generate one from the latest slogans courtesy of Socialist Worker.
Media still peddle lies

Code

Scrape them slogans

#!/usr/bin/python
#-*- coding:utf-8 -*-

from urllib import urlopen
from BeautifulSoup import BeautifulSoup

url = "http://www.socialistworker.co.uk/section.php?id=19"
webpage = urlopen(url).read()

# parse it with Beautiful Soup to extract p tags
soup = BeautifulSoup(webpage)

# get content of the <a> tags inside <h4 class="hilihead">

headingSoup = soup.findAll('h4', { "class" : "hilihead" })

# print text within first two h4 tags
#for i in range(0,2):
#	print headingSoup[i].contents[0].contents[0]
	
# append slogans to a list for later use
slogans = []
for i in range(0,2):
	slogan = headingSoup[i].contents[0].contents[0]
	slogans.append(slogan)
print slogans

making PDFs

Anyone know a good way of making nice looking pdfs?

The internets suggested making a .ps file and using Ghostscript's ps2pdf function to convert to .pdf.

generate a .ps file

This contains instructions on fonts etc.

%!
/Helvetica findfont 300 scalefont setfont
300 300 moveto
(Hello, world!) show
showpage

convert to .pdf

In bash, do something like this:

find . -type f -name "*.ps" | while read ONELINE; do ps2pdf "$ONELINE" "$(echo "$ONELINE" | sed 's/.ps/.pdf/g')"; done