Commit bed05e171f3cfb595a25a8567e9887242b7e68b9
- server/alipi.py 34 ---------------+++++++++++++++++++
- server/templates/feeds.html 20 ++++++++++++++++++++
- Diff rendering mode:
- inline
- side by side
server/alipi.py
1 | |||
---|---|---|---|
2 | |||
3 | |||
4 | |||
5 | 1 | #-*-coding: utf-8 -*- | |
2 | from flask import Flask, request, render_template, g, redirect, jsonify, make_response | ||
6 | from bson import Code | 3 | from bson import Code |
7 | |||
8 | |||
9 | |||
10 | |||
11 | |||
12 | |||
13 | |||
14 | |||
15 | 4 | from urllib import quote_plus, unquote_plus | |
5 | import urllib2, StringIO, lxml.html, pymongo, conf, oursql | ||
16 | app = Flask(__name__) | 6 | app = Flask(__name__) |
17 | @app.before_request | 7 | @app.before_request |
18 | def first(): | 8 | def first(): |
… | … | ||
286 | coll = g.db['post'] | 286 | coll = g.db['post'] |
287 | d = {} | 287 | d = {} |
288 | cntr = 0 | 288 | cntr = 0 |
289 | 289 | for i in coll.find().sort('_id',direction=-1): | |
290 | if i['data'] != '<br/>': | 290 | if i['data'] != '<br/>': |
291 | i['_id'] = str(i['_id']) | 291 | i['_id'] = str(i['_id']) |
292 | d[cntr] = i | 292 | d[cntr] = i |
… | … | ||
295 | response.headers['Access-Control-Allow-Origin'] = '*' | 295 | response.headers['Access-Control-Allow-Origin'] = '*' |
296 | return response | 296 | return response |
297 | 297 | ||
298 | @app.route('/feeds/write', methods=['POST']) | ||
299 | def save_feed(): | ||
300 | coll = g.db['feed'] | ||
301 | d = {} | ||
302 | d['about'] = request.form['about'] | ||
303 | d['blog'] = request.form['blog'] | ||
304 | d['bxpath'] = request.form['bxpath'] | ||
305 | d['xpath'] = request.form['xpath'] | ||
306 | d['author'] = request.form['author'] | ||
307 | coll.insert(d) | ||
308 | response = make_response() | ||
309 | response.data = repr(request.form['blog']) | ||
310 | response.headers['Access-Control-Allow-Origin'] = '*' | ||
311 | return response | ||
298 | 312 | ||
299 | import logging,os | 313 | import logging,os |
300 | from logging import FileHandler | 314 | from logging import FileHandler |
server/templates/feeds.html
4 | <script type="text/javascript"> | 4 | <script type="text/javascript"> |
---|---|---|---|
5 | $.getJSON("http://127.0.0.1:5000/feed", function(data) | 5 | $.getJSON("http://127.0.0.1:5000/feed", function(data) |
6 | { | 6 | { |
7 | d = $.makeArray(data); | ||
8 | d.reverse(); | ||
7 | str = ""; | 9 | str = ""; |
10 | console.log(d[0]); | ||
8 | $.each(data, function(i, val) | 11 | $.each(data, function(i, val) |
9 | { | 12 | { |
10 | if(val['about'] != undefined && val['about'] != 'undefined' && val['author'] != 'undefined' ) | 13 | if(val['about'] != undefined && val['about'] != 'undefined' && val['author'] != 'undefined' ) |
… | … | ||
18 | </script> | 18 | </script> |
19 | </head> | 19 | </head> |
20 | <body style="text-wrap:normal"> | 20 | <body style="text-wrap:normal"> |
21 | @<input type="text" id="t1" name="author" value="author" /> says <input type="text" id="t2" name="about" value="about" /> <input type="text" id="t3" name="xpath" value="xpath" /> is related to <input type="text" id="t4" name="blog" value="blog" /> <input type="text" id="t5" name="bxpath" value="bxpath" /> <input type="submit" id="post" name="alipi" value="Feed" onclick="postForm();" /> | ||
21 | <div id="feeds"> | 22 | <div id="feeds"> |
22 | </div> | 23 | </div> |
24 | <script type="text/javascript"> | ||
25 | function postForm() | ||
26 | { | ||
27 | console.log("here"); | ||
28 | var arr = {}; | ||
29 | arr['author'] = $('#t1').val(); | ||
30 | arr['about'] = $('#t2').val(); | ||
31 | arr['xpath'] = $('#t3').val(); | ||
32 | arr['blog'] = $('#t4').val(); | ||
33 | arr['bxpath'] = $('#t5').val(); | ||
34 | $.post("http://127.0.0.1:5000/feeds/write", arr, function(data) | ||
35 | { | ||
36 | alert("Posted"); | ||
37 | }); | ||
38 | } | ||
39 | </script> | ||
23 | </body> | 40 | </body> |
24 | </html> | 41 | </html> |