4 |
5 | webnet
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/index.yaml:
--------------------------------------------------------------------------------
1 | indexes:
2 |
3 | # AUTOGENERATED
4 |
5 | # This index.yaml is automatically updated whenever the dev_appserver
6 | # detects that a new type of query is run. If you want to manage the
7 | # index.yaml file manually, remove the above marker line (the line
8 | # saying "# AUTOGENERATED"). If you want to manage some indexes
9 | # manually, move them above the marker line. The index.yaml file is
10 | # automatically uploaded to the admin console when you next deploy
11 | # your application using appcfg.py.
12 |
--------------------------------------------------------------------------------
/api-example.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | webnet - related api example
6 |
7 |
8 |
9 |
Example usage of the Google Search API to find related sites
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | #
3 | # Copyright 2007 Google Inc.
4 | #
5 | # Licensed under the Apache License, Version 2.0 (the "License");
6 | # you may not use this file except in compliance with the License.
7 | # You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | #
17 |
18 |
19 | from google.appengine.ext import webapp
20 | from google.appengine.ext.webapp import template
21 | from google.appengine.ext.webapp import util
22 | import os
23 |
24 |
25 | class MainHandler(webapp.RequestHandler):
26 |
27 | def get(self, uri):
28 | uri = uri if ( len(uri) > 0 ) else 'index.html'
29 | path = os.path.join(os.path.dirname(__file__), uri)
30 | self.response.out.write(template.render(path, {}))
31 |
32 | def main():
33 | application = webapp.WSGIApplication([('/(.*)', MainHandler)], debug=True)
34 | util.run_wsgi_app(application)
35 |
36 | if __name__ == '__main__':
37 | main()
38 |
--------------------------------------------------------------------------------
/static/js/webnet.js:
--------------------------------------------------------------------------------
1 | /*jslint white: true, browser: true, devel: true, forin: true, onevar: true, undef: true, nomen: true, eqeqeq: true, plusplus: true, bitwise: true, regexp: true, strict: true, immed: true, newcap: false */
2 | /*globals window: false, Raphael: false, jQuery: false */
3 | "use strict";
4 | (function (global, console, Raphael, $) {
5 | var W = 640,
6 | H = 480,
7 | R = 20,
8 | canvas,
9 | root;
10 |
11 | function log() {
12 | if (console) {
13 | console.log.apply(this, Array.prototype.slice.call(arguments));
14 | }
15 | }
16 |
17 | function node() {
18 | var that = {},
19 | children = [];
20 |
21 | that.extend = function (count) {
22 | var i;
23 |
24 | if (count == null) {
25 | count = 3;
26 | }
27 |
28 | for (i = 0; i < count; i += 1) {
29 | children.push(node());
30 | }
31 |
32 | return children;
33 | };
34 |
35 | that.children = function () {
36 | return children;
37 | };
38 |
39 | return that;
40 | }
41 |
42 | // returns SVG path format for a simple line
43 | function line(x1, y1, x2, y2) {
44 | return "M" + x1 + " " + y1 + "L" + x2 + " " + y2;
45 | }
46 |
47 | function draw(node, x, y, parentX, parentY) {
48 | var i,
49 | l,
50 | children,
51 | newX,
52 | newY,
53 | element,
54 | lineElement;
55 |
56 | element = canvas.circle(x, y, R);
57 | element.attr({
58 | fill: "#000"
59 | });
60 |
61 | if (parentX != null && parentY != null) {
62 | lineElement = canvas.path(line(parentX, parentY, x, y));
63 | }
64 |
65 | function clicked() {
66 | element.unclick(clicked);
67 |
68 | children = node.extend();
69 | for (i = 0, l = children.length; i < l; i += 1) {
70 | // Obviously, this is retarded, but I didn't feel like working out a neat
71 | // visual balancing algorithm at the time
72 | switch (i) {
73 | case 0:
74 | newX = x - 80;
75 | newY = y;
76 | break;
77 | case 1:
78 | newX = x - 60;
79 | newY = y - 60;
80 | break;
81 | case 2:
82 | newX = x;
83 | newY = y - 80;
84 | break;
85 | }
86 | draw(children[i], newX, newY, x, y);
87 | }
88 | }
89 |
90 | element.click(clicked);
91 | }
92 |
93 | function drawAll() {
94 | draw(root, W / 2, H / 2);
95 | }
96 |
97 | function go() {
98 | canvas = Raphael("target", W, H);
99 | root = node();
100 | drawAll();
101 | }
102 |
103 | $(go); // you made an anonymous function call a function, refactored for you :)
104 |
105 | }(window, window.console, Raphael, jQuery));
--------------------------------------------------------------------------------
/static/js/webnet-search.js:
--------------------------------------------------------------------------------
1 | (function(global, $, search, gwsapi, rest){
2 |
3 | gwsapi = {
4 |
5 | endpoint: "http://ajax.googleapis.com/ajax/services/search/web",
6 |
7 | data: {
8 |
9 | "v": "1.0",
10 |
11 | // only valid for -> http://web-net.appspot.com
12 | "key": "ABQIAAAAkkdaXuqsqYaxndd7AhpfQxTXUXu-1b2d1fQ-ne93ANWuraz4xhR9nlMEPbsmi-DIypuV2Aa6FrFvAw"
13 |
14 | }
15 |
16 | };
17 |
18 | search = {
19 |
20 | init: function() {
21 |
22 | search.field = $("#field");
23 |
24 | search.button = $("#button").bind("click keypress", search.findRelatedSites);
25 |
26 | search.results = $("#results");
27 |
28 | },
29 |
30 | findRelatedSites: function(data) {
31 |
32 | if (search.request) {
33 |
34 | search.request.abort();
35 |
36 | }
37 |
38 | data = $.extend(gwsapi.data, { "q": "related:" + search.field.val() });
39 |
40 | search.request = $.ajax({
41 |
42 | url: gwsapi.endpoint,
43 |
44 | dataType: "jsonp",
45 |
46 | data: data,
47 |
48 | success: search.loadResults,
49 |
50 | error: search.error
51 |
52 | });
53 |
54 | },
55 |
56 | loadResults: function(data) {
57 |
58 | search.request = null;
59 |
60 | if (data.responseStatus === 200) {
61 |
62 | search.results.empty();
63 |
64 | data = data.responseData || {};
65 |
66 | data.results = data.results || [];
67 |
68 | $.each(data.results, search.loadResult);
69 |
70 | } else {
71 |
72 | search.error(data.responseDetail);
73 |
74 | }
75 |
76 | },
77 |
78 | loadResult: function(result, data) {
79 |
80 | result = $("").attr({
81 |
82 | "href": data.unescapedUrl,
83 |
84 | "title": "Click to load similar results for " + data.visibleUrl + "...",
85 |
86 | }).click(search.findRelatedFromResult).html(data.titleNoFormatting);
87 |
88 | result = result.wrap("").parent();
89 |
90 | search.results.append(result);
91 |
92 | },
93 |
94 | findRelatedFromResult: function(site) {
95 |
96 | site = $(this).attr("href");
97 |
98 | search.field.val(site);
99 |
100 | search.findRelatedSites();
101 |
102 | return false;
103 |
104 | },
105 |
106 | error: function(out) {
107 |
108 | if(console && console.log && console.trace) {
109 |
110 | console.log("An error occurred:", out);
111 |
112 | console.trace();
113 |
114 | }
115 |
116 | }
117 |
118 | };
119 |
120 | $(search.init);
121 |
122 | })(window, jQuery);
--------------------------------------------------------------------------------
/static/js/raphael.min.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Raphael 1.3.1 - JavaScript Vector Library
3 | *
4 | * Copyright (c) 2008 - 2009 Dmitry Baranovskiy (http://raphaeljs.com)
5 | * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
6 | */
7 | Raphael=(function(){var a=/[, ]+/,aO=/^(circle|rect|path|ellipse|text|image)$/,L=document,au=window,l={was:"Raphael" in au,is:au.Raphael},an=function(){if(an.is(arguments[0],"array")){var d=arguments[0],e=w[aW](an,d.splice(0,3+an.is(d[0],al))),S=e.set();for(var R=0,a0=d[m];R