-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to serve JSON, also added a small example HTML page to il…
…lustrate how to use it.
- Loading branch information
Showing
5 changed files
with
164 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!-- | ||
rndpic - an App Engine app to display random pictures from Picasa Web. | ||
Copyright (C) 2011 Patrick Moor <patrick@moor.ws> | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
<html> | ||
<head> | ||
<title>sample slideshow using rndpic.appspot.com</title> | ||
</head> | ||
<body> | ||
<p>This is a sample slideshow using <a href="http://rndpic.appspot.com">rndpic.appspot.com</a>.</p> | ||
<div> | ||
<a href="#" id="rndpic_link"><img id="rndpic_image"/></a> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
|
||
function loadNewImage() { | ||
xmlhttp = new XMLHttpRequest(); | ||
xmlhttp.onreadystatechange = function() { | ||
if (xmlhttp.readyState == 4) { | ||
var image = eval("(" + xmlhttp.responseText + ")"); | ||
|
||
function switchImage() { | ||
var linkTag = document.getElementById("rndpic_link"); | ||
var imageTag = document.getElementById("rndpic_image"); | ||
linkTag.href = image.target_url; | ||
imageTag.width = image.width; | ||
imageTag.height = image.height; | ||
imageTag.src = image.thumbnail_url; | ||
} | ||
|
||
var preloadedThumbnail = new Image(); | ||
preloadedThumbnail.src = image.thumbnail_url; | ||
preloadedThumbnail.onload = switchImage | ||
|
||
// reload every 5 seconds | ||
window.setTimeout("loadNewImage()", 5 * 1000); | ||
} | ||
}; | ||
xmlhttp.open("GET", "http://rndpic.appspot.com/json/patrick.moor?size=400u", true); | ||
xmlhttp.send(); | ||
} | ||
|
||
loadNewImage(); | ||
|
||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# rndpic - an App Engine app to display random pictures from Picasa Web. | ||
# Copyright (C) 2011 Patrick Moor <patrick@moor.ws> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from google.appengine.ext import webapp | ||
from django.utils import simplejson | ||
|
||
class JsonHandler(webapp.RequestHandler): | ||
|
||
def __init__(self, picker): | ||
self._picker = picker | ||
|
||
def get(self, user_name): | ||
self.response.headers["Content-Type"] = "application/json" | ||
self.response.headers["Access-Control-Allow-Origin"] = "*" | ||
size = self.request.get("size", "200u") | ||
picture = self._picker.Pick(user_name, size) | ||
if picture: | ||
content = { | ||
"height": picture.GetHeight(), | ||
"width": picture.GetWidth(), | ||
"thumbnail_url": picture.GetThumbnailUrl(), | ||
"target_url": picture.GetLink(), | ||
} | ||
simplejson.dump(content, self.response.out) | ||
else: | ||
self.response.set_status(204) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# rndpic - an App Engine app to display random pictures from Picasa Web. | ||
# Copyright (C) 2011 Patrick Moor <patrick@moor.ws> | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from google.appengine.ext import webapp | ||
from google.appengine.ext.webapp.util import run_wsgi_app | ||
|
||
from feed import FeedRepository | ||
from album_repository import AlbumRepository | ||
from picker import RandomPicturePicker | ||
|
||
from user_handler import UserHandler | ||
from json_handler import JsonHandler | ||
|
||
|
||
repository = AlbumRepository(FeedRepository()) | ||
picker = RandomPicturePicker(repository) | ||
|
||
|
||
def _ConstructUserHandler(): | ||
return UserHandler(picker) | ||
|
||
|
||
def _ConstructJsonHandler(): | ||
return JsonHandler(picker) | ||
|
||
|
||
application = webapp.WSGIApplication( | ||
[ | ||
(r'/user/([^/]+)', _ConstructUserHandler), | ||
(r'/json/([^/]+)', _ConstructJsonHandler), | ||
], | ||
debug=False) | ||
|
||
|
||
def main(): | ||
run_wsgi_app(application) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters