Ejemplo n.º 1
0
def home_timeline():
    params = flask.request.args.to_dict()
    params["include_entities"] = 1
    params["model_version"] = 7
    params["tweet_mode"] = "extended"
    data = timeline("Home", functools.partial(flask.g.api.get, "statuses/home_timeline", params=params))
    data["results"] = utils.remove_status_by_id(data["results"], params.get("max_id"))
    data["next_page_url"] = utils.build_next_page_url(data["results"], flask.request.args.to_dict())
    return data
Ejemplo n.º 2
0
def search_tweets():
    params = flask.request.args.to_dict()
    params["q"] = urllib.unquote(params["q"]).encode("utf8")
    params["include_entities"] = 1
    params["model_version"] = 7
    params["tweet_mode"] = "extended"
    data = timeline("Search", functools.partial(flask.g.api.get, "search/tweets", params=params))
    data["results"] = utils.remove_status_by_id(data["results"]["statuses"], params.get("max_id"))
    data["next_page_url"] = utils.build_next_page_url(data["results"], params)
    return data
Ejemplo n.º 3
0
def user_favorites(screen_name):
    params = flask.request.args.to_dict()
    params["include_entities"] = 1
    params["model_version"] = 7
    params["tweet_mode"] = "extended"
    data = timeline(
        "%s Favorites" % screen_name,
        functools.partial(flask.g.api.get, "favorites/list", screen_name=screen_name, params=params),
    )
    data["results"] = utils.remove_status_by_id(data["results"], params.get("max_id"))
    data["next_page_url"] = utils.build_next_page_url(data["results"], flask.request.args.to_dict())
    return data
Ejemplo n.º 4
0
def search_tweets():
    params = flask.request.args.to_dict()
    params["q"] = urllib.unquote(params["q"]).encode("utf8")
    params["include_entities"] = 1
    params["model_version"] = 7
    params["tweet_mode"] = "extended"
    data = timeline(
        "Search",
        functools.partial(flask.g.api.get, "search/tweets", params=params))
    data["results"] = utils.remove_status_by_id(data["results"]["statuses"],
                                                params.get("max_id"))
    data["next_page_url"] = utils.build_next_page_url(data["results"], params)
    return data
Ejemplo n.º 5
0
def home_timeline():
    params = flask.request.args.to_dict()
    params["include_entities"] = 1
    params["model_version"] = 7
    params["tweet_mode"] = "extended"
    data = timeline(
        "Home",
        functools.partial(flask.g.api.get,
                          "statuses/home_timeline",
                          params=params))
    data["results"] = utils.remove_status_by_id(data["results"],
                                                params.get("max_id"))
    data["next_page_url"] = utils.build_next_page_url(
        data["results"], flask.request.args.to_dict())
    return data
Ejemplo n.º 6
0
def notifications_timeline():
    params = flask.request.args.to_dict()
    params["include_entities"] = 1
    params["include_my_retweet"] = 1
    params["include_rts"] = 1
    params["model_version"] = 7
    params["tweet_mode"] = "extended"
    data = timeline(
        "Notifications", functools.partial(flask.g.api.get, "activity/about_me", version="1.1", params=params)
    )
    data["results"] = utils.remove_status_by_id(data["results"], params.get("max_id"))
    data["next_page_url"] = utils.build_next_page_url(
        data["results"], flask.request.args.to_dict(), key_name="max_position"
    )
    return data
Ejemplo n.º 7
0
def user_favorites(screen_name):
    params = flask.request.args.to_dict()
    params["include_entities"] = 1
    params["model_version"] = 7
    params["tweet_mode"] = "extended"
    data = timeline(
        "%s Favorites" % screen_name,
        functools.partial(flask.g.api.get,
                          "favorites/list",
                          screen_name=screen_name,
                          params=params))
    data["results"] = utils.remove_status_by_id(data["results"],
                                                params.get("max_id"))
    data["next_page_url"] = utils.build_next_page_url(
        data["results"], flask.request.args.to_dict())
    return data
Ejemplo n.º 8
0
def notifications_timeline():
    params = flask.request.args.to_dict()
    params["include_entities"] = 1
    params["include_my_retweet"] = 1
    params["include_rts"] = 1
    params["model_version"] = 7
    params["tweet_mode"] = "extended"
    data = timeline(
        "Notifications",
        functools.partial(flask.g.api.get,
                          "activity/about_me",
                          version="1.1",
                          params=params))
    data["results"] = utils.remove_status_by_id(data["results"],
                                                params.get("max_id"))
    data["next_page_url"] = utils.build_next_page_url(
        data["results"], flask.request.args.to_dict(), key_name="max_position")
    return data
Ejemplo n.º 9
0
def user(screen_name):
    data = {
        "title": "User %s" % screen_name,
        "results": [],
    }
    if not flask.request.args:
        try:
            result = flask.g.api.get("users/show", screen_name=screen_name).json()
        except twitter.Error as e:
            flask.flash("Can not show user %s: %s" % (screen_name, str(e)))
            return data
        data["user"] = render.prerender_user_entities(result)
        days_delta = (time.time() - render.prerender_timestamp(result["created_at"])) // 86400
        data["user"]["tweets_per_day"] = "%.4g" % (result["statuses_count"] / days_delta) if days_delta > 0 else 0
        try:
            result = flask.g.api.get("friendships/show", source_screen_name=flask.g.screen_name,
                                     target_screen_name=data["user"]["screen_name"]).json()
        except twitter.Error:
            pass
        else:
            source = result["relationship"]["source"]
            del source["id_str"]
            del source["id"]
            del source["screen_name"]
            data["user"].update(source)
    else:
        data["title"] = "User %s Timeline" % screen_name
    params = flask.request.args.to_dict()
    params["model_version"] = 7
    params["tweet_mode"] = "extended"
    try:
        tweets_result = flask.g.api.get("statuses/user_timeline", screen_name=screen_name, **params).json()
    except twitter.Error as e:
        flask.flash("Can not get timeline: %s" % str(e))
    else:
        data["results"] = utils.remove_status_by_id(tweets_result, flask.request.args.get("max_id"))
    data["next_page_url"] = utils.build_next_page_url(data["results"], flask.request.args.to_dict())
    return data