I need to poll a web service, in this case twitter's API, and I'm wondering what the conventional wisdom is on this topic. I'm not sure whether this is important, but I've always found feedback useful in the past.

我需要轮询一个Web服务,在这个例子中是twitter的API,我想知道这个主题的传统智慧是什么。我不确定这是否重要,但我总是发现过去有用的反馈。

A couple scenarios I've come up with:

我想出了几个场景:

  1. The querying process starts every X seconds, eg a cron job runs a python script

    查询过程每X秒开始一次,例如cron作业运行python脚本

  2. A process continually loops and queries at each iteration, eg ... well, here is where I enter unfamiliar territory. Do I just run a python script that doesn't end?

    一个过程在每次迭代时不断循环和查询,例如......好吧,这里是我进入不熟悉领域的地方。我只是运行一个不会结束的python脚本吗?

Thanks for your advice.

谢谢你的建议。

ps - regarding the particulars of twitter: I know that it sends emails for following and direct messages, but sometimes one might want the flexibility of parsing @replies. In those cases, I believe polling is as good as it gets.

ps - 关于twitter的详细信息:我知道它会发送关于跟踪和直接消息的电子邮件,但有时可能需要解析@replies的灵活性。在这些情况下,我相信民意调查一如既往。

pps - twitter limits bots to 100 requests per 60 minutes. I don't know if this also limits web scraping or rss feed reading. Anyone know how easy or hard it is to be whitelisted?

pps - twitter将机器人限制为每60分钟100次请求。我不知道这是否也限制了网页抓取或RSS阅读量。任何人都知道被列入白名单有多容易或多难?

Thanks again.

2 个解决方案

#1


"Do I just run a python script that doesn't end?"

“我只是运行一个不会结束的python脚本吗?”

How is this unfamiliar territory?

这个陌生的领域怎么样?

import time
polling_interval = 36.0 # (100 requests in 3600 seconds)
running= True
while running:
    start= time.clock()
    poll_twitter()
    anything_else_that_seems_important()
    work_duration = time.clock() - start
    time.sleep( polling_interval - work_duration )

It's just a loop.

这只是一个循环。

更多相关文章

  1. Python脚本如何获取当前环节和用户等信息
  2. python mysql 导出到mongodb脚本
  3. 脚本结束后如何运行进程并退出?
  4. 如何获得正在运行的Python脚本的路径?(复制)
  5. Shell脚本更改带变量的目录
  6. Linux(Debian)设置开机自启动脚本
  7. 《Linux命令行与shell脚本》笔记--第5章:使用Linux环境变量
  8. linux shell脚本编程笔记(四): 获取字符串长度的七种方法
  9. 查看Linux服务器网卡流量小脚本shell和Python各一例

随机推荐

  1. 《Android/OPhone 开发完全讲义》目录
  2. Android 面试题总结之Android 基础(三)
  3. Android 并发之CountDownLatch、CyclicBa
  4. Android 自定义RadioButton样式 RadioGro
  5. 搭建 Android 2.2 开发环境
  6. Android如何让TextView子元素随着父元素
  7. android 开发技巧(9)--为文本添加发亮的
  8. Android - OpenCv - 解决预览图像自动旋
  9. Android 源码结构
  10. Android矢量图形-Vector