From 7b90e1f15007931fa31d4df0a5e401f5e348e155 Mon Sep 17 00:00:00 2001 From: Zachary Hanif Date: Sat, 9 Nov 2019 15:47:29 -0500 Subject: [PATCH] added documentation, removed SQLAlchemy. --- install/development_setup | 27 +++++++++++++++++++++++++-- src/server.py | 18 ++++++------------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/install/development_setup b/install/development_setup index a558a6a..62cd6b6 100644 --- a/install/development_setup +++ b/install/development_setup @@ -1,9 +1,32 @@ +ssh -i ~/Downloads/DNS.pem ubuntu@ec2-18-191-73-24.us-east-2.compute.amazonaws.com +# Install Packages +sudo apt-get update +sudo apt-get install python3-pip +sudo apt-get install python3-venv +sudo apt-get install postgresql-server-dev-10 + +git clone https://github.com/zhanif3/818_search.git + # First, install the needed python environnment -virtenv env +cd 818_search +python3 -m venv env # Run the virtual environment source env/bin/activate # Install needed python packages -pip install pipfile +(env)$ pip install flask +(env)$ pip install psycopg2 + + +# Set up the database (DO NOT DO THIS ON AWS SERVER) +# sudo -u postgres psql +sudo -u postgres createuser --interactive + 818project, y +sudo -u postgres createdb sammy +sudo adduser sammy +sudo -i -u sammy +psql +# What DB am I connected to? +\conninfo \ No newline at end of file diff --git a/src/server.py b/src/server.py index 742c982..ac8aac7 100644 --- a/src/server.py +++ b/src/server.py @@ -1,6 +1,5 @@ from flask import Flask - -from flask.ext.sqlalchemy import SQLAlchemy +import psycopg2 import os app = Flask(__name__) @@ -10,16 +9,6 @@ POSTGRES_URL = "127.0.0.1:5432" POSTGRES_DB = "project" -DB_URL = 'postgresql+psycopg2://{user}:{pw}@{url}/{db}'.format(user=POSTGRES_USER,pw=POSTGRES_PW,url=POSTGRES_URL,db=POSTGRES_DB) - -app.config['SQLALCHEMY_DATABASE_URI'] = DB_URL - -db = SQLAlchemy(app) - -class Experiment(db.Model): - id = db.Column(db.Integer, primary_key=True) - experiment_data = db.Column(db.String(200), unique=False, nullable=True) - @app.route('/upload', methods=['GET', 'POST']) def upload(): if flask.request.method == 'POST': @@ -44,3 +33,8 @@ def hello(): if __name__ == '__main__': app.run(debug=True, host='0.0.0.0') + # Connect to an existing database + conn = psycopg2.connect("dbname=test user=postgres") + + # Open a cursor to perform database operations + cur = conn.cursor()