以编程方式对黑客新闻报道进行投票?
我决定编写一个应用程序,例如: http://michaelgrinich.com/hackernews/ 但对于 Android 设备,我的想法是使用 Web 应用程序后端(因为我更喜欢使用 Python 和 Web 进行编码,而不是完全使用 Java 进行 Android 设备编码)。
我现在实现的是这样的:
$ curl -i http://localhost:8080/stories.json?page=1\&stories=1
HTTP/1.0 200 OK
Date: Sun, 25 Apr 2010 07:59:37 GMT
Server: WSGIServer/0.1 Python/2.6.5
Content-Length: 296
Content-Type: application/json
[{"title": "Don\u2019t talk to aliens, warns Stephen Hawking", "url": "http://www.timesonline.co.uk/tol/news/science/space/article7107207.ece?", "unix_time": 1272175177, "comments": 15, "score": 38, "user": "chaostheory", "position": 1, "human_time": "Sun Apr 25 01:59:37 2010", "id": "1292241"}]
下一步(我认为也是最后一步)是投票,我的设计是做这样的事情:
$ curl -i http://localhost:8080/stories/1 -d "vote=up" -u username:password
将投票赞成和:
$ curl -i http://localhost:8080/stories/1 -d "vote=down" -u username:password
投票反对。
我不知道该怎么做...我打算使用 Twill 但登录链接是总是不同的,例如:
http://news.ycombinator.com/x?fnid=7u89ccHKln
稍后 Android 应用程序将使用此 API。
有以编程方式浏览黑客新闻的经验吗?
I decided to write an app like: http://michaelgrinich.com/hackernews/ but for Android devices, my idea will use a web application backend (because I rather code in Python and for the web than completely in Java for Android devices).
What I have right now implemented is something like this:
$ curl -i http://localhost:8080/stories.json?page=1\&stories=1
HTTP/1.0 200 OK
Date: Sun, 25 Apr 2010 07:59:37 GMT
Server: WSGIServer/0.1 Python/2.6.5
Content-Length: 296
Content-Type: application/json
[{"title": "Don\u2019t talk to aliens, warns Stephen Hawking", "url": "http://www.timesonline.co.uk/tol/news/science/space/article7107207.ece?", "unix_time": 1272175177, "comments": 15, "score": 38, "user": "chaostheory", "position": 1, "human_time": "Sun Apr 25 01:59:37 2010", "id": "1292241"}]
The next step (and final I think) is voting, my design is doing something like this:
$ curl -i http://localhost:8080/stories/1 -d "vote=up" -u username:password
Will vote up and:
$ curl -i http://localhost:8080/stories/1 -d "vote=down" -u username:password
Vote down.
I have no idea how to do it though... I was planning to use Twill but the login link is always different, e.g.:
http://news.ycombinator.com/x?fnid=7u89ccHKln
Later the Android app will consume this API.
Any experience with programmatically browsing Hacker News?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Twill 有一种方法列出所有链接,并且您将链接作为对象获取:
因此链接将是类似于:http://news.ycombinator.com/x?fnid=SvdNlGQoqo
Twill has a way to list all the links, and you get the links as an objects:
So link will be something like:
http://news.ycombinator.com/x?fnid=SvdNlGQoqo