Skip to content

Instantly share code, notes, and snippets.

@futureshape
Created February 5, 2013 18:51
Show Gist options
  • Save futureshape/4716676 to your computer and use it in GitHub Desktop.
Save futureshape/4716676 to your computer and use it in GitHub Desktop.
Download a list of tweets from Twitter and format them into a PDF for printing - each page shows the full tweet text, screen name and profile image. Python dependencies: * Twitter (http://pypi.python.org/pypi/twitter) * fpdf (http://pypi.python.org/pypi/fpdf/1.7)
from twitter import *
from fpdf import FPDF
import urllib
pdf=FPDF('L', 'mm', 'A4')
pdf.add_font('DejaVu','','DejaVuSans.ttf',uni=True)
t = Twitter(
auth=OAuth("xxx",
"xxx",
"xxx",
"xxx")
)
tweetlist = t.favorites.list(count=200)
for tweet in tweetlist:
screen_name = tweet['user']['screen_name']
tweet_text = tweet['text']
print screen_name + ': ' + tweet_text
pdf.add_page()
pdf.set_font('DejaVu','',56)
pdf.multi_cell(0, 25, tweet_text, align='L')
pdf.set_y(-55)
pdf.set_x(60)
pdf.set_font('DejaVu','',45)
pdf.multi_cell(0,30,'@' + screen_name)
profile_image_url = tweet['user']['profile_image_url'].replace("_normal", "")
avatar_file_name = "avatars/"+screen_name+".jpg"
urllib.urlretrieve(profile_image_url, avatar_file_name)
pdf.image(avatar_file_name, 10, 160, 40, 40)
pdf.output('tweets.pdf','F')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment