当前位置: 首页>>代码示例>>Python>>正文


Python Post.save_post方法代码示例

本文整理汇总了Python中model.Post.save_post方法的典型用法代码示例。如果您正苦于以下问题:Python Post.save_post方法的具体用法?Python Post.save_post怎么用?Python Post.save_post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.Post的用法示例。


在下文中一共展示了Post.save_post方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: receive

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import save_post [as 别名]
    def receive(self, mail_message):
        try:
            email = mail_message.to.split('@')
        except:
            email = None
        email_prefix = email[0].split('.')
        screen_name_temp = email_prefix[0].split('<')
        try:
            screen_name = screen_name_temp[1]
        except:
            screen_name = screen_name_temp[0]
            
        email_key = email_prefix[1]
        email_user = User.find_by_screen_name(screen_name.lower());
        try:
            if(email_key == email_user.email_key):
                # Set Up Twitter Client
                callback_url = "%s/verify" % self.request.host_url
                client = oauth.TwitterClient(MainHandler.application_key, MainHandler.application_secret, callback_url)
                #Get Post
                plaintext_bodies = mail_message.bodies('text/plain')
                for content_type, body in plaintext_bodies:
                        decoded_text = body.decode()
                        content = decoded_text
            
                try:
                    subject = mail_message.subject + "\n\r"
                except:
                    subject = ''

                if content is not None:
                    body = functions.strip_tags(content)
                else:
                    body = ''

                #Save Post
                post_info = {}
                post_info['content'] = subject + body
                post_key = Post.save_post(post_info)

                #Save Tweetc
                user = User.get_by_key_name(str(email_user.twitter_id))
                tweetc_info = {}
                tweetc_info['tweet_id'] = None
                tweetc_info['tweet'] = None
                tweetc_info['user'] = user.key()
                tweetc_info['post'] = post_key
                tweetc_info['client'] = 'email'
                tweetc_key = Tweetc.save_tweetc(tweetc_info)

                #Send Tweet
                tweetc = Tweetc.get(tweetc_key)
                tweet = functions.word_wrap(content,108,prefix ="||")
                tweet = tweet.split("||")
                
                
                tweetc_code = tweetc.code()
                del tweet[0]
                if len(tweet) == 1:
                    i = 1
                elif len(tweet) == 2:
                    i = 2
                else:
                    i = 3
                count = 0
                tweet_list = []
                while (count < i):
                   last = i - 1
                   if count == last:
                       tweetout = tweet[count] + ' ' + str(count + 1) + '/' + str(i)
                       if len(tweet) > 3:
                           tweetout += '...'
                       tweetout += ' http://tweetc.com/' + tweetc_code
                   else:
                       tweetout = tweet[count] + ' ' + str(count + 1) + '/' + str(i)
                   self.response.out.write(tweetout)
                   tweet_list.append(tweetout)
                   count = count + 1
                first_tweet = tweet_list[0] + ' http://tweetc.com/' + tweetc_code
                tweet_list.reverse()
                count = 0
                while (count < i):
                   self.response.out.write(tweet_list[count] + '<br>')
                   additional_params={"status":tweet_list[count]}
                   url = "http://twitter.com/statuses/update.json"
                   result = client.make_request(url=url, token=user.token,secret=user.secret, additional_params=additional_params, method=urlfetch.POST)
                   rsp = json.loads(result.content)
                   if count == 0:
                       status_id = rsp['id']
                   count = count + 1

                #Update Tweetc with Tweet ID
                tweetc = Tweetc.get(tweetc_key)
                tweetc.tweet_id = status_id
                tweetc.tweet = first_tweet
                tweetc.put()
        except:
            logging.info(screen_name)
            logging.info(email_key)
            logging.info("Sending Email Error")
开发者ID:seedprod,项目名称:tweetc,代码行数:102,代码来源:main-sample.py

示例2: post

# 需要导入模块: from model import Post [as 别名]
# 或者: from model.Post import save_post [as 别名]
  def post(self, action):
    #Start Session 
    self.session = sessions.Session()
    if (action == "settings"):
        key =self.request.get('email_key')
        if(len(key) is 0):
            return self.redirect('/settings' )

        user_info = {}
        user_info['id'] = str(self.session["twitter_id"])
        user_info['email_key'] = key
        User.update_settings(user_info)
        return self.redirect('/settings' + '?p=1' )
        
    if (action == "post"):
        # Set Up Twitter Client
        callback_url = "%s/verify" % self.request.host_url
        client = oauth.TwitterClient(MainHandler.application_key, MainHandler.application_secret, callback_url)
        #Get Post
        content = self.request.get('content')
        contet = functions.strip_tags(content)
        #Save Post
        post_info = {}
        post_info['content'] = content
        post_key = Post.save_post(post_info)
    
        #Save Tweetc
        user = User.get_by_key_name(str(self.session["twitter_id"]))
        tweetc_info = {}
        tweetc_info['tweet_id'] = None
        tweetc_info['tweet'] = None
        tweetc_info['user'] = user.key()
        tweetc_info['post'] = post_key
        tweetc_info['client'] = 'web'
        tweetc_key = Tweetc.save_tweetc(tweetc_info)

        #Send Tweet
        tweetc = Tweetc.get(tweetc_key)
        tweet = functions.word_wrap(content,108,prefix ="||")
        tweet = tweet.split("||")
 
        tweetc_code = tweetc.code()
        del tweet[0]
        if len(tweet) == 1:
            i = 1
        elif len(tweet) == 2:
            i = 2
        else:
            i = 3
        count = 0
        tweet_list = []
        while (count < i):
           last = i - 1
           if count == last:
               tweetout = tweet[count] + ' ' + str(count + 1) + '/' + str(i)
               if len(tweet) > 3:
                   tweetout += '...'
               tweetout += ' http://tweetc.com/' + tweetc_code
           else:
               tweetout = tweet[count] + ' ' + str(count + 1) + '/' + str(i)
           self.response.out.write(tweetout)
           tweet_list.append(tweetout)
           count = count + 1
        first_tweet = tweet_list[0] + ' http://tweetc.com/' + tweetc_code
        tweet_list.reverse()
        count = 0
        while (count < i):
           self.response.out.write(tweet_list[count] + '<br>')
           additional_params={"status":tweet_list[count]}
           url = "http://twitter.com/statuses/update.json"
           result = client.make_request(url=url, token=user.token,secret=user.secret, additional_params=additional_params, method=urlfetch.POST)
           rsp = json.loads(result.content)
           if count == 0:
               status_id = rsp['id']
           count = count + 1

    
        #Update Tweetc with Tweet ID
        tweetc = Tweetc.get(tweetc_key)
        tweetc.tweet_id = status_id
        tweetc.tweet = first_tweet
        tweetc.put()
        
        return self.redirect('/user/' + user.screen_name + '?p=1' )
开发者ID:seedprod,项目名称:tweetc,代码行数:86,代码来源:main-sample.py


注:本文中的model.Post.save_post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。