我正在定义一个将项目推送到消息队列的项目导出器.下面是代码.
from scrapy.contrib.exporter import JsonLinesItemExporter
from scrapy.utils.serialize import ScrapyJSONEncoder
from scrapy import log
from scrapy.conf import settings
from carrot.connection import BrokerConnection, Exchange
from carrot.messaging import Publisher
log.start()
class QueueItemExporter(JsonLinesItemExporter):
def __init__(self, **kwargs):
log.msg("Initialising queue exporter", level=log.DEBUG)
self._configure(kwargs)
host_name = settings.get('BROKER_HOST', 'localhost')
port = settings.get('BROKER_PORT', 5672)
userid = settings.get('BROKER_USERID', "guest")
password = settings.get('BROKER_PASSWORD', "guest")
virtual_host = settings.get('BROKER_VIRTUAL_HOST', "/")
self.encoder = settings.get('MESSAGE_Q_SERIALIZER', ScrapyJSONEncoder)(**kwargs)
log.msg("Connecting to broker", level=log.DEBUG)
self.q_connection = BrokerConnection(hostname=host_name, port=port,
userid=userid, password=password,
virtual_host=virtual_host)
self.exchange = Exchange("scrapers", type="topic")
log.msg("Connected", level=log.DEBUG)
def start_exporting(self): …Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,我正在使用devise和omniauth实现身份验证.我已经找到了登录/退出等,我想知道的是,连接到用户图形api端点的最有效方法是初始化并准备好在我的应用程序中使用.
例如:如果在我想要的个人资料页面上,
profile_image = current_user.fbgraph.get_picture("me")
Run Code Online (Sandbox Code Playgroud)
如何使用最少的API调用完成此操作(我将在整个应用程序中使用类似的调用)
我似乎错过了一些非常简单的事情.我想要做的只是;用作CSV导出器中的分隔符而不是,.
我知道CSV出口通kwargs到CSV作家,但我似乎无法弄清楚如何通过这个分隔符.
我这样叫我的蜘蛛:
scrapy crawl spidername --set FEED_URI=output.csv --set FEED_FORMAT=csv
Run Code Online (Sandbox Code Playgroud) 我有一个定制的500汉德与哨兵一起使用.在我的urls.py文件中,我有:
def handler500(request):
"""
500 error handler which includes ``request`` in the context.
Templates: `500.html`
Context: None
"""
from django.template import Context, loader
from django.http import HttpResponseServerError
t = loader.get_template('500.html') # You need to create a 500.html template.
return HttpResponseServerError(t.render(RequestContext(request)))
Run Code Online (Sandbox Code Playgroud)
在我的500.html模板中:
{% extends "intranet/index.html" %}
{% block main_content %}
<h1>Internal Error!</h1>
<p>You've encountered an error, please try again in some time or file an
error report if the problem persists.
{% if request.sentry.id %}
You may reference this error as …Run Code Online (Sandbox Code Playgroud) 我在这里使用fab脚本.fab deploy创建应用程序后立即抛出错误.错误是:
Fatal error: Low level socket error connecting to host username.webfactional.com: Connection refused (tried 1 time)
Underlying exception:
Connection refused
Run Code Online (Sandbox Code Playgroud)
我已经看到了这个答案,但我的机器上运行了ssh.
我正在使用一个流浪的Geodjango盒子,端口转发对我不起作用.
在盒子上,我跑了:
python manage.py runserver 0.0.0.0:8000
Run Code Online (Sandbox Code Playgroud)
但http://localhost:8000与http://localhost:4567这两个发现在主机上什么都没有.
在Vagrant框中,curl -v 'http://localhost:8000/'给出通常的:
<h2>Congratulations on your first Django-powered page.</h2>
Run Code Online (Sandbox Code Playgroud)
这表明Django运行正常.但是在主机上,尝试curl -v 'http://localhost:8000/'提供以下输出:
curl: (7) Failed connect to localhost:8000; Connection refused
Run Code Online (Sandbox Code Playgroud)
我的Vagrantfile具有以下端口转发设置:
config.vm.forward_port 8000, 4567
Run Code Online (Sandbox Code Playgroud)
禁用Mac的防火墙没有帮助,停止Apache没有任何区别.我试过lsof -i :8000在主机上运行并且没有输出,所以我认为什么都没有使用端口.
谁能提出任何建议?
我使用redis存储某些实体的标签.数据示例:
+-------------+--------------------------------+
| key | value |
+-------------+--------------------------------+
| book:1:tags | [python, ruby, rails] |
+-------------+--------------------------------+
| book:2:tags | [fiction, fantasy] |
+-------------+--------------------------------+
| book:3:tags | [fiction, adventure] |
+-------------+--------------------------------+
Run Code Online (Sandbox Code Playgroud)
如何找到所有带有特定标签的书籍,即所有标有fiction?的书籍?
我很想知道如何在更高级别(即库等)中实现延迟评估.例如,Django ORM或ActiveRecord如何推迟对查询的评估,直到实际使用它为止?
我们正在尝试设置和使用渗透,但我们并没有像预期的那样得到结果.
首先,我注册了几个问题:
curl -XPUT 'localhost:9200/index-234234/.percolator/query1' -d '{
"query" : {
"range" : {
"price" : { "gte": 100 }
}
}
}'
curl -XPUT 'localhost:9200/index-234234/.percolator/query2' -d '{
"query" : {
"range" : {
"price" : { "gte": 200 }
}
}
}'
Run Code Online (Sandbox Code Playgroud)
然后,当我尝试将它与150匹配时,理想情况下只匹配query1,而不是匹配两个查询:
curl -XGET 'localhost:9200/index-234234/message/_percolate' -d '{
"doc" : {
"price" : 150
}
}'
{"took":4,"_shards":{"total":5,"successful":5,"failed":0},"total":2,"matches":[{"_index":"index-234234","_id":"query1"},{"_index":"index-234234","_id":"query2"}]}
Run Code Online (Sandbox Code Playgroud)
关于为什么会发生这种情况的任何指示都将非常感激.
在此页面中有滚动周期函数的官方示例。
使用的功能是什么?(给定 N 滚动周期)
有谁知道这个功能,或者我怎样才能找到它?
我有一个继承自另一个模型的模型(不是抽象)我有一个继承模型的ModelForm,但我不想显示基础模型中的任何字段.除了明确手动将每个字段添加到排除列表之外,实现此目的的最佳方法是什么?
我要在黄瓜上测试的页面上有以下HTML。
<div class='try_options'>
<ul>
<li>
<div>
<img alt="" src="/images/main_page1.jpg" />
<div class='right_section'>
<p>
Feature 1
</p>
<a class='suggest_btn' href='url1'>Try Now</a>
</div>
</div>
</li>
<li>
<div>
<img alt="" src="/images/main_page2.jpg" />
<div class='right_section'>
<p>
Feature 2
</p>
<a class='suggest_btn' href='url2'>Try Now</a>
</div>
</div>
</li>
<li>
<div>
<img alt="" src="/images/main_page3.jpg" />
<div class='right_section'>
<p>
Feature 3
</p>
<a class='suggest_btn' href='url3'>Try Now</a>
</div>
</div>
</li>
<li>
<div>
<img alt="" src="/images/main_page4.jpg" />
<div class='right_section'>
<p>
Feature 4
</p>
<a class='suggest_btn' href='url4'>Try Now</a>
</div>
</div>
</li> …Run Code Online (Sandbox Code Playgroud)