Skip to content

Instantly share code, notes, and snippets.

@hironow
Last active August 29, 2015 14:02
Show Gist options
  • Save hironow/179af2b5466839d65e40 to your computer and use it in GitHub Desktop.
Save hironow/179af2b5466839d65e40 to your computer and use it in GitHub Desktop.
python-twitter + wheezy.template, #imas
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>
@def title():
@end
@title()\
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<!-- Custom styles for this template -->
<style type="text/css">
body {
padding-top: 20px;
padding-bottom: 20px;
}
.navbar {
margin-bottom: 20px;
}
</style>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<!-- Static navbar -->
<div class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">@title()\
</a>
</div>
</div>
@def content():
@end
@content()\
@def footer():
&copy; Copyright 2014 by Me.
@end
@footer()\
</div>
@inline("shared/snippet/script.html")
@def script():
@end
@script()\
</body>
</html>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://code.jquery.com/jquery.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
@extends("shared/master.html")
@def title():
@require(subject)
@subject!s
@end
@def content():
@require(tweets)
@for tweet in tweets:
<blockquote class="twitter-tweet">
<a href="https://twitter.com/@tweet.user.screen_name!s/status/@tweet.id!s">https://twitter.com/@tweet.user.screen_name!s/status/@tweet.id!s</a>
</blockquote>
@end
@end
@def script():
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
@end
# -*- coding: utf-8 -*-
import twitter
import tw_key
from wheezy.html.utils import html_escape
from wheezy.html.ext.template import InlineExtension
from wheezy.template.engine import Engine
from wheezy.template.ext.core import CoreExtension
from wheezy.template.loader import FileLoader
CONSUMER_KEY = tw_key.twdict['cons_key']
CONSUMER_SECRET = tw_key.twdict['cons_sec']
ACCESS_TOKEN_KEY = tw_key.twdict['accto_key']
ACCESS_TOKEN_SECRET = tw_key.twdict['accto_sec']
api = twitter.Api(consumer_key=CONSUMER_KEY,
consumer_secret=CONSUMER_SECRET,
access_token_key=ACCESS_TOKEN_KEY,
access_token_secret=ACCESS_TOKEN_SECRET)
tweets = api.GetSearch(term="#imas")
searchpath = ['templates']
engine = Engine(
loader=FileLoader(searchpath),
extensions=[
CoreExtension(),
InlineExtension(searchpath),
])
engine.global_vars.update({
'h': html_escape
})
template = engine.get_template('twi_wheezy.html')
html = template.render(
dict(subject=u'python-twitter + wheezy.template アイマスで検索',
tweets=tweets))
with open('index.html', 'w') as f:
f.write(html.encode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment