以编程方式对黑客新闻报道进行投票?

发布于 2024-08-30 08:05:17 字数 1297 浏览 1 评论 0原文

我决定编写一个应用程序,例如: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望她远 2024-09-06 08:05:18

Twill 有一种方法列出所有链接,并且您将链接作为对象获取:

login_url = ''
for link in showlinks():
    if link.text == "login":
        login_url = link.url

go(login_url)

因此链接将是类似于:http://news.ycombinator.com/x?fnid=SvdNlGQoqo

Twill has a way to list all the links, and you get the links as an objects:

login_url = ''
for link in showlinks():
    if link.text == "login":
        login_url = link.url

go(login_url)

So link will be something like: http://news.ycombinator.com/x?fnid=SvdNlGQoqo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文