|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +Feed it the JSON and get a wall of tweets as HTML. If you want to get the |
| 5 | +wall in chronological order, a handy trick is: |
| 6 | +
|
| 7 | + % tail -r tweets.json | ./wall.py > wall.html |
| 8 | +
|
| 9 | +""" |
| 10 | + |
| 11 | +import json |
| 12 | +import fileinput |
| 13 | +import dateutil.parser |
| 14 | + |
| 15 | +print """<!doctype html> |
| 16 | +<html> |
| 17 | +
|
| 18 | +<head> |
| 19 | + <title>congrats @dancohen</title> |
| 20 | + <style> |
| 21 | + body { |
| 22 | + font-size: 12pt; |
| 23 | + margin-left: auto; |
| 24 | + margin-right: auto; |
| 25 | + width: 95%; |
| 26 | + } |
| 27 | +
|
| 28 | + article.tweet { |
| 29 | + position: relative; |
| 30 | + float: left; |
| 31 | + border: thin #eeeeee solid; |
| 32 | + margin: 10px; |
| 33 | + width: 270px; |
| 34 | + padding: 10px; |
| 35 | + height: 160px; |
| 36 | + } |
| 37 | +
|
| 38 | + .name { |
| 39 | + font-weight: bold; |
| 40 | + } |
| 41 | +
|
| 42 | + img.avatar { |
| 43 | + vertical-align: middle; |
| 44 | + float: left; |
| 45 | + margin-right: 10px; |
| 46 | + border-radius: 5px; |
| 47 | + height: 45px; |
| 48 | + } |
| 49 | +
|
| 50 | + .tweet footer { |
| 51 | + position: absolute; |
| 52 | + bottom: 5px; |
| 53 | + left: 10px; |
| 54 | + } |
| 55 | +
|
| 56 | + time { |
| 57 | + font-size: small; |
| 58 | + } |
| 59 | +
|
| 60 | + footer#page { |
| 61 | + margin-top: 15px; |
| 62 | + clear: both; |
| 63 | + width: 100%; |
| 64 | + text-align: center; |
| 65 | + font-size: 20pt; |
| 66 | + font-weight: heavy; |
| 67 | + } |
| 68 | +
|
| 69 | + </style> |
| 70 | +</head> |
| 71 | +
|
| 72 | +<body> |
| 73 | +
|
| 74 | +<h1>created on the command line with <a href="http://github.com/edsu/twarc">twarc</a> |
| 75 | +
|
| 76 | +<div id="tweets"> |
| 77 | +""" |
| 78 | + |
| 79 | +for line in fileinput.input(): |
| 80 | + tweet = json.loads(line) |
| 81 | + t = { |
| 82 | + "created_at": tweet["created_at"], |
| 83 | + "name": tweet["user"]["name"], |
| 84 | + "username": tweet["user"]["screen_name"], |
| 85 | + "user_url": "http://twitter.com/" + tweet["user"]["screen_name"], |
| 86 | + "text": tweet["text"], |
| 87 | + "avatar": tweet["user"]["profile_image_url"], |
| 88 | + "url": "http://twitter.com/" + tweet["user"]["screen_name"] + "/status/" + tweet["id_str"], |
| 89 | + } |
| 90 | + |
| 91 | + html = """ |
| 92 | + <article class="tweet"> |
| 93 | + <img class="avatar" src="%(avatar)s"> |
| 94 | + <a href="%(user_url)s" class="name">%(name)s</a><br> |
| 95 | + <span class="username">%(username)s</span><br> |
| 96 | + <br> |
| 97 | + <span class="text">%(text)s</span><br> |
| 98 | + <footer> |
| 99 | + <a href="%(url)s"><time>%(created_at)s</time></a> |
| 100 | + </footer> |
| 101 | + </article> |
| 102 | + """ % t |
| 103 | + |
| 104 | + print html.encode("utf-8") |
| 105 | + |
| 106 | +print """ |
| 107 | +
|
| 108 | +</div> |
| 109 | +
|
| 110 | +<footer id="page"> |
| 111 | +<hr> |
| 112 | +<br> |
| 113 | +created on the command line with <a href="http://github.com/edsu/twarc">twarc</a>. |
| 114 | +<br> |
| 115 | +<br> |
| 116 | +</footer> |
| 117 | +
|
| 118 | +</body> |
| 119 | +</html>""" |
0 commit comments