Tweets2pdf

2011年3月1日 发表评论 阅读评论

Days ago, when I was trying to find a way to backup my tweets, I got an idea,why not write a program to generate my tweets to pdf which, in my opinion, is the most elegent document format, so I made a decision to write such a program, but I do not have much time, so I drop the idea of writing it using C, but what language shoud I choose? Since I was willing to learn python long time ago, why not take this chance to learn something about python. What’s more, python is much easier than C, and it can save much time for me, so tweets2pdf written in python came out. OK, stop here, now I will introduce tweets2pdf.

tweets2pdf is only available in Linux now, because I know little about application development in windows, so anyone porting it to windows or other OS is welcome.

1. DOWNLOAD

tarball and demo download: http://code.google.com/p/tweets2pdf/

source code checkout: http://code.google.com/p/tweets2pdf/source/checkout

2. REQUIRES

Reportlab Official Site: http://www.reportlab.com/software/opensource/

The ReportLab Toolkit is the time-proven, ultra-robust open-source engine for programatically creating PDF documents and forms the foundation of RML; it also contains a library for creating platform-independent vector graphics. It’s a fast, flexible, cross platform solution written in Python.

Install in Ubuntu using apt-get:

sudo apt-get install python-reportlab

In other Linux version you can install it with the source code:

Download the source code of reportlab here: http://www.reportlab.com/ftp/

It’s easy to install.If there’s problem,go to the official installation guide:
http://www.reportlab.com/software/installation/

3.INSTALLATION

tar xzf tweets2pdf-0.1.0.tar.gz
cd tweets2pdf-0.1.0
sudo python setup.py install

4. HOWTOUSE

levin@slack:~$ tweets2pdf
This is the first time you use tweets2pdf,needs a little initialization
Please input the location of the font file,eg. /usr/share/fonts/truetype/msyh.ttf:

1.Configuration

You need to make a configuration for your first use of tweets2pdf. What’s most important is to specify an appropriate font for reportlab: Input the absolute path of the font file and press enter. After initialization, the configuration will be saved in ~/.tweets2pdf/cfg.xml, which can be modified if your need some changes.

2.Authentication

For the first time you use tweets2pdf, you also need to authenticate through OAuth to get your access token.Allow tweets2pdf to access your tweets in your browser, and then get a PIN code which shoud be input back to tweets2pdf for it to continue authentication.

After finishing the two steps, you can try to build your own pdf file from your tweets. It can generate 4 types of tweets:

[1] timeline of yourself
[2] my tweets retweeted
[3] tweets retweeted by me
[4] timeline of somebody

5.PROXY

tweets2pdf supports HTTP proxy, set http proxy in this way:

export http_proxy=http://username:password@proxyhost:port
tweets2pdf

You can also use proxychains to make tweets2pdf fetch your tweets through ssh channel.

