Commit bed05e171f3cfb595a25a8567e9887242b7e68b9
- Diff rendering mode:
- inline
- side by side
server/alipi.py
(19 / 15)
  | |||
1 | from flask import Flask | ||
2 | from flask import request | ||
3 | from flask import render_template | ||
4 | import lxml.html | ||
5 | import pymongo | ||
1 | #-*-coding: utf-8 -*- | ||
2 | from flask import Flask, request, render_template, g, redirect, jsonify, make_response | ||
6 | 3 | from bson import Code | |
7 | import urllib2 | ||
8 | import StringIO | ||
9 | from flask import g | ||
10 | from flask import redirect | ||
11 | from urllib import quote_plus | ||
12 | from urllib import unquote_plus | ||
13 | import conf | ||
14 | import oursql | ||
15 | from flask import jsonify | ||
4 | from urllib import quote_plus, unquote_plus | ||
5 | import urllib2, StringIO, lxml.html, pymongo, conf, oursql | ||
16 | 6 | app = Flask(__name__) | |
17 | 7 | @app.before_request | |
18 | 8 | def first(): | |
… | … | ||
286 | 286 | coll = g.db['post'] | |
287 | 287 | d = {} | |
288 | 288 | cntr = 0 | |
289 | for i in coll.find(): | ||
289 | for i in coll.find().sort('_id',direction=-1): | ||
290 | 290 | if i['data'] != '<br/>': | |
291 | 291 | i['_id'] = str(i['_id']) | |
292 | 292 | d[cntr] = i | |
… | … | ||
295 | 295 | response.headers['Access-Control-Allow-Origin'] = '*' | |
296 | 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 | 313 | import logging,os | |
300 | 314 | from logging import FileHandler |
server/templates/feeds.html
(20 / 0)
  | |||
4 | 4 | <script type="text/javascript"> | |
5 | 5 | $.getJSON("http://127.0.0.1:5000/feed", function(data) | |
6 | 6 | { | |
7 | d = $.makeArray(data); | ||
8 | d.reverse(); | ||
7 | 9 | str = ""; | |
10 | console.log(d[0]); | ||
8 | 11 | $.each(data, function(i, val) | |
9 | 12 | { | |
10 | 13 | if(val['about'] != undefined && val['about'] != 'undefined' && val['author'] != 'undefined' ) | |
… | … | ||
18 | 18 | </script> | |
19 | 19 | </head> | |
20 | 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 | 22 | <div id="feeds"> | |
22 | 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 | 40 | </body> | |
24 | 41 | </html> |