Esempio n. 1
0
def test_get_tips(db_setup):
    tips = get_tips()
    assert len(tips) == 10
    jupyter_tips = get_tips('jupyter')
    assert len(jupyter_tips) == 2
    numpy_tips = get_tips('numpy')
    assert len(numpy_tips) == 2
Esempio n. 2
0
def index(tag=None):
    tag = tag or request.query.get('tag') or None
    pageno = request.query.get('page', 1)
    offset, limit = tw_user_action.pagination.get_page_range(pageno)
    tags = get_hashtags()
    tips = get_tips(tag, offset=offset, limit=limit)
    likes = tw_user_action.get_favorites()
    likes = [like.id for like in likes.items(200)]

    return {
        'search_tag': tag or '',
        'tags': tags,
        'tips': tips,
        'likes': likes,
        'pagination': tw_user_action.pagination.get_html_pagination(pageno),
        'screen': TWITTER_ACCOUNT
    }
Esempio n. 3
0
    def call_graph(self, **kargs):
        """
        creates graph from twitter data where labels are links 
        https://github.com/plotly/plotlyjs-flask-example
        """
        start, end, interval = kargs['start'], kargs['end'], kargs['interval']
        patt = re.compile(r'\<|\>|&nbsp;|&gt;|&lt;|\"|\'')
        url_pre = '<a href="https://twitter.com/' + TWITTER_ACCOUNT + '/status/{}" >{}</a>'
        fav, links, info = [], [], []

        if config_pagination:
            tweets = get_tips(
                tag=None, offset=kargs.get('offset'),
                limit=kargs.get('limit'))  #self.user.get_tweets()
        else:
            tweets = self.user.get_tweets().items(300)

        for i, tw in enumerate(tweets, 1):
            if (start <= i <= end):
                fav.append(tw.favorite_count if hasattr(tw, 'favorite_count'
                                                        ) else tw.likes)
                tdate = tw.created_at if hasattr(tw,
                                                 'created_at') else tw.created
                dt = tdate.strftime('%-d%b%-Y %-I.%-M%p') if isinstance(
                    tdate, datetime.datetime) else i
                tid = tw.tweetid if hasattr(tw, 'tweetid') else tw.id
                links.append(url_pre.format(tid, dt))
                info.append(patt.sub('', tw.text[0:40]))
                start = start + 1
                if start > end:
                    if kargs.get('contineous') and not config_pagination:
                        end += interval
                        yield Graph.prepare_gdata(x=links,
                                                  y=fav,
                                                  mode='marker',
                                                  text=info,
                                                  type='bar')
                        fav, links, info = [], [], []
                    else:
                        yield Graph.prepare_gdata(x=links,
                                                  y=fav,
                                                  mode='marker',
                                                  text=info,
                                                  type='bar')
                        break
Esempio n. 4
0
 def import_hashtags(self):
     tips = get_tips()
     hashtags_cnt = self.get_hashtag_counter(tips)
     add_hashtags(hashtags_cnt)
Esempio n. 5
0
def get_tips():
    return tips.get_tips(cache)
Esempio n. 6
0
def index(tag=None):
    tag = tag or request.query.get('tag') or None
    tags = get_hashtags()
    tips = get_tips(tag)

    return {'search_tag': tag or '', 'tags': tags, 'tips': tips}
Esempio n. 7
0
def test_add_tips(db_setup):
    tweets = list(_gen_tweets())[:2]
    add_tips(tweets)
    tips = get_tips()
    assert len(tips) == 12