本文整理匯總了Python中models.Channel.create方法的典型用法代碼示例。如果您正苦於以下問題:Python Channel.create方法的具體用法?Python Channel.create怎麽用?Python Channel.create使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類models.Channel
的用法示例。
在下文中一共展示了Channel.create方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_bot
# 需要導入模塊: from models import Channel [as 別名]
# 或者: from models.Channel import create [as 別名]
def add_bot(self, channel, name):
channel = channel.lower()
name = name.lower()
try:
Bot.get(Bot.name == name)
except peewee.DoesNotExist:
pass # this seems really unpythonic somehow
else:
raise KeyError('Bot already exists')
try:
chan_o = Channel.get(Channel.name == channel)
except peewee.DoesNotExist:
chan_o = Channel.create(name=channel)
Bot.create(name=name,
channel=chan_o)
示例2: _initialize_channels_and_users
# 需要導入模塊: from models import Channel [as 別名]
# 或者: from models.Channel import create [as 別名]
def _initialize_channels_and_users(self):
self.info('Loading channels and users...')
channel_id_to_name_map, channel_name_to_id_map = \
self.slack.channel_id_name_maps()
with self.database_manager.transaction():
for k, v in channel_id_to_name_map.items():
is_direct = True if k.startswith('D0') else False
try:
channel = Channel.get(
Channel.slack_id == k
)
channel.slack_name = v
channel.is_direct = is_direct
channel.save()
except Channel.DoesNotExist:
channel = Channel.create(
slack_name=v,
slack_id=k,
is_direct=is_direct
)
except Exception as e:
self.error(e)
channel_members = self.slack.channel_members(channel.slack_name)
for channel_member in channel_members:
is_slackbot = True if channel_member[1] == 'USLACKBOT' else False
try:
user = User.get(
User.slack_name == channel_member[1],
User.slack_id == channel_member[0],
User.is_slackbot == is_slackbot
)
except User.DoesNotExist:
user = User.create(
slack_name=channel_member[1],
slack_id=channel_member[0],
is_slackbot=is_slackbot
)
except Exception as e:
self.error(e)
try:
ChannelUserRelationship.create(
channel=channel,
user=user
)
except:
pass