It's May, but it's a story about releasing a web service that visualizes Twitter's positioned tweets. I want to get rid of this sexual root that burns out when I can make what I want to make. It is being played with acclaim.
It's made from a bottle, but it's extremely simple. After all, the duplication remains the same, and the time is not in Japan time. This is a good example of burning out the details as they are.
By the way, for API, of course, use GET search / tweets. Attempts to optionally collect nearby data with the geocode option. If you search nationwide, the top 100 keywords will be searched in the search, so you may not see ranked tweets in the search results. In that case, there is no choice but to display an error page where nothing is displayed.
There may be other good ways, but I couldn't think of that much.
Process by pulling location information from the browser. Then, if you have the option to look for a neighborhood, the distance
geocoding = send_geo + "," + near
Combine with and pass.
@route("/show", method="GET")
def send_geos():
send_geo = request.query.send_geo
search_words = request.query.search_words
near = request.query.near
geocoding = send_geo + "," + near
if search_words:
C_KEY = "****************"
C_SECRET = "****************"
A_KEY = "****************"
A_SECRET = "****************"
url = "https://api.twitter.com/1.1/search/tweets.json?"
if near:
params = {
"q": (search_words, "utf-8"),
"lang": "ja",
"geocode": (geocoding),
"result_type": "mixed",
"count": "100"
}
tw = OAuth1Session(C_KEY,C_SECRET,A_KEY,A_SECRET)
req = tw.get(url, params = params)
tweets = json.loads(req.text)
dic = tweets
else:
params = {
"q": (search_words, "utf-8"),
"lang": "ja",
"result_type": "mixed",
"count": "100"
}
tw = OAuth1Session(C_KEY,C_SECRET,A_KEY,A_SECRET)
req = tw.get(url, params = params)
tweets = json.loads(req.text)
dic = tweets
If there is no positioned tweet, a problem will occur, so try to escape there. If it is not positioned, use except to perform another process.
if req.status_code == 200:
for tweet in tweets["statuses"]:
created_at = YmdHMS(tweet["created_at"])
User = (tweet["user"]["screen_name"].encode("utf-8"))
U_Name = (tweet["user"]["name"].encode("utf-8"))
U_img = (tweet["user"]["profile_image_url"])
Text = (tweet["text"].encode("utf-8"))
if "http" in "Text":
Text = Text.split("http", 1)[0]
Text = Text.split("@")[0]
Text = Text.split("RT")[0]
try:
Place = (tweet["place"]["bounding_box"]["coordinates"])
flat_list = []
for e in Place:
flat_list.extend(e)
flat_list2 = []
for b in flat_list:
flat_list2.extend(b)
flat_list3 = []
for c in flat_list:
flat_list3.extend(c)
geolng = flat_list3[0]
geolat = flat_list3[1]
Geocode is (tweet ["place"] ["bounding_box"] ["coordinates"]) I'm going to get it, but if I do this, the nesting is terrible, so I'm canceling the nesting.
This is the basic Python in-script processing. The rest is written directly in the tpl file.
The process of writing Python in tpl as follows. With this, all tweets are displayed properly.
Tweet data is pulled from what is stored in the database. For example, saving the data as plain text.
%for line in f:
% line = line.rstrip()
% l = line.split(",")
% User = l[0]
% U_Name = l[1]
% U_img = l[2]
% Text = l[3]
% created_at = l[-3]
%geolng = l[-1]
%geolat = l[-2]
<li class="twlist">
<font size="2" color="#d8d8d8">{{created_at}}・{{geolat}},{{geolng}}</font><br>
<span class="fleft"><a href="https://twitter.com/{{User}}" target="_blank"><img src="{{U_img}}"></a></span>
<b>{{U_Name}}</b> <font size="2"><a href="https://twitter.com/{{User}}" target="_blank">@{{User}}</a></font><br>{{Text}}<br><hr class="clear">
</li>
%end
<ul>
When writing to tpl, it can be processed even if the indent is ignored. If you export it as it is, the order will be out of order, so it will be formatted with Jquery.
<script type="text/javascript">
$(function () {
$('ul').html(
$('li').sort(function(a, b) {
if ($(a).text() < $(b).text()) {
return 1;
} else {
return -1;
}
})
);
});
</script>
The same is true for plotting on a map, and Python is written in Javascript for Google map.
%for line in f:
% line = line.rstrip()
% l = line.split(",")
% User = l[0]
% U_Name = l[1]
% U_img = l[2]
% Text = l[3]
% created_at = l[-3]
%geolng = l[-1]
%geolat = l[-2]
['<a href=https://twitter.com/{{User}} target="_blank"><img src={{U_img}}></a><br>{{U_Name}}:{{User}}<br>{{created_at}}<br><marquee>{{Text}}</marquee>', {{geolat}}, {{geolng}}],
%end
['You', {{default_tag}}]
{{User}} Something is a variable that was returned template in bottle. A single Python script processes about 200 lines.
So, when I tried running it on the Web, it looked like this.
http://www.geo-twit.com/
use? I wonder if there is ...
Recommended Posts