Esempio n. 1
0
 def testInsert(self):
     title = hmac.new(bytearray('signature','utf-8'), bytearray(str(random.random()),'utf-8'), hashlib.sha256).hexdigest()
     name = hmac.new(bytearray('signature','utf-8'), bytearray(str(random.random()),'utf-8'), hashlib.sha256).hexdigest()
     post = hmac.new(bytearray('signature','utf-8'), bytearray(str(random.random()),'utf-8'), hashlib.sha256).hexdigest()
     DB.create_db();
     DB.insert_db(title, name, post)
     res = DB.getpostbyname(title)
     flag = False
     if (res[0]==title and res[1]==name and res[2]==post):
         flag = True
     self.assertTrue(flag)
Esempio n. 2
0
    def getUidByUname(uname):
        if (uname is None):
            return None

        conn = DB()
        uname = conn.escape(uname)

        rows = conn.query("SELECT * FROM User WHERE uname='%s' " % (uname))
        if len(rows) < 1:
            return None

        return rows[0]['uid']
Esempio n. 3
0
 def testDbInsert(self):
     title = hmac.new(bytearray('signature','utf-8'), bytearray(str(random.random()),'utf-8'), hashlib.sha256).hexdigest()
     name = hmac.new(bytearray('signature','utf-8'), bytearray(str(random.random()),'utf-8'), hashlib.sha256).hexdigest()
     post = hmac.new(bytearray('signature','utf-8'), bytearray(str(random.random()),'utf-8'), hashlib.sha256).hexdigest()
     flask_db = DB()
     DB.load_config(flask_db,['../app/config.ini'])
     DB.create_db(flask_db);
     DB.insert(flask_db, title, name, post)
     res = DB.getpostbyname(flask_db, title)
     flag = False
     if (res[0]==title and res[1]==name and res[2]==post):
         flag = True
     self.assertTrue(flag)
Esempio n. 4
0
    def checkUser(uname, pwd):
        print("check user", uname, pwd)
        if (uname is None) or (pwd is None):
            return False

        conn = DB()
        uname = conn.escape(uname)
        pwd = conn.escape(pwd)
        rows = DB().query(
            "SELECT * FROM User WHERE uname='%s' AND password='******'" %
            (uname, pwd))
        if len(rows) < 1:
            return False

        uid = rows[0]['uid']

        if uid is None:
            return False

        return True
Esempio n. 5
0
def post_processing(request):
    title = html.unescape(request.form['title'])
    name = html.unescape(request.form['name'])
        
    title = re.sub(r'\<[^>]*\>', '', title)
    name = re.sub(r'\<[^>]*\>', '', name)
        
    json_p = json.loads( html.unescape(request.form['post']) )
    post = ''
    for p in json_p:
        if json_p[p]['type'] == "text":
            cont = urllib.request.unquote(json_p[p]['content'])
            cont = re.sub(r'\<[^>]*\>', '', cont)
            post += '<p>' + cont + '</p>' 
        elif json_p[p]['type'] == "youtube":
            post += '<p>' + urllib.request.unquote(json_p[p]['content']) + '</p>' 
    res = DB().insert_db(title, name, post)
    return '/' + title
    
Esempio n. 6
0
#! /usr/bin/python2.7

from flask import Flask, render_template, request
from app.Article import Article
from app.DB import DB
from app.Parser import Parser

app = Flask(__name__)
app.config["DEBUG"] = True  # Only include this while you are testing your app

# Initialize db
db = DB(purge=False)

# Initialize parser
parser = Parser(db)

# Initialize watch list
watch_list = []


@app.route("/", methods=['GET'])
def get_watchlist():
    if watch_list:
        art = db.get_articles(watch_list)
    else:
        global watch_list
        watch_list = list(set(watch_list))
        art = db.get_general_articles()

    print watch_list
    return render_template('layout.html', articles=art)
Esempio n. 7
0
 def testDbCheck(self):
     flask_db = DB()
     DB.load_config(flask_db,['../app/config.ini'])
     flag = DB.check(flask_db)
     self.assertTrue(flag)
Esempio n. 8
0
def show_post(postname):
    res = DB().getpostbyname(postname)
    return render_template('post.html', res=res).replace("!!!Post!!!", res[2])
Esempio n. 9
0
def create_db():
    return DB().create_db()
Esempio n. 10
0
def show_db():
    return DB().show_db()
Esempio n. 11
0
from flask import Flask, request, redirect
from flask.templating import render_template
from app.DB import DB
from app.core import *

DEBUG = False

app = Flask(__name__)
flask_db = DB()


@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == 'GET':
        return render_template('index.html')

    elif request.method == 'POST':
        return post_processing(request, flask_db)


@app.route('/admin', methods=['GET', 'POST'])
def admin():
    return render_template('admin.html')


@app.route('/<postname>', methods=['GET'])
def show_post(postname):
    res = DB.getpostbyname(flask_db, postname)
    return render_template('post.html', res=res).replace("!!!Post!!!", res[2])