Commit c6d359e0d93c019dc8a6c40499d2a570ef951858

Intermediate commit
fetch.py
(36 / 12)
  
1010import lxml.html
1111import urllib2
1212import StringIO
13import json
1314
1415app = Flask(__name__)
1516
4747 c = pymongo.Connection()
4848 db = c['mural']
4949 coll = db['data']
50 try:
51 for i in d:
52 coll.insert(request.args['data'])
53 response = make_response()
54 response.status = '200 OK'
55 response.status_code = 200
56 return response
57 except:
58 response = make_response()
59 response.status = "500"
60 response.data = "Your post could not be saved. Try posting again."
61 return response
50 for i in request.form['data']:
51 coll.insert(i)
52 response = make_response()
53 response.status = "200 OK"
54 return response
6255
56@app.route('/web', methods=['GET'])
57def web():
58 return render_template('web.html')
6359
6460@app.route('/SWeeText', methods=['GET'])
6561def SWeeText():
7474 # inject the JS toolbar to annotate text
7575 script = root.makeelement('script')
7676 script.set('src', 'static/text-annotation.js')
77 tree = root.makeelement('script')
78 tree.set('src', 'static/tree.js')
79 bs_js = root.makeelement('script')
80 bs_js.set('src', 'static/bootstrap.js')
81 jq = root.makeelement('script')
82 jq.set('src', 'static/jquery-1.9.1.min.js')
83 jit = root.makeelement('script')
84 jit.set('src', 'static/jit.js')
85 us = root.makeelement('script')
86 us.set('src', 'static/underscore-min-1.4.4.js')
87
7788 link = root.makeelement('link')
7889 link.set('href', 'static/text-annotation.css')
7990 link.set('type', 'text/css')
8091 link.set('rel', 'stylesheet')
92 bs = root.makeelement('link')
93 bs.set('href', 'static/bootstrap.css')
94 bs.set('type', 'text/css')
95 bs.set('rel', 'stylesheet')
96 tree_css = root.makeelement('link')
97 tree_css.set('href', 'static/tree.css')
98 tree_css.set('type', 'text/css')
99 tree_css.set('rel', 'stylesheet')
81100
101 root.body.append(jq)
102 root.body.append(bs_js)
103 root.body.append(jit)
104 root.body.append(us)
105 root.body.append(tree)
82106 root.body.append(script)
107
108 root.head.append(bs)
83109 root.head.append(link)
110 root.head.append(tree_css)
84111
85112 return lxml.html.tostring(root)
86113
  
111111 event.stopPropagation();
112112 }
113113 //Log.write('centering node ', node.name);
114 console.log('centering node', node.name);
114115 RGraph.onClick(node.id, {
115116 hideLabels: false,
116117 onComplete: function() {
151151 user: user,
152152 type: this.type,
153153 uri: resource,
154 top: attribs.top,
155 bottom: attribs.bottom,
156 left: attribs.left,
157 right: attribs.right,
158154 nodes: this.nodes,
159155 };
156 if(attribs.hasOwnProperty('top') &&
157 attribs.hasOwnProperty('bottom') &&
158 attribs.hasOwnProperty('right') &&
159 attribs.hasOwnProperty('left')) {
160 data.top = attribs.top;
161 data.bottom = attribs.bottom;
162 data.left = attribs.left;
163 data.right = attribs.right;
164 }
165 if(attribs.hasOwnProperty('xpath')) {
166 data.xpath = attribs.xpath;
167 }
160168 this.swts.push(data);
161169 this.nodes = [];
162170 },
173173 return;
174174 }
175175 $('#publish').attr('disabled', 'disabled');
176 //$('#posted').show();
177 var swts = '';
178 for(var i in this.swts) {
179 var data = this.swts[i];
180 var swt = '@'+data.user+' '+data.type+' '+data.uri;
181 if(data.hasOwnProperty('xpath')) {
182 swt += ' xpath: '+data.xpath;
183 }
184 if(data.hasOwnProperty('top')) {
185 swt += ' #['+data.top+','+data.right+','+data.bottom+','+data.left+']';
186 }
187 swt += ' ' + data.nodes;
188 swts += swt + '\n';
189 }
190 $('#sweet').html(swts);
191 $('#sweeted').show();
176192 $.ajax({
177193 type: 'POST',
178194 url: config.indexer + '/submit',
179 data: {'data': JSON.stringify(this.swts)},
195 data: {'data': this.swts},
180196 success: function() {
181 $.ajax({
197 /*$.ajax({
182198 type: 'POST',
183199 url: config.postTweetUrl,
184200 data: {'data': JSON.stringify(this.swts)},
205205 error: function() {
206206 $('#fail-posting').show();
207207 }
208 });
208 });*/
209 $('#posted').show();
210 var swts = '';
211 for(var i in this.swts) {
212 var data = this.swts[i];
213 var swt = '@'+data.user+' '+data.type+' '+data.uri;
214 if(data.hasOwnProperty('xpath')) {
215 swt += ' xpath: '+data.xpath;
216 }
217 if(data.hasOwnProperty('top')) {
218 swt += ' #['+data.top+','+data.right+','+data.bottom+','+data.left+']';
219 }
220 swt += ' ' + data.nodes;
221 swts += swt + '\n';
222 }
223 $('#sweet').html(swts);
224 this.swts = [];
209225 },
210226 error: function() {
211 $('#fail-posting').show();
227 //$('#fail-posting').show();
212228 }
213229 });
214230 }
266266 size: 14
267267 },
268268 interpolation: 'polar',
269 transition: $jit.Trans.Sine.easeInOut,
269 transition: $jit.Trans.Sine.easeIn,
270270 levelDistance: 150,
271271 onCreateLabel: function(domElement, node) {
272272 console.log('oncreatelabel');
  
7070 <!-- PLEASE, LET THIS NOTE ABOUT AUTHOR AND PROJECT SOMEWHERE ON YOUR WEBSITE, OR AT LEAST IN THE COMMENT IN HTML. THANK YOU -->
7171 </div>
7272
73 </div>
7374 </div>
7475
7576 <script type="text/javascript" >resize();</script>