根据主题名称验证主题是否存在 [英] Verify if a topic exists based on topic name

查看:62
本文介绍了根据主题名称验证主题是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据主题名称验证主题是否存在.

I'm trying to verify if a topic exists based on topic name.

你知道这是否可能吗?

例如,我想验证名称为"test"的主题是否已经存在.

For example I want to verify if topic with name "test" already exist.

以下是我正在尝试的操作,但由于主题列表包含topicArns而不是topicNames而无法正常工作...

Below is what I'm trying but doesn't work because topicsList contains topicArns and not topicNames...

topics = sns.get_all_topics()   
topicsList = topics['ListTopicsResponse']['ListTopicsResult'['Topics']

if "test" in topicsList:
    print("true")

推荐答案

这是一种hack,但它应该可以工作:

This is kind of a hack but it should work:

topics = sns.get_all_topics()   
topic_list = topics['ListTopicsResponse']['ListTopicsResult']['Topics']
topic_names = [t['TopicArn'].split(':')[5] for t in topic_list]

if 'test' in topic_names:
   print(True)

这篇关于根据主题名称验证主题是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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