當前位置: 首頁>>代碼示例>>Python>>正文


Python Channel.create方法代碼示例

本文整理匯總了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)
開發者ID:Bevinsky,項目名稱:packlist-assembler,代碼行數:17,代碼來源:assembler.py

示例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
開發者ID:gabeos,項目名稱:slackotron,代碼行數:48,代碼來源:slackotron.py


注:本文中的models.Channel.create方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。