惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
Google Online Security Blog
Google Online Security Blog
Engineering at Meta
Engineering at Meta
U
Unit 42
Security Latest
Security Latest
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
D
Docker
T
Tailwind CSS Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
云风的 BLOG
云风的 BLOG
Hugging Face - Blog
Hugging Face - Blog
M
MIT News - Artificial intelligence
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
MongoDB | Blog
MongoDB | Blog
H
Help Net Security
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
S
Security Affairs
T
The Exploit Database - CXSecurity.com
S
SegmentFault 最新的问题
N
News and Events Feed by Topic
The GitHub Blog
The GitHub Blog
Apple Machine Learning Research
Apple Machine Learning Research
S
Securelist
IT之家
IT之家
P
Palo Alto Networks Blog
D
DataBreaches.Net
Help Net Security
Help Net Security
N
Netflix TechBlog - Medium
B
Blog RSS Feed
AWS News Blog
AWS News Blog
Scott Helme
Scott Helme
爱范儿
爱范儿
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
腾讯CDC
I
Intezer
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
Microsoft Security Blog
Microsoft Security Blog
人人都是产品经理
人人都是产品经理
G
GRAHAM CLULEY
N
News | PayPal Newsroom
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
F
Fortinet All Blogs
The Register - Security
The Register - Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
博客园 - 【当耐特】

herrkaefer

"Vibe planning \u003e vibe coding" "Anything to Markdown" "Built anocus: anonymous commenting for static sites" "日记与小说 -- AI 续写小说欣赏" "Any-podcast: from newsletters to a podcast" "Made MicPipe: a simple voice input tool using ChatGPT dictation" "关于 Tools 和 Skills 的一点感想" "Realtime monitoring of ComEd hourly price" "Introducing SwiftEdgeTTS" "Thoughts on the philosophy of building AI-native apps" "jelly鼻屎" "等饭的人" "Use home assistant to motivate my kid to brush teeth" "Migrated Blog to Hugo and Cloudflare Pages" "Easy Aspen monitoring for Chicago parents" "Introducing HabitBuilder: A simple Telegram bot for habit tracking" "鼓捣" "Open folder or file with Sublime Text from Finder toolbar" "Python dev workflow on macOS" "Create new text file from Finder toolbar" "Uno reinvented for 3-year-old kids" "Uno变身儿童数字游戏" "Handle annoying operations of objects in Realm DB" "Move Jekyll blog to Ubuntu VPS" "Introducing Mole" "Note taking without note taking app" "Deploy Python web application on Ubuntu server" "Setup Shadowsocks / VPN on Ubuntu Server" "Linode Notes - Basic Setup" "CLASS Style Adapted for Embedded Systems" "psycopgr Tutorial" "pgRouting Notes" "PostgreSQL Notes" "阿城三王" "这一年,这一把日子" "另一面的发现——读《坟》" "定理" "封面与腰封" "Google book下载" "lulu最新写真出炉" "The Big Bang Theory第三季" "自拍婚纱照1" "日全食" "期待动画片" "《麦兜响当当》动画电影主题曲" "转:饶毅--“杂志拜物教”:何时发Cell Nature Science 论文害你" "转:饶毅--提醒年轻人:何时SCI害你?" "西安" "3d打印机" "Dropbox" "刷牙" "贴几张照片" "6156167" "永久和凤凰" "老板的想法" "春" "原来奥巴马也是个朗读者" "应邀发Freeware List 2.0" "史上最能睡的淘宝老板" "至少出名的效果是达到了" "错怪了msn" "独立游戏节2009" "114" "馒头" "Crayon Physics Deluxe" "2008,2009" "盖章记" "小虎队附身许巍" "怎么给word文档加索引:排序问题" "怎么给word文档加索引Q\u0026amp;A" "怎么给Word文档加索引" "教我如何不疯掉" "二则" "P" "哦!报告" "蓝天" "萧翰" "lm" "故宫印象" "转:美国历任总统像" "time can kill itself" "嗯" "建议,只是建议哦" "奥地利行记3" "奥地利行记2" "奥地利行记1" "叶子" "GayBoy" "天使教你扔frisbie" "门徒因何面容愁?" "手机教堂" "丝竹管弦之盛" "残奥" "争座位" "秋意浅" "总理府" "流觞曲水" "映带左右引以为" "咚咚咚 续" "茂林修竹又有"
"自动转发Twitter到微博"
"herrkaefer" · 2017-11-06 · via herrkaefer

在Twitter上关注了几个图片账号, 比如@HistoryInPix, 经常想把一些有趣的图文转发到微博, 但操作起来却麻烦. 闲来无聊, 就做了个小机器人来自动把感兴趣的账号发的推全部转发到微博的某个账号(@图中看史)里, 这样在微博里就可以关注和转发了. 简单记录一下过程.

Open source: GitHub: twitter2weibo

准备工作

首先, 在Twitter和微博的开发平台上注册成为开发者, 并分别创建应用.

Twitter上很简单, 创建即生效, 直接拿到四个值: consumer_key, consumer_secret, access_token, access_token_secret.

微博上就有点麻烦, 因为需要官方审核. 因此需要做一个简单网页, 放上微博组件, 审核通过后才可以让第三方账号(开发者之外的账号)使用.

在微博开发平台的"基本信息"里, 得到App KeyApp Secret. 在"高级信息"的授权回调页可以填: http://127.0.0.1/callback.

接下来, 可以在iPython里顺序执行下面一次性授权工作, 得到token:




from weibo import Client



REDIRECT_URI = "http://127.0.0.1/callback"



c = Client(API_KEY, API_SECRET, REDIRECT_URI)



c.authorize_url

在浏览器打开授权页, 在地址栏里拷贝得到code.




code = 'xxxxxxxxx'



c.set_code(code)



print(c.token)

得到token后便可以保存到script中以供使用.

然后还需要注册一个微博"接收账号", 用于发布微博.

在VPS上配置Python环境

使用第三方库tweepyweibo, 来分别调用Twitter和微博的API.

脚本

基本流程: 从多个关注的Twitter账号抓取新的推文及图片, 然后发到微博账号.

建立一个appcofig.py私有文件, 存放Twitter和微博应用的key, secret等参数.

使用pickle存储每个Twitter账号最后转发的tweet的时间.

定期执行

在VPS上, 使用Cron来做即可.

添加任务:




10 * * * * python /home/herrkaefer/twitter2weibo/twitter2weibo.py >> /home/herrkaefer/twitter2weibo/log.txt

含义是每小时的10分执行一次, 并log到文件中.

在本次执行时, 应该检测脚本是否已经在执行中, 如果已经在执行则退出. 为了实现这一点, 可借用一个临时文件来判断. 在每次执行前:




pidfile = "/tmp/twitter2weibo.pid"



if os.path.isfile(pidfile):



sys.exit()



file(pidfile, 'w').write(str(os.getpid()))

正常执行后:




os.unlink(pidfile)



sys.exit()

限制

  • 微博每天有user rate limit, 不能太频繁, 但具体限制是多少, 官方文档中语焉不详. 目前设为3分钟发一条, 转发的Twitter账号数量很少, 看起来没问题.

  • 微博API只允许发一张图片, 因此推文含多图的, 只能转发第一张.