def create_status(**kwargs): defaults = { 'id': 1, 'created_at': now(), 'user': '******', 'text': 'Status created at %s' % now, } defaults.update(**kwargs) return Status(**defaults)
def create_status(): sleep(0.02) now = datetime.now() defaults = { 'id': random.randint(0, 999), 'created_at': now, 'user': '******', 'text': 'Status created at %s' % now, } defaults.update(**kwargs) return Status(**defaults)
def _to_status(status, **kwargs): """ Convert a `tweepy.Status` to a `turses.models.Status`. """ if hasattr(status, 'full_text'): text = status.full_text else: text = status.text defaults = { 'id': status.id, 'created_at': status.created_at, 'user': None, 'text': text, 'is_reply': False, 'is_retweet': False, 'is_favorite': False, 'in_reply_to_user': '', 'in_reply_to_status_id': None, 'retweeted_status': None, 'retweet_count': 0, 'author': '', 'entities': getattr(status, 'entities', None), } # When fetching an individual user her last status is included and # does not include a `user` attribute if getattr(status, 'user', None): defaults['user'] = status.user.screen_name if hasattr(status, 'retweeted_status'): defaults['is_retweet'] = True defaults['retweeted_status'] = _to_status(status.retweeted_status) defaults['retweet_count'] = status.retweet_count # the `retweeted_status` could not have a `user` attribute # (e.g. when fetching a user and her last status is a retweet) if hasattr(status.retweeted_status, 'user'): defaults['author'] = status.retweeted_status.user.screen_name if getattr(status, 'in_reply_to_screen_name', False): defaults['is_reply'] = True defaults['in_reply_to_user'] = status.in_reply_to_screen_name if getattr(status, 'in_reply_to_status_id', False): defaults['in_reply_to_status_id'] = status.in_reply_to_status_id if hasattr(status, 'favorited'): defaults['is_favorite'] = status.favorited defaults.update(**kwargs) return Status(**defaults)
def _to_status_from_search(status, **kwargs): """ Convert a `tweepy.SearchResult` to a `turses.models.Status`. """ defaults = { 'id': status.id, 'created_at': status.created_at, 'user': status.from_user, 'text': status.text, 'entities': getattr(status, 'entities', None), } defaults.update(**kwargs) return Status(**defaults)