实时数据与烧瓶? [英] Real time data with flask?

查看:155
本文介绍了实时数据与烧瓶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在尝试使用flask和twitter流API来构建一个应用程序。我最终想要做的是根据附加的地理位置数据实时更新地图。什么是最好的选择,我发送实时数据给用户没有页面刷新? Ajax是一个选项吗?我也看了看现在似乎贬值的剑圣。任何帮助指引我在正确的方向将不胜感激。

解决方案

有几件事你可以做。首先是使用ajax,在那里你只需要为REST api设置每个请求的时间间隔。另一种选择是使用websocket。这里是一些文档来实现python的websockets https://ws4py.readthedocs.org/en/latest/ 。使用Ajax将是更容易的解决方案,但websockets是一个更好的。

如果您不熟悉websockets,那么这个想法就是服务器可以向客户端发送消息。所以当有人进入你的网站时,客户端和服务器之间会打开一个连接。在服务器端,当您使用地理位置传输某些数据并且想要在地图上显示数据时,服务器可以使用数据向客户端发送消息。这样,地图上显示的所有内容都是实时的,而且您没有任何其他请求。


Hello I am trying to build an application using flask and the twitter stream API. What I would eventually like to do is update a map in real time with tweets based on their attached geolocation data. What would be the best option for me to send real time data to the user without a page refresh? Is Ajax an option? I also looked into Juggernaut which now seems to be depreciated. Any help steering me in the right direction would be greatly appreciated.

解决方案

There are a couple things you can do. The first is using ajax, where you just set an interval for each request to the REST api. The other option would be to use websockets. Here is some documentation to implement websockets with python https://ws4py.readthedocs.org/en/latest/. Using ajax would be the easier solution, but websockets is a better one.

If you are unfamiliar with websockets, the idea is that a server can send a message to the client. So when someone goes to your website a connection opens between the client and server. On the server side when you stream some data with a geolocation and you want to display it on the map, the server can send a message to the client with the data. That way, everything displayed on the map is in real time and you dont have any more requests than necessary.

这篇关于实时数据与烧瓶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