ueBLOG | RandomTumblrを作ってみた

http://www.ueblog.org/randomtumblr/photo/(Tumblrのユーザー名)/(サイズ 75,100,250,400,500のどれか オプション)/

例 ueblog を画像サイズ100で表示

http://www.ueblog.org/randomtumblr/photo/ueblog/100

ちなみにrandomtumblrのサーバー側のロジックはこんだけ、db使わないからモデルもない

urls.py
>|python|
#randomtumblr
(r’^randomtumblr/photo/(?P.*)/$’, ‘djblogkit.blog.randomtumblr.show’),

randomtumblr.py

from django.shortcuts import render_to_response
from django.http import Http404

def show(request, uid=None):
    photourl_list = [“photo-url-75”, “photo-url-100”, “photo-url-250”, “photo-url-400”, “photo-url-500”]
    if request.method == “GET”:
        if request.GET.get(“size”, None) in photourl_list:
            photourl = request.GET.get(“size”)
        else:
            photourl = photourl_list[-1]
    else:
        return Http404
    if not uid:
        return Http404
    return render_to_response(“randomtumblr.html”,  {“uid”:uid, “photourl”:photourl})
subscrib
<html>
    <head>
        <title>Random Tumblr - ueblog</title>
        <script type="text/javascript" src="/media/javascript/jquery.js"></script>
        <script type="text/javascript" src="http://ueblog.tumblr.com/api/read/json?num=1&type=photo"></script>
        <script type="text/javascript" src="/media/javascript/jquery.jsonp.js"></script>
        <script type="text/javascript">

            function get_total() {
                return tumblr_api_read["posts-total"];
            }
            
            function get_random() {
                return Math.floor(Math.random() * get_total());
            }
            
            function tumblr_image_jsonp() {
                var url = "http://ueblog.tumblr.com/api/read/json?callback=tumblr_image&type=photo&num=1&start=" + get_random();
                $.getJSONP(url, tumblr_image);
            }
           
            function tumblr_image(json) {
                var result = json.posts[0];
                var url = result["url"];
                var photo_url = result["photo-url-100"];
                $("#photo_link").attr("href", url);
                $("#photo_link").attr("target", "_blank");
                $("#photo_img").fadeOut();
                $("#photo_img").attr("src", photo_url);
                $("#photo_img").fadeIn();
            }

            $(document).ready(function () {
                    tumblr_image_jsonp();
                    setInterval(tumblr_image_jsonp, 8000);
            });

        </script>

    </head>
    <body>
        <div id="photo">
            <!-- <span id="photo_click">click</span> -->
            <a id="photo_link">
                <img id="photo_img">
            </a>
            </div>
        </div>

    </body>
</html>