- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试向客户端返回 Twitter 元数据流,客户端以通过 tweepy 的“track”过滤的形式输入该元数据流。
我遇到的问题是,即使服务器接收并处理请求,也没有任何内容返回到浏览器。这是我到目前为止的代码:
main.py:
import flask
from flask.views import MethodView
from tweetStreamsRT import StreamerRt
app = flask.Flask(__name__)
app.secret_key = "asecret"
class View(MethodView):
def get(self):
return flask.render_template('index.html')
def post(self):
results = StreamerRt().filter(track = (flask.request.form['event']))
flask.flash(results)
return self.get()
app.add_url_rule('/', view_func = View.as_view('index'), methods=['GET', 'POST'])
app.debug = True
app.run()
连接到 Twitter Streaming API 的类:
import sys
import tweepy
import json
import time
#from textwrap import TextWrapper
import pymongo
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_TOKEN = ''
ACCESS_TOKEN_SECRET = ''
auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN,ACCESS_TOKEN_SECRET)
connection = pymongo.Connection()
db = connection.twitterStream
class Listener(tweepy.StreamListener):
def on_status(self, status):
message = {}
if status.author.lang == 'en':
try:
message = {
'Author': status.author.screen_name,
'Author_id': status.id,
'Time_normal': str(status.created_at),
'geo_enabled': status.author.geo_enabled,
'Geo': status.geo,
'Place' : status.place,
'Coordinates': status.coordinates}
db.tweetStream.insert(message)
except Exception, e:
print >> sys.stderr, 'Encountered Exception:', e
pass
def on_error(self, status_code):
waitPeriod = 60
if status_code == 420:
print >> sys.stderr, 'Encountered a %i Error, will retry in %i minutes' % \
(status_code, waitPeriod/60)
time.sleep(waitPeriod)
waitPeriod *= 2
return waitPeriod
else:
print >> sys.stderr, 'Encountered error with status code:', status_code
return True
def on_timeout(self):
print >> sys.stderr, 'Timeout...'
return True
def StreamerRt():
return tweepy.streaming.Stream(auth, Listener(), timeout=60)
我的 html 文件继承自基本文件并形成 html 文件:
{% extends "base.html" %}
{% import "forms.html" as forms %}
{% block page_header %}
<div class="page-header">
<h1>Welcome</h1>
</div>
{% endblock %}
{% block content %}
<h2>Enter the Event you would like to follow</h2>
<form action="/" method="post">
<input type="text" name="event" />
<input type="submit" value="Submit Query" />
</form>
{% with messages = get_flashed_messages() %}
{% if messages %}
Results:
<pre>
{% for message in messages %}
{{ message }}
{% endfor %}
</pre>
{% endif %}
{% endwith %}
{% endblock %}
似乎无法向客户端返回任何流数据。
如何将某些元数据从 Twitter Streaming API 返回到浏览器,同时将其写入数据库。
谢谢
此外,StreamerRt 函数不会按来自客户端的输入按轨道进行过滤,但似乎会返回整个公共(public)时间线。
最佳答案
我认为Flask-Sijax就是您正在寻找的。 Hookbox是另一种选择,here是关于如何将 hookbox 与 Flask 集成的教程。另一种选择是 gevent here是一篇关于在 Flask 中使用 gevent 的 SO 帖子。我能想到的最后一个是tornado .
关于python - 如何使用 Python/flask 将 Twitter 元数据从服务器流式传输到客户端浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12965401/
最终目标:我想要由 Git 跟踪的文件,但让这些文件对于所有分支都是相同的版本。如果您使用 gitignore 文件,则所有分支的文件都是相同的,但不幸的是不会被跟踪。当我跑 git push或类似的
我想从 PDF 文件中删除元数据。我已经尝试使用“exiftool”、“pdftk”和“qpdf”来删除元数据(建议的方法 - https://gist.github.com/hubgit/60783
AWS EC2 元数据从 EC2 提供了有关其自身的必要信息(废话!) - 是否有任何与 lambda 等效的信息。 我了解与 EC2 不同的 lambda 函数的 Multi-Tenancy 和短期
我正在使用 libavformat(即 C 库)将 MPEG4/H264 编码为 mp4 文件,我想在 MP4 文件中添加一些元数据,例如日期/时间。有人可以告诉我如何做到这一点吗? 谢谢。 最佳答案
有谁知道任何允许从 .jpg 图像中提取 java 元数据的类?或者可能是一些有用的代码? 谢谢! 最佳答案 我维护着一个库,正是这样做的。 https://github.com/drewnoakes
我尝试找出如何从媒体获取元数据有一段时间了,但到目前为止没有任何效果。我有类 Song,其中有 SimpleStringProperties,如标题、艺术家等。我尝试在类构造函数中为它们设置值: pr
我已经多次遇到这个问题,并且从不喜欢所选择的解决方案。假设您在数据库中有一个状态列表(作为一个简单的示例)。在您的代码隐藏中,您希望能够通过 ID 引用状态并通过 Intellisense 获得状态列
我在我的应用程序中使用 google 登录并从 google 获取用户个人资料信息。 我已经测试过,它在我这边工作正常,但苹果拒绝了它。我没有发现任何错误。 苹果拒绝原因:“Verify is you
我正在开发一个基于 MySQL 数据库的 Web 应用程序。我需要收集和分析使用情况和性能统计数据。统计数据将针对非技术人员。 如何实现此功能?您应该将我的问题视为编程问题,但如果您知道合适的工具或扩
我对如何保存表格行的元数据有疑问。 例如,我有一个表,其中包含有关图像 items_images 的数据。编号,整数(20)标题,VARCHAR(255)添加日期,DATETIME... 现在我想添加
我不明白为什么我必须在 list 中使用两个元数据元素才能开始运行我的 Google Maps API v2 项目。这些标签的用途是什么? 最佳答案 元数据是指有关数据的数据。 关于java -
如何获取 SharePoint 文档库中项目的内容类型列或元数据? 此链接提供了我不需要的文件属性 http://msdn.microsoft.com/en-us/library/microsoft.
我很确定这是可能的,只是不确定它的术语是什么以及如何去做。基本上,如果您右键单击任何文件并转到属性,然后转到摘要,您可以向文件添加评论等。 我想知道的是,您将如何从 C# 中有问题地执行此操作。此外,
在我的应用程序中,我正在从 Assets 库中检索 UIImage,该图像具有元数据。然后,该应用程序会调整图像大小并旋转图像,从而创建新图像。新图像没有预期的原始元数据,但如何在上传前将元数据添加回
Java 通过JDBC获得连接以后,得到一个Connection 对象,可以从这个对象获得有关数据库管理系统的各种信息,包括数据库中的各个表,表中的各个列,数据类型,触发器,存储过程等各方面的信息。
想知道是否有人知道扩展或配置 Breeze 以便服务器返回实体元数据中的附加信息的任何方法?我想使用这些附加数据来协助验证。 假设我有一个应用了一些数据注释的实体模型: public class Pe
我正在寻找将 MEF 用于我正在构建的应用程序的插件系统。我希望每个组件在(GUID)上都有一个我希望能够查找的标识符。但是,此 ID 在处理导出部件时也很有用。 有没有一种方法可以让我在导出的部分上
我对不完整的视频有疑问。例如上传失败的视频。如果您使用 ffmpeg -i 检查其元数据您将获得 1 小时的持续时间,但实际上只有 10mb 已上传到服务器,实际持续时间约为 7 分钟。查找这些视频
我在使用 FFmpeg 覆盖视频文件上的元数据时遇到了一些问题,这些文件之前已经添加了元数据(FFmpeg 也添加了以前的元数据)。 所以我使用ffmpeg -i path/to/video file
我有两个项目组想要加入: A B 使用常规连接会给我一个包含 4 个项目的集合: ServerA with Metadata A; ServerB with Metad
我是一名优秀的程序员,十分优秀!