V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
ahxxm
V2EX  ›  Python

写了个删推小工具…

  •  
  •   ahxxm ·
    ahxxm · 2013-05-11 18:50:04 +08:00 · 4023 次点击
    这是一个创建于 4003 天前的主题,其中的信息可能已经有所发展或是发生改变。
    直接上链接: https://github.com/ahxxm/Old-Tweet-Delete

    对to do我是这么想的:

    1.整合tweepy是为了降低使用难度,看了一下代码,import来import去的……

    2.用vps测试时没有遇到api limit,于是想要多线程,直接把tweet id分组或者用多个api什么的,这叫……binomial deleting algorithm?

    3.输入python old-tweets-delete.py后,打开当前文件夹内的tweets.zip,列出每月tweets数,并输入月份,格式可以是:201001-201008,或者“201001,201005,201006-201012”。

    4.vpn不是人人都有的,查了一圈儿,只发现urllib2可以用http代理,有帖子称python程序会调用IE代理、会调用环境变量http_proxy,但测试均无效。

    求解
    18 条回复    1970-01-01 08:00:00 +08:00
    thedevil5032
        1
    thedevil5032  
       2013-05-11 20:35:38 +08:00   ❤️ 1
    我只用过 Python3 里面的 urllib.request.urlopen。

    下面这段话来自 Python 自己的文档:
    http://docs.python.org/3/library/urllib.request.html#module-urllib.request

    In addition, if proxy settings are detected (for example, when a *_proxy environment variable like http_proxy is set), ProxyHandler is default installed and makes sure the requests are handled through the proxy.

    我做过一个 PyQt 应用,VocVoc@github。其中用到了 urlopen, 用下来的效果是确实会自动检测代理设置。

    当时的情形是这样的:
    我处于教育网内利用 IPV6 + GAgent 免费上网(IPV4 要收费), export http_proxy='127.0.0.1:8087',而 VocVoc 用到 urlopen 的功能完全正常(可以联网)。

    记得要 export http_proxy 这个变量才能起效哦。

    ====
    我不熟悉 Py2 的 http库。。
    不过我也在 urllib 和 urllib2 的官方文档里面都搜到关于代理的一段话,和上面的类似,可以自动利用 http_proxy 这个变量。

    另外, 建议你的 Readme.md 小题目也按照 md 的格式来。
    scola
        2
    scola  
       2013-05-11 21:14:43 +08:00
    lz写这个的需求在哪里呢,我很少要删自己的推,除非误发
    ahxxm
        3
    ahxxm  
    OP
       2013-05-12 07:47:58 +08:00
    @thedevil5032 忘记说明了,第4点是win8测试的,vps本身在墙外…
    恩我去看看markdown style guide……
    ahxxm
        4
    ahxxm  
    OP
       2013-05-12 07:48:59 +08:00
    @scola 看到个网站说能删除xxx天之前的所有推,试了一下无效,就自己写了。。
    ahxxm
        5
    ahxxm  
    OP
       2013-05-12 07:55:04 +08:00
    @thedevil5032 刚拿虚拟机里debian测试,这程序不会调用http_proxy(wget会),api.statues_update()直接timeout了。。
    AstroProfundis
        6
    AstroProfundis  
       2013-05-12 09:52:59 +08:00
    我是来歪楼的...
    我自己抓推做备份...完全没有删推的需求...
    ahxxm
        7
    ahxxm  
    OP
       2013-05-12 10:35:35 +08:00
    @AstroProfundis 蘑菇党你抓谁的推!
    AstroProfundis
        8
    AstroProfundis  
       2013-05-12 10:45:11 +08:00
    @ahxxm 我自己的啊...
    ahxxm
        9
    ahxxm  
    OP
       2013-05-12 11:10:41 +08:00
    @AstroProfundis archive不好用吗....
    AstroProfundis
        10
    AstroProfundis  
       2013-05-12 11:25:51 +08:00
    @ahxxm ThinkUp 不光archive了还能有统计... 然后 TweetNest 出来的直接就是一个网页界面,类似archive出来的那种,但感觉要舒服点...(而且archive每次都要下载全部,好麻烦,自己抓可以增量嘛...
    codesaler
        11
    codesaler  
       2013-05-12 11:58:03 +08:00
    楼主写个爬某个帐号的所有发过的图片的下载地址吧
    ahxxm
        12
    ahxxm  
    OP
       2013-05-14 10:03:12 +08:00
    @codesaler 那么多图床,新手表示有点为难。。。
    codesaler
        13
    codesaler  
       2013-05-14 10:55:36 +08:00
    @ahxxm 我最近想做这种,用笨办法,查找页面上的特定域名,然后发出请求,如果有图片就爬来,不过现在遇到的麻烦是没找到合适的方法模拟js操作,可能用调用api方法遍历每个推是更好的解决方案
    ahxxm
        14
    ahxxm  
    OP
       2013-05-14 12:12:50 +08:00
    @codesaler 不知道为什么你这两个回复配合头像戳到我笑点……
    直接找某个帐号要存档最方便吧,调用api一条条把推文爬下来会不会有点奇怪?
    推文存档的js文件里有media_url用来显示官方图床或者什么其他东西,url短链接和expanded_url还原后链接,(也许还得判定一下是不是需要再还原。。)
    codesaler
        15
    codesaler  
       2013-05-14 13:55:59 +08:00
    @ahxxm 头像的确不错。人家不给存档呢?
    ahxxm
        16
    ahxxm  
    OP
       2013-05-14 16:56:40 +08:00 via Android
    @codesaler 给代码让他帮忙运行一下? 好吧…我暂时没法满足你这个需求… 先记下了>_<
    gzb1985
        17
    gzb1985  
       2013-05-17 17:09:13 +08:00
    还有一个删微博的工具: 卧槽!http://wocao123.sinaapp.com
    piresion
        18
    piresion  
       2013-05-17 17:55:15 +08:00
    @gzb1985 这个感觉不错~名字挺有个性的
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   986 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:49 · PVG 06:49 · LAX 15:49 · JFK 18:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.