コード例 #1
0
def addJournal():
    msg = ""
    try:
        print("inside of addjournal")
        title = request.form['title']
        date = request.form['date']
        author = request.form['author']
        tag = request.form['tag']
        emotion = request.form['emotion']
        content = request.form['content']

        con = dbconnection()
        cur = con.cursor()
        cur.execute(
            "INSERT INTO Journal(title, date, content, author, emotion, tag) VALUES(?, ?, ?, ?, ?, ?)",
            (title, date, content, author, emotion, tag))
        print("about to commit")
        con.commit()
        msg = "Journal successfully saved"

    except Error as e:
        print("Error, can not upload" + e)
    finally:
        # cur.close()
        # con.close()
        return render_template("result.html", msg=msg)
コード例 #2
0
def updateJournal():
    msg = ""
    try:
        _id = request.form['id']
        title = request.form['title']
        date = request.form['date']
        # author = request.form['author']
        tag = request.form['tag']
        emotion = request.form['emotion']
        content = request.form['content']
        print(_id, title, date, tag)

        con = dbconnection()
        cur = con.cursor()
        cur.execute(
            "UPDATE Journal SET title = ?, date = ?, content = ?, emotion = ?, tag = ? WHERE id = ?",
            (title, date, content, emotion, tag, _id))
        con.commit()
        msg = "Update Successful"
        return redirect("/thoughts")
    except Error as e:
        print("Error" + e)
        con.rollback()
        msg = "There is an error, rollback time."
    finally:
        cur.close()
        con.close()
コード例 #3
0
def findAllJournals():
    con = dbconnection()
    con.row_factory = sqlite3.Row
    cur = con.cursor()
    cur.execute("SELECT * FROM Journal")
    rows = cur.fetchall()
    return rows
コード例 #4
0
ファイル: app.py プロジェクト: JamesStyles101/FlaskJounal
def addJournal():
    msg = ""
    try:
        # Insert to DB
        title = request.form['title']
        date = request.form['date']
        author = request.form['author']
        tag = request.form['tag']
        emotion = request.form['emotion']
        content = request.form['content']
        print("Everything parsed!")

        con = dbconnection()
        cur = con.cursor()
        cur.execute(
            "INSERT INTO Journal(title, date, author, tag, emotions, content) VALUES(?,?,?,?,?,?); ",
            (title, date, author, tag, emotion, content))

        con.commit()
        print("Data inserted!")
        msg = "Journal successfully saved"
        return redirect("/journals")
    except Error as e:
        print("Hey there is an error: " + e)
        msg = e
    finally:
        # cur.close()
        # con.close()
        return render_template("result.html", msg=msg)
コード例 #5
0
def get_dict_resultset(sql):
    conn = dbconnection()
    cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
    cur.execute(sql)
    ans =cur.fetchall()
    dict_result = []
    for row in ans:
        dict_result.append(dict(row))
    return dict_result
コード例 #6
0
ファイル: app.py プロジェクト: JamesStyles101/FlaskJounal
def deleteJournal(id):
    try:
        con = dbconnection()
        cur = con.cursor()
        cur.execute("DELETE FROM Journal WHERE id = ?", (str(id), ))
        con.commit()
        msg = "Journally succesfully deleted!"
        return render_template("result.html", msg=msg)
    except Error as e:
        print("Error " + e)
        con.rollback()
        msg = "There is an error while deleting this journal"
    finally:
        cur.close()
        con.close()
コード例 #7
0
def deleteJournal(id):

    try:
        con = dbconnection()
        cur = con.cursor()
        cur.execute("DELETE FROM Journal WHERE id= ?", (str(id), ))
        con.commit()
        msg = "Journal deleted"
        return redirect("/thoughts")
    except Error as e:
        print("There is an error" + e)
        con.rollback()
        msg = "Error with deleting content"
    finally:
        cur.close()
        con.close()
コード例 #8
0
ファイル: app.py プロジェクト: JamesStyles101/FlaskJounal
def editJournal(id):
    try:
        con = dbconnection()
        cur = con.cursor()
        cur.execute("SELECT * FROM Journal WHERE id = ?", (str(id), ))
        row = cur.fetchone()
        if row:
            return render_template("editJournal.html", aJournal=row)
        else:
            msg = "Cannot find the journal with this id"
    except Error as e:
        print("There is an error " + e)
        msg = e
    finally:
        cur.close()
        con.close()
コード例 #9
0
ファイル: contact.py プロジェクト: srinivasanU/flask_crud
import psycopg2
from db import dbconnection
from conversion import get_dict_resultset
import sys

conn = dbconnection()
cur = conn.cursor()

Option_list = [
    'Option 1 . Add', 'Option 2 . Update', 'Option 3 . List',
    'Option 4 . Delete', 'Option 5 . Exit'
]


def looper():
    for i in Option_list:
        print i
    print '#######################################'
    input_option = input("Enter a Option Number: ")
    options(int(input_option))


def create_option():
    firstname = raw_input("Enter the Firstname : ")
    lastname = raw_input("Enter the Lastname : ")
    phone_no = raw_input("Enter the Phone Number : ")
    cur.execute(
        "insert into contacts (firstname,lastname,phone_no) values(%s,%s,%s)",
        (firstname, lastname, phone_no))
    conn.commit()
    print '#######################################'
コード例 #10
0
ファイル: main.py プロジェクト: KarlovAV/DirectumRxLoadData
    results = jobs.get_job_with_filter(dbconn, performer, discriminator, filter)
    return response.get_scalar_result(results)


@app.route('/docs/<uuid:discriminator>/<int:author>', methods=['GET'])
def get_doc(author, discriminator):
    results = docs.get_doc_with_filter(dbconn, author, discriminator)
    return response.get_scalar_result(results)


@app.route('/docs/<int:author>', methods=['GET'])
def get_any_doc(author):
    results = docs.get_any_doc(dbconn, author)
    return response.get_scalar_result(results)


if __name__ == '__main__':
    parser = ArgumentParser()
    parser.add_argument("-e", "--engine", dest="engine", help="set sql engine")
    parser.add_argument("-ht", "--host", dest="host", help="set sql host")
    parser.add_argument("-d", "--db", dest="dbname", help="set db nane")
    parser.add_argument("-n", "--user", dest="username", help="set user name for connect to db")
    parser.add_argument("-p", "--pwd", dest="password", help="set user name password")
    parser.add_argument("-pr", "--port", dest="port", help="port", default=None)
    args = parser.parse_args()
    print(args)
    dbconn = db.dbconnection(args.engine, args.host, args.dbname, args.username, args.password, args.port)
    app.debug = True  # enables auto reload during development
    app.run(host='0.0.0.0', port=5555)
    app.run()