Star Wars release commemoration, Star Wars style TL application made with bottle

I moved my hands as I thought, so the contents of the script are dirty, and there is nothing ingenuity with just one .tpl file. You can get TL by streaming, add a search function, and play various things.

index.py



#!/user/bin/env python
# -*- coding: utf-8 -*-
from bottle import route, run, template, request, static_file, url, get, post, response, error
from requests_oauthlib import OAuth1Session
import json
import requests
import time, calendar
import datetime
from datetime import timedelta
from datetime import datetime
import pytz
today = datetime.now(pytz.timezone('Asia/Tokyo'))
import sys, codecs
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)

@route("/")
def title():

	C_KEY = "***************"
	C_SECRET = "***************"
	A_KEY = "***************"
	A_SECRET = "***************"

	search_words = u"Christmas"

	url = "https://api.twitter.com/1.1/search/tweets.json?"
	params = {
				"q": (search_words, "utf-8"),
				"lang": "ja",
				"result_type": "recent",
				"count": "100"
				}
	tw = OAuth1Session(C_KEY,C_SECRET,A_KEY,A_SECRET)
	req = tw.get(url, params = params)
	tweets = json.loads(req.text)
	for tweet in tweets["statuses"]:
		Created_at = YmdHMS(tweet["created_at"])
		User = (tweet["user"]["screen_name"].encode("utf-8"))
		Name = (tweet["user"]["name"].encode("utf-8"))
		Text = (tweet["text"].encode("utf-8"))
		U_img = (tweet["user"]["profile_image_url"])

	return template("main", Created_at=Created_at, User=User, Name=Name, Text=Text)


def YmdHMS(created_at):
    time_utc = time.strptime(created_at, '%a %b %d %H:%M:%S +0000 %Y')
    unix_time = calendar.timegm(time_utc)
    time_local = time.localtime(unix_time)
    return int(time.strftime("%Y%m%d%H%M%S", time_local))


run(host='localhost', port=8000, debug=True, reloader=True)

main.tpl



<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">

<title>StarTwit</title>
</head>

<body>



  <style>
  body{
      background: #000;
  }
  #titles{
      position: absolute;
      width: 18em;
      height: 50em;
      bottom: 0;
      left: 50%;
      margin-left: -9em;
      font-size: 350%;
      font-weight: bold;
      text-align: justify;
      overflow: hidden;
      color: #fff;
      transform-origin: 50% 100%;
      transform: perspective(300px) rotateX(25deg);
  }
  #titles:after{
      position: absolute;
      content: ' ';
      left: 0;
      right: 0;
      top: 0;
      bottom: 60%;
      background-image: linear-gradient(top, rgba(0,0,0,1) 0%, transparent 100%);
      pointer-events: none;
  }
  #titlecontent{
      position: absolute;
      top: 100%;
      color: #fff;
      animation: scroll 100s linear 4s infinite;
  }
  @keyframes scroll {
      0% { top: 100%; }
      100% { top: -170%; }
  }
  </style>
  <div id="titles"><div id="titlecontent">
    <ul>
      <li>{{Created_at}}</li>
      <li>{{User}}:{{Name}}</li>
      <li>{{Text}}</li>
    </ul>

  </div></div>
  </body>
  </html>

img.jpg

It will be implemented like this. We have taken privacy into consideration.

Recommended Posts

Star Wars release commemoration, Star Wars style TL application made with bottle
[Perfume x STAR WARS] Style conversion with Chainer starting in 1 minute
Twitter posting application made with Django
Twitter search client made with bottle
Until you publish (deploy) a web application made with bottle on Heroku
[Python] A quick web application with Bottle!
I made a WEB application with Django