channels.join是不允许用于机器人的用户.我希望我的RTM使用机器人能够收听机器人集成页面中列出的其他渠道.
我没有看到在bot集成页面中更改频道的方法:

这只是机器人的限制还是我错过了一些基本的东西?
我是一个业余爱好者(而且相当新的)程序员,他在python中编写了几个有用的(对我来说)脚本来处理各种系统自动化任务,这些任务涉及在其他各种活动中复制,重命名和下载文件.
我想创建一个从我的系统中提供的网页,它只会提供一些按钮,这些按钮可以让我远程启动这些脚本.
问题是我不知道从哪里开始调查如何做到这一点.假设我有一个名为的脚本:
file_arranger.py
如何让网页执行该脚本需要做什么?这不是为了公共消费,所以任何轻量级都会很棒.对于奖励积分,我需要考虑为Web用户提供此类脚本的输出?
编辑:第一个答案让我意识到我忘了包含这是一个Win2k3系统.
以下代码与TypeError: 'Mock' object is not iterablein 失败,ImBeingTested.i_call_other_coroutines因为我已被ImGoingToBeMockedMock对象替换.
如何模仿协同程序?
class ImGoingToBeMocked:
@asyncio.coroutine
def yeah_im_not_going_to_run(self):
yield from asyncio.sleep(1)
return "sup"
class ImBeingTested:
def __init__(self, hidude):
self.hidude = hidude
@asyncio.coroutine
def i_call_other_coroutines(self):
return (yield from self.hidude.yeah_im_not_going_to_run())
class TestImBeingTested(unittest.TestCase):
def test_i_call_other_coroutines(self):
mocked = Mock(ImGoingToBeMocked)
ibt = ImBeingTested(mocked)
ret = asyncio.get_event_loop().run_until_complete(ibt.i_call_other_coroutines())
Run Code Online (Sandbox Code Playgroud) 我正在编写一个我希望最终用户可以选择使用的库,就像它的方法和函数不是协同程序一样.
例如,给定此功能:
@asyncio.coroutine
def blah_getter():
return (yield from http_client.get('http://blahblahblah'))
Run Code Online (Sandbox Code Playgroud)
不关心在自己的代码中使用任何异步功能的最终用户仍然需要导入asyncio并运行:
>>> response = asyncio.get_event_loop().run_until_complete(blah_getter())
Run Code Online (Sandbox Code Playgroud)
如果可以的话,这将是很酷的,blah_getter确定我是否被称为协程,并做出相应的反应.
所以类似于:
@asyncio.coroutine
def blah_getter():
if magically_determine_if_being_yielded_from():
return (yield from http_client.get('http://blahblahblah'))
else:
el = asyncio.get_event_loop()
return el.run_until_complete(http_client.get('http://blahblahblah'))
Run Code Online (Sandbox Code Playgroud) 我有这个表(由Django生成):
CREATE TABLE feeds_person (
id serial PRIMARY KEY,
created timestamp with time zone NOT NULL,
modified timestamp with time zone NOT NULL,
name character varying(4000) NOT NULL,
url character varying(1000) NOT NULL,
email character varying(254) NOT NULL,
CONSTRAINT feeds_person_name_ad8c7469_uniq UNIQUE (name, url, email)
);
Run Code Online (Sandbox Code Playgroud)
我想批量插入大量使用数据INSERT与ON CONFLICT条款.
皱纹是我需要得到所有行的id背面,无论它们是否已经存在.
在其他情况下,我会做类似的事情:
INSERT INTO feeds_person (created, modified, name, url, email)
VALUES blah blah blah
ON CONFLICT (name, url, email) DO UPDATE SET url = feeds_person.url …Run Code Online (Sandbox Code Playgroud) 好像当我有一个继承自gevent.Greenlet的抽象基类(它继承自C扩展模块greenlet:https://github.com/python-greenlet/greenlet)时,实现它的类不会引发任何关于未实现方法的abc错误.
class ActorBase(gevent.Greenlet):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def foo(self):
print "foo"
class ActorBaseTest(ActorBase):
def bar(self):
print "bar"
abt = ActorBaseTest() # no errors!
Run Code Online (Sandbox Code Playgroud)
如果我从object它继承失败按预期方式:
class ActorBase(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def foo(self):
print "foo"
class ActorBaseTest(ActorBase):
def bar(self):
print "bar"
>>> abt = ActorBaseTest()
Traceback (most recent call last):
File "/home/dw/.virtualenvs/prj/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 2827, in run_code
exec code_obj in self.user_global_ns, self.user_ns
File "<ipython-input-6-d67a142e7297>", line 1, in <module>
abt = ActorBaseTest()
TypeError: Can't instantiate abstract class …Run Code Online (Sandbox Code Playgroud) 假设我有一个这样的函数:
def a_function(data: Tuple[Tuple[str, ...], ...]) -> Mapping[Tuple[str, ...], int]:
pass
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以通过类型注释来指示该类型与通过参数传入的类型Tuple[str, ...]相同?Tuple[str, ...]data
换句话说,传入的元组将包含同质元组的同质列表,所有这些元组都可能看起来像('fred', 'smith'), ('ananya', 'cooper'),并且返回的字典将看起来像{('fred', 'smith'): 7, ('ananya', 'cooper'): 13}。
鉴于这些模型:
class Listing(models.Model):
features = models.ManyToManyField('Feature', related_name='listing_details')
comments = models.TextField()
class Feature(models.Model):
feature = models.CharField(max_length=100, unique=True)
Run Code Online (Sandbox Code Playgroud)
如何Listing使用评论或相关Features之一中的文本对s 进行全文搜索?
我试过这个:
In[28]: Listing.objects.annotate(search=SearchVector('comments', 'features__feature')).filter(search='something').count()
Out[28]:
1215
Run Code Online (Sandbox Code Playgroud)
所以,我知道并非所有这些记录都包含 text something。
但是,这个数字是“正确的”,因为常规的非全文查询会出现相同的数字:
In[33]: Listing.objects.filter(Q(comments__icontains='something') | Q(features__feature__icontains='something')).count()
Out[33]:
1215
Run Code Online (Sandbox Code Playgroud)
我可以坐下来只Listing包含文本对象something在comments外地或在features__feature像这样:
In[34]: Listing.objects.filter(Q(comments__icontains='something') | Q(features__feature__icontains='something')).distinct().count()
Out[34]:
25
Run Code Online (Sandbox Code Playgroud)
真正的问题归结为如何通过全文搜索取回相同的 25 条记录?
class JsonHavingModel(models.Model):
the_field = JSONField(unique=True)
Run Code Online (Sandbox Code Playgroud)
这有点像:
CREATE UNIQUE INDEX app_jsonhavingmodel_the_field_c1f3c983_uniq ON app_jsonhavingmodel (the_field);
Run Code Online (Sandbox Code Playgroud)
但这究竟意味着什么呢?它只检查键吗?只是价值观?只是文字JSON文本?是检查整个对象层次结构吗?这是一个愚蠢的问题吗?什么是生命的意义?
给出一个像这样的字符串列表:
a_list_of_keys = ['a key', 'heres another', 'oh hey a key']
Run Code Online (Sandbox Code Playgroud)
什么是从dict中检索嵌套系列键的方法
the_value_i_want = some_dict['a key']['heres another']['oh hey a key']
Run Code Online (Sandbox Code Playgroud) python ×5
django ×3
postgresql ×3
python-3.x ×2
abc ×1
cgi ×1
dictionary ×1
gevent ×1
greenlets ×1
inheritance ×1
list ×1
mocking ×1
python-2.7 ×1
python-3.5 ×1
slack-api ×1
sql ×1
types ×1
unit-testing ×1
upsert ×1
web-services ×1
windows ×1