twitter.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:TwitterCompetitionBot 作者: BenAllenUK 项目源码 文件源码
def MaximumHitFrequency(self):
        '''Determines the minimum number of seconds that a program must wait
        before hitting the server again without exceeding the rate_limit
        imposed for the currently authenticated user.

        Returns:
          The minimum second interval that a program must use so as to not
          exceed the rate_limit imposed for the user.
        '''
        rate_status = self.GetRateLimitStatus()
        reset_time  = rate_status.get('reset_time', None)
        limit       = rate_status.get('remaining_hits', None)

        if reset_time:
            # put the reset time into a datetime object
            reset = datetime.datetime(*rfc822.parsedate(reset_time)[:7])

            # find the difference in time between now and the reset time + 1 hour
            delta = reset + datetime.timedelta(hours=1) - datetime.datetime.utcnow()

            if not limit:
                return int(delta.seconds)

            # determine the minimum number of seconds allowed as a regular interval
            max_frequency = int(delta.seconds / limit) + 1

            # return the number of seconds
            return max_frequency

        return 60
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号