--- a/fetch.py +++ /dev/null @@ -1,154 +1 @@ -from flask import Flask -from flask import request -from flask import render_template -from flask import make_response -from flask import jsonify -import logging -from logging import FileHandler -import pymongo -import os -import lxml.html -import urllib2 -import StringIO -import json - -app = Flask(__name__) - - -@app.route('/', methods=['GET']) -def index(): - if request.args.has_key('url'): - return render_template('index.html', url=request.args['url']) - else: - return render_template('index.html') - - -@app.route('/fetch', methods=['GET']) -def fetch(): - connection = pymongo.Connection() - db = connection['mural'] - collection = db['data'] - ret = {} - x = 0 - resource = "default" - if request.args.has_key('uri'): - resource = request.args['uri'] - for i in collection.find({'uri':resource}): - del(i['_id']) - ret[x] = i - x = x + 1 - if len(ret) == 0: - ret['error'] = "Sorry! No re-treats for you." - return jsonify(ret) - - -@app.route('/search', methods=['GET']) -def search(): - connection = pymongo.Connection() - db = connection['mural'] - collection = db['data'] - y = 0 - ret = {} - keywords_dict = json.loads(request.args['data']) - keywords = json.loads(keywords_dict)['data'] - for i in collection.find(): - for keyword in keywords: - print keyword - try: - if keyword in i['nodes']: - del(i['_id']) - ret[y] = i - y = y + 1 - except: - pass - return render_template('blank.html', content = ret) - - -@app.route('/submit', methods=['POST']) -def submit(): - c = pymongo.Connection() - db = c['mural'] - coll = db['data'] - requestData = json.loads(request.form['data']) - try: - for i in requestData: - coll.insert(i) - response = make_response() - response.headers['Access-Control-Allow-Origin'] = '*' - response.status = '200 OK' - response.status_code = 200 - return response - except: - response = make_response() - response.status = "500" - response.data = "Your post could not be saved. Try posting again." - return response - -@app.route('/web', methods=['GET']) -def web(): - return render_template('web.html') - -@app.route('/SWeeText', methods=['GET']) -def SWeeText(): - if request.args.has_key('url'): - myhandler1 = urllib2.Request(request.args['url'], headers={'User-Agent': "Mozilla/5.0(X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11"}) - a = urllib2.urlopen(myhandler1) - page = a.read() - a.close() - try: - page = unicode(page, 'utf-8') - except UnicodeDecodeError: - pass - root = lxml.html.parse(StringIO.StringIO(page)).getroot() - root.make_links_absolute(request.args['url'], resolve_base_href = True) - - # inject the JS toolbar to annotate text - script = root.makeelement('script') - script.set('src', 'static/text-annotation.js') - tree = root.makeelement('script') - tree.set('src', 'static/tree.js') - bs_js = root.makeelement('script') - bs_js.set('src', 'static/bootstrap.js') - jq = root.makeelement('script') - jq.set('src', 'static/jquery-1.9.1.min.js') - jit = root.makeelement('script') - jit.set('src', 'static/jit.js') - us = root.makeelement('script') - us.set('src', 'static/underscore-min-1.4.4.js') - - link = root.makeelement('link') - link.set('href', 'static/text-annotation.css') - link.set('type', 'text/css') - link.set('rel', 'stylesheet') - bs = root.makeelement('link') - bs.set('href', 'static/bootstrap.css') - bs.set('type', 'text/css') - bs.set('rel', 'stylesheet') - tree_css = root.makeelement('link') - tree_css.set('href', 'static/tree.css') - tree_css.set('type', 'text/css') - tree_css.set('rel', 'stylesheet') - - root.body.append(jq) - root.body.append(bs_js) - root.body.append(jit) - root.body.append(us) - root.body.append(tree) - root.body.append(script) - - root.head.append(bs) - root.head.append(link) - root.head.append(tree_css) - - return lxml.html.tostring(root) - - -#Log the errors, don't depend on apache to log it for you. - fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a') - fil.setLevel(logging.ERROR) - app.logger.addHandler(fil) - - -if __name__ == "__main__": - app.run(debug=True, host='0.0.0.0') --- /dev/null +++ b/server.py @@ -1 +1,165 @@ +from flask import Flask +from flask import request +from flask import render_template +from flask import make_response +from flask import jsonify +import logging +from logging import FileHandler +import pymongo +import os +import lxml.html +import urllib2 +import StringIO +import json + +app = Flask(__name__) + + +@app.route('/', methods=['GET']) +def index(): + if request.args.has_key('url'): + return render_template('index.html', url=request.args['url']) + else: + return render_template('index.html') + + +@app.route('/fetch', methods=['GET']) +def fetch(): + connection = pymongo.Connection() + db = connection['mural'] + collection = db['data'] + ret = {} + x = 0 + resource = "default" + if request.args.has_key('uri'): + resource = request.args['uri'] + for i in collection.find({'uri':resource}): + del(i['_id']) + ret[x] = i + x = x + 1 + if len(ret) == 0: + ret['error'] = "Sorry! No re-treats for you." + return jsonify(ret) + + +@app.route('/search', methods=['GET']) +def search(): + connection = pymongo.Connection() + db = connection['mural'] + collection = db['data'] + y = 0 + ret = {} + keywords_dict = json.loads(request.args['data']) + keywords = json.loads(keywords_dict)['data'] + for i in collection.find(): + for keyword in keywords: + print keyword + try: + if keyword in i['nodes']: + del(i['_id']) + ret[y] = i + y = y + 1 + except: + pass + return render_template('blank.html', content = ret) + + +@app.route('/submit', methods=['POST']) +def submit(): + c = pymongo.Connection() + db = c['mural'] + coll = db['data'] + requestData = json.loads(request.form['data']) + try: + for i in requestData: + coll.insert(i) + response = make_response() + response.headers['Access-Control-Allow-Origin'] = '*' + response.status = '200 OK' + response.status_code = 200 + return response + except: + response = make_response() + response.status = "500" + response.data = "Your post could not be saved. Try posting again." + return response + +@app.route('/web', methods=['GET']) +def web(): + return render_template('web.html') + +@app.route('/SWeeText', methods=['GET']) +def SWeeText(): + if request.args.has_key('url'): + # Log -- comment them + print "Got URL " + request.args['url'] + " .. Fetching and Parsing.." + myhandler1 = urllib2.Request(request.args['url'], headers={'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:20.0) Gecko/20100101 Firefox/20.0"}) + a = urllib2.urlopen(myhandler1) + page = a.read() + a.close() + try: + page = unicode(page, 'utf-8') + except UnicodeDecodeError: + pass + root = lxml.html.parse(StringIO.StringIO(page)).getroot() + root.make_links_absolute(request.args['url'], resolve_base_href = True) + # Log -- comment them + print "Page parsed.. Preparing to send.." + + # inject the JS toolbar to annotate text + jq = root.makeelement('script') + jq.set('src', 'static/jquery-1.9.1.min.js') + + script = root.makeelement('script') + script.set('src', 'static/text-annotation.js') + + tree = root.makeelement('script') + tree.set('src', 'static/tree.js') + + bs_js = root.makeelement('script') + bs_js.set('src', 'static/bootstrap.js') + + jit = root.makeelement('script') + jit.set('src', 'static/jit.js') + + us = root.makeelement('script') + us.set('src', 'static/underscore-min-1.4.4.js') + + link = root.makeelement('link') + link.set('href', 'static/text-annotation.css') + link.set('type', 'text/css') + link.set('rel', 'stylesheet') + + bs = root.makeelement('link') + bs.set('href', 'static/bootstrap.css') + bs.set('type', 'text/css') + bs.set('rel', 'stylesheet') + + tree_css = root.makeelement('link') + tree_css.set('href', 'static/tree.css') + tree_css.set('type', 'text/css') + tree_css.set('rel', 'stylesheet') + + root.head.append(bs) + root.head.append(link) + root.head.append(tree_css) + + root.head.append(jq) + root.head.append(bs_js) + root.head.append(jit) + root.head.append(us) + root.head.append(tree) + root.head.append(script) + + return lxml.html.tostring(root) + + +#Log the errors, don't depend on apache to log it for you. + fil = FileHandler(os.path.join(os.path.dirname(__file__), 'logme'),mode='a') + fil.setLevel(logging.ERROR) + app.logger.addHandler(fil) + + +if __name__ == "__main__": + app.run(debug=True, host='0.0.0.0') --- /dev/null +++ b/static/graphs/GirijaKalyanaStory.json @@ -1 +1,170 @@ +[{ +"adjacencies" :[{"nodeTo" :"ShivaPurana", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory", +"nodeFrom":"ShivaPurana", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"ShivaPurana","name":"ShivaPurana" +},{ +"adjacencies" :[{"nodeTo" :"Pampapathi", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"Hampamma", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"Daksha", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaMural", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"PalaPuja", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"KalyanUtsav", +"nodeFrom":"GirijaKalyanaStory", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaStory","name":"GirijaKalyanaStory" +},{ +"adjacencies" :[{"nodeTo" :"PampapathiEg1", +"nodeFrom":"Pampapathi", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"PampapathiEg2", +"nodeFrom":"Pampapathi", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"Snake", +"nodeFrom":"Pampapathi", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"Nandi", +"nodeFrom":"Pampapathi", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"Hampamma", +"nodeFrom":"Pampapathi", +"data":{"$color":"black"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory", +"nodeFrom":"Pampapathi", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Pampapathi","name":"Pampapathi" +},{ +"adjacencies" :[{"nodeTo" :"Pampapathi", +"nodeFrom":"Hampamma", +"data":{"$color":"black"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Hampamma","name":"Hampamma" +},{ +"adjacencies" :[{"nodeTo" :"Daksha", +"nodeFrom":"Hampamma", +"data":{"$color":"black"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Hampamma","name":"Hampamma" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory", +"nodeFrom":"Hampamma", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Hampamma","name":"Hampamma" +},{ +"adjacencies" :[{"nodeTo" :"Hampamma", +"nodeFrom":"Daksha", +"data":{"$color":"black"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Daksha","name":"Daksha" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory", +"nodeFrom":"Daksha", +"data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"Daksha","name":"Daksha" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaEg", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"Anklet", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"Pampapathi", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"Hampamma", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"Daksha", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"GirijaKalyanaStory", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"KalyanaMantapa", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"VijaynagaraTradition", +"nodeFrom":"GirijaKalyanaMural", +"data":{"$color":"blue"}}] , +"data":{"$color":"white","$type":"ellipse", +"$label-color":"black","$label-size":"20","$nodecDir":""},"id":"GirijaKalyanaMural","name":"GirijaKalyanaMural" +},{ +"adjacencies" :[{"nodeTo" :"NandiEg", +"nodeFrom":"Nandi", + "data":{"$color":"blue"}}] , +"data":{"$color":"lightgray","$type":"rectangle", +"$label-color":"black","$label-size":"20","$nodeDir":""},"id":"Nandi","name":"Nandi" +}] --- a/static/text-annotation.css +++ b/static/text-annotation.css @@ -1,31 +1,17 @@ #annotate-bar { - position: absolute; + position: fixed; + width: 80%; top: 1px; - left: 35%; - width: 180px; - height: 35px; - margin: auto; - border: 1px solid black; - background-color: #F0F0F0; - border-radius: 3px; - opacity: 0.9; - z-index: 1000; - padding: 3px 10px; } -#anno-btn { - margin: 0 5px; - opacity: 1; -} -#publish { - opacity:1; - margin: 0 5px; -} #sweeted { - opacity: 1; z-index: 1000 !important; display: none; - width: 400px !important; - font-style: bold !important; font-size: 16px; + width: 100%; +} +.alert { + margin: auto; + width: 700px; + box-shadow: 3px 3px 3px #468847; } --- a/static/text-annotation.js +++ b/static/text-annotation.js @@ -32,6 +32,8 @@ nodes[i].addEventListener('mouseout', onHoverOut); } } + //$(document).mouseover(onHover); + //$(document).mouseout(onHoverOut); }; var removeSelect = function() { var nodes = document.getElementsByTagName('*'); @@ -43,13 +45,22 @@ nodes[i].removeEventListener('mouseout', onHoverOut); } } + //$(document).unbind('mouseover', onHover); + //$(document).unbind('mouseout', onHoverOut); }; var toolbar_template = function() { - return '
' + - '