OK, just have a try, maybe you will like it. If you like it, follow me @levin108 for more information

  1. 2011年2月24日14:26 | #1

    强贴,沙发

  2. 2011年2月24日14:56 | #2

    下次得中英文版本都发一遍。

  3. 2011年2月24日15:46 | #3

    太强大了,抠腚达人啊,tweets备份成PDF确实是不错的选择

  4. 2011年2月24日16:57 | #4

    已经用上了,十分感谢

  5. test
    2011年2月24日19:00 | #5

    安装报错
    /usr/lib/python2.4/distutils/dist.py:236: UserWarning: Unknown distribution option: ‘requires’
    warnings.warn(msg)
    running install
    running build
    running build_py
    running build_scripts
    running install_lib
    byte-compiling /usr/lib/python2.4/site-packages/tweets2pdf/oauthapi.py to oauthapi.pyc
    File “/usr/lib/python2.4/site-packages/tweets2pdf/oauthapi.py”, line 136
    except urllib2.URLError as e:
    ^
    SyntaxError: invalid syntax
    byte-compiling /usr/lib/python2.4/site-packages/tweets2pdf/pdfgen.py to pdfgen.pyc
    File “/usr/lib/python2.4/site-packages/tweets2pdf/pdfgen.py”, line 119
    class tp_document():
    ^
    SyntaxError: invalid syntax
    running install_scripts
    changing mode of /usr/bin/tweets2pdf to 755
    running install_data

  6. ardkat
    2011年2月27日18:05 | #7

    @levin 谢谢提供这么好的工具。
    我想移植到mac上来
    先用homebrew安装了pil
    然后就直接setup.py install
    过程如下
    running install
    running build
    running build_py
    creating build
    creating build/lib
    creating build/lib/tweets2pdf
    copying tweets2pdf/__init__.py -> build/lib/tweets2pdf
    copying tweets2pdf/config.py -> build/lib/tweets2pdf
    copying tweets2pdf/oauth.py -> build/lib/tweets2pdf
    copying tweets2pdf/oauthapi.py -> build/lib/tweets2pdf
    copying tweets2pdf/pdfgen.py -> build/lib/tweets2pdf
    copying tweets2pdf/template.py -> build/lib/tweets2pdf
    copying tweets2pdf/tweets2pdf.py -> build/lib/tweets2pdf
    copying tweets2pdf/twitter.py -> build/lib/tweets2pdf
    running build_scripts
    creating build/scripts-2.6
    copying and adjusting scripts/tweets2pdf -> build/scripts-2.6
    changing mode of build/scripts-2.6/tweets2pdf from 644 to 755
    running install_lib
    creating /usr/lib/python2.6/site-packages
    creating /usr/lib/python2.6/site-packages/tweets2pdf
    copying build/lib/tweets2pdf/__init__.py -> /usr/lib/python2.6/site-packages/tweets2pdf
    copying build/lib/tweets2pdf/config.py -> /usr/lib/python2.6/site-packages/tweets2pdf
    copying build/lib/tweets2pdf/oauth.py -> /usr/lib/python2.6/site-packages/tweets2pdf
    copying build/lib/tweets2pdf/oauthapi.py -> /usr/lib/python2.6/site-packages/tweets2pdf
    copying build/lib/tweets2pdf/pdfgen.py -> /usr/lib/python2.6/site-packages/tweets2pdf
    copying build/lib/tweets2pdf/template.py -> /usr/lib/python2.6/site-packages/tweets2pdf
    copying build/lib/tweets2pdf/tweets2pdf.py -> /usr/lib/python2.6/site-packages/tweets2pdf
    copying build/lib/tweets2pdf/twitter.py -> /usr/lib/python2.6/site-packages/tweets2pdf
    byte-compiling /usr/lib/python2.6/site-packages/tweets2pdf/__init__.py to __init__.pyc
    byte-compiling /usr/lib/python2.6/site-packages/tweets2pdf/config.py to config.pyc
    byte-compiling /usr/lib/python2.6/site-packages/tweets2pdf/oauth.py to oauth.pyc
    byte-compiling /usr/lib/python2.6/site-packages/tweets2pdf/oauthapi.py to oauthapi.pyc
    byte-compiling /usr/lib/python2.6/site-packages/tweets2pdf/pdfgen.py to pdfgen.pyc
    byte-compiling /usr/lib/python2.6/site-packages/tweets2pdf/template.py to template.pyc
    byte-compiling /usr/lib/python2.6/site-packages/tweets2pdf/tweets2pdf.py to tweets2pdf.pyc
    byte-compiling /usr/lib/python2.6/site-packages/tweets2pdf/twitter.py to twitter.pyc
    running install_scripts
    copying build/scripts-2.6/tweets2pdf -> /usr/bin
    changing mode of /usr/bin/tweets2pdf to 755
    running install_data
    creating /usr/share/pixmaps
    copying tweets2pdf.png -> /usr/share/pixmaps
    running install_egg_info
    Writing /usr/lib/python2.6/site-packages/tweets2pdf-0.2.0-py2.6.egg-info

    我是python 2.6.1
    然后运行tweet2pdf 没有出现初始化,就报这个问题了。

    Traceback (most recent call last):
    File “/usr/bin/tweets2pdf”, line 38, in
    import tweets2pdf.tweets2pdf
    ImportError: No module named tweets2pdf.tweets2pdf

    会是什么问题呢?
    当然我也在看这个问题。

  7. dinohu
    2011年3月4日01:20 | #9

    Traceback (most recent call last):
    File “/usr/lib/python2.6/site-packages/tweets2pdf/tweets2pdf.py”, line 180, in start_button_clicked
    main_panel = self)
    File “/usr/lib/python2.6/site-packages/tweets2pdf/pdfgen.py”, line 156, in __init__
    pdfmetrics.registerFont(TTFont(‘song’, font_path))
    File “/usr/lib/python2.6/site-packages/reportlab/pdfbase/ttfonts.py”, line 993, in __init__
    self.face = TTFontFace(filename, validate=validate, subfontIndex=subfontIndex)
    File “/usr/lib/python2.6/site-packages/reportlab/pdfbase/ttfonts.py”, line 902, in __init__
    TTFontFile.__init__(self, filename, validate=validate, subfontIndex=subfontIndex)
    File “/usr/lib/python2.6/site-packages/reportlab/pdfbase/ttfonts.py”, line 410, in __init__
    TTFontParser.__init__(self, file, validate=validate,subfontIndex=subfontIndex)
    File “/usr/lib/python2.6/site-packages/reportlab/pdfbase/ttfonts.py”, line 191, in __init__
    self.readFile(file)
    File “/usr/lib/python2.6/site-packages/reportlab/pdfbase/ttfonts.py”, line 267, in readFile
    self._ttf_data = file.read()
    AttributeError: ‘unicode’ object has no attribute ‘read’

    应该是问题,无论我选什么字体都是这样,请解决

  8. AsterOcclu
    2011年3月5日15:56 | #10

    @ardkat
    请问您把Tweets2PDF移植到Mac上平台的工作有进展了吗?话说……GUI版是不是需要先安装Pygtk之类的包?

  9. ardkat
    2011年3月5日16:02 | #11

    @AsterOcclu
    其实移植当天就好了,不过问题是要做成tarball会有不少整合的事情,所以我还在看是不是可以直接用Cocoa来做Native的code调用楼主的Python代码。
    移植Pygtk是可以,不过我是用另外一个,你要是有兴趣也可以自己试试下面的GTK-OSX吧,我就是用这个,当天就弄好了。记得64位系统要用使用Python32位环境,页面里面说的很清楚。
    http://sourceforge.net/apps/trac/gtk-osx/wiki/Build

  10. AsterOcclu
    2011年3月5日22:38 | #12

    @ardkat
    原来是用GTK-OSK啊,因为我一开始也用了pil,遇到了和您一样的问题……那我再尝试一下,同时感谢@levin了。

  11. 凝赤
    2011年5月22日19:27 | #13

    Python 3 无法导入 import pygtk
    应该是还不支持吧
    更改成/usr/bin/python2就解决了,不过个人觉得这个小软件放在家目录下运行就好了的
    放到根里去,实无必要的哈~~

  12. Andy
    2011年10月5日06:09 | #14

    每次都是停留在最后creating pdf… 的阶段没反应,一直在那里creating pdf 数小时都是一样。progress那里显示已经100%了。 请问可能是哪里的原因?不会是因为太多吧? 40页

  13. Andy
    2011年10月5日07:39 | #15

    我试过linux和win下都是一样的问题:
    Exception in thread Thread-1:
    Traceback (most recent call last):
    File “threading.pyo”, line 530, in __bootstrap_inner
    File “threading.pyo”, line 483, in run
    File “tweets2pdf\tweets2pdf.pyo”, line 42, in generate_thread
    File “tweets2pdf\pdfgen.pyo”, line 609, in dump
    File “reportlab\platypus\doctemplate.pyo”, line 1117, in build
    File “reportlab\platypus\doctemplate.pyo”, line 906, in build
    File “reportlab\platypus\doctemplate.pyo”, line 848, in _endBuild
    File “reportlab\pdfgen\canvas.pyo”, line 1123, in save
    File “reportlab\pdfbase\pdfdoc.pyo”, line 235, in SaveToFile
    File “reportlab\pdfbase\pdfdoc.pyo”, line 257, in GetPDFData
    File “reportlab\pdfbase\pdfdoc.pyo”, line 417, in format
    File “reportlab\pdfbase\pdfdoc.pyo”, line 869, in format
    File “reportlab\pdfbase\pdfdoc.pyo”, line 102, in format
    File “reportlab\pdfbase\pdfdoc.pyo”, line 1635, in format
    File “reportlab\pdfbase\pdfdoc.pyo”, line 667, in format
    File “reportlab\pdfbase\pdfdoc.pyo”, line 102, in format
    File “reportlab\pdfbase\pdfdoc.pyo”, line 1764, in format
    ValueError: format not resolved erased_695353
    请问是怎么回事?

  14. 比利
    2012年1月10日17:23 | #16

    Andy :
    每次都是停留在最后creating pdf… 的阶段没反应,一直在那里creating pdf 数小时都是一样。progress那里显示已经100%了。 请问可能是哪里的原因?不会是因为太多吧? 40页

    博主您好,我在win7下同样遇到了该问题,杀毒软件也关了,运行时也给了管理员权限的.

  15. 2012年1月10日17:27 | #17

    @比利
    这个问题目前在已经修复了,但如果是win7的话集成版我没有重新制作,因为没有win7的环境了,所以如果想要使用最新版本的话需要自己安装需要依赖的相关软件,如pygtk,reportlab等,另外tweets2pdf已经迁移到github上去了,https://github.com/levin108/tweets2pdf 这是最新地址,可以从这里下载最新的代码

  16. 比利
    2012年1月10日17:39 | #18

    既然如此不妨告诉我下win7下要正常运行都需要安装哪些依赖包?我自己试试.
    我确实需要备份一下… 今天从早上10点到现在都绕了好大一个圈了.

  17. 2012年1月10日17:43 | #19

    @比利
    pygtk, reportlab

注意: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。使用'@all ',将会将评论发送给之前所有其它评论者。请务必注意user必须和评论者名相匹配(大小写一致)。