Ejemplo n.º 1
0
def init_db():
    dbi.cache_cnf()
    dbi.use('uwushu_db')
Ejemplo n.º 2
0
#FindASubstitute
#Bianca Pio, Alexandra Bullen-Smith, Margaret Harrigan
#CS 304 Final Project
#Submitted May 13, 2020
#data.py is the python file containing functions to navigate the database

import database
import cs304dbi as dbi

dsn = dbi.cache_cnf()
dbi.use('findasubstitute_db')


#sees if an entered username already exists
def usernameAvailability(conn, username):
    curs = dbi.dict_cursor(conn)
    sql = 'select * from employee1 where username = %s'
    vals = [username]
    curs.execute(sql, vals)
    available = curs.fetchall()
    if (len(available) == 1):
        return True  #username already exists
    else:
        return False  #unique username


def emailAvailability(conn, email):
    curs = dbi.dict_cursor(conn)
    sql = 'select * from employee1 where email = %s'
    vals = [email]
    curs.execute(sql, vals)
Ejemplo n.º 3
0

'''URL for profiles on network, visible to other users.'''


@app.route("/profile/<userID>")
def alumnusPage(userID):
    conn = dbi.connect()
    profileInfo = sqlOperations.profileInfo(conn, userID)
    return render_template("alumnus.html", result=profileInfo)


if __name__ == '__main__':

    import sys, os
    if len(sys.argv) > 1:
        # arg, if any, is the desired port number
        print(sys.argv[1])
        port = int(sys.argv[1])

        assert (port > 1024)
        if not (1943 <= port <= 1950):
            print('For CAS, choose a port from 1943 to 1950')
            sys.exit()
    else:
        port = os.getuid()
        cnf = dbi.cache_cnf()  # defaults to ~/.my.cnf
        dbi.use(nameDB)
        conn = dbi.connect()
    app.debug = True
    app.run('0.0.0.0', port)
Ejemplo n.º 4
0
def init_db():
    dbi.cache_cnf()
    dbi.use('techship_db')
Ejemplo n.º 5
0
        return render_template('form_data.html',
                               method=request.method,
                               form_data={})


@app.route('/testform/')
def testform():
    return render_template('testform.html')


if __name__ == '__main__':
    import sys, os
    if len(sys.argv) > 1:
        # arg, if any, is the desired port number
        port = int(sys.argv[1])
        assert (port > 1024)
    else:
        port = os.getuid()
    # the following database code works for both PyMySQL and SQLite3
    dbi.cache_cnf()
    dbi.use('wmdb')
    conn = dbi.connect()
    curs = dbi.dict_cursor(conn)
    # the following query works for both MySQL and SQLite
    curs.execute('select current_timestamp as ct')
    row = curs.fetchone()
    ct = row['ct']
    print('connected to WMDB at {}'.format(ct))
    app.debug = True
    app.run('0.0.0.0', port)
Ejemplo n.º 6
0
        song id, title, artist, and album for a song in that genre
    '''
    curs = dbi.dict_cursor(conn)
    genre = '%' + genre + '%'
    curs.execute(
        '''select song_id, song_title, 
        artist_name, artist_id, 
        album_title, album_id from coda_song
        join coda_album using(album_id)
        join coda_artist using(artist_id)
        where coda_song.genre like %s''', [genre])
    genreDictList = curs.fetchall()
    return genreDictList


# ==========================================================
# This starts the ball rolling, *if* the file is run as a
# script, rather than just being imported.

if __name__ == '__main__':
    dbi.cache_cnf()  # defaults to ~/.my.cnf
    dbi.use('coda_db')
    conn = dbi.connect()
    # songInfo = get_song(conn, 1)

    # genres = get_genres(conn)
    # print(genres)

    # countrySongs = songs_by_genre(conn, 'Christmas')
    # print(countrySongs)
Ejemplo n.º 7
0
def init_db():
    dbi.cache_cnf()
    dbi.use('foodie_db')  # or whatever db
Ejemplo n.º 8
0
def startup():
    dbi.cache_cnf()
    dbi.use('zipvote_db')
Ejemplo n.º 9
0
    results = curs.fetchall()
    return results


def allowed_file(filename):
    '''Helper function for uploadSyllabus that checks if the file is a pdf'''
    return '.' in filename and \
           filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


def saveToDB(x, aFile):
    '''Helper function for uploadSyllabus that puts the file name in the database'''
    try:
        conn = dbi.connect()
        curs = dbi.dict_cursor(conn)
        curs.execute(
            '''
                INSERT into syllabi(cid, filename) VALUES (%s, %s)
                    ON DUPLICATE KEY UPDATE filename = %s''',
            [x, aFile, aFile])
        conn.commit()
        flash('Upload successful')
    except Exception as err:
        flash('Upload failed {why}'.format(why=err))


if __name__ == '__main__':
    dbi.cache_cnf()  # defaults to ~/.my.cnf
    dbi.use('syllabo_db')
    conn = dbi.connect()
Ejemplo n.º 10
0
Archivo: app.py Proyecto: audreah/coda
def init_db():
    dbi.cache_cnf()
    dbi.use('coda_db')
Ejemplo n.º 11
0
from flask import (Flask, render_template, make_response, url_for, request,
                   redirect, flash, session, send_from_directory, jsonify)
from werkzeug.utils import secure_filename
import pymysql
import cs304dbi as dbi
dsn = dbi.cache_cnf()
dbi.use('whealth_db')

app = Flask(__name__)

import random

app.secret_key = 'your secret here'
# replace that with a random key
app.secret_key = ''.join([
    random.choice(('ABCDEFGHIJKLMNOPQRSTUVXYZ' + 'abcdefghijklmnopqrstuvxyz' +
                   '0123456789')) for i in range(20)
])

# This gets us better error messages for certain common request errors
app.config['TRAP_BAD_REQUEST_ERRORS'] = True

staffID = 1409


@app.route('/')
def index():
    return render_template('main.html')


@app.route('/suggest/', methods=["GET", "POST"])
Ejemplo n.º 12
0
def is_username_unique(conn, username):
    # Checks if username is unique while user is registering.
    curs = dbi.cursor(conn)
    sql = '''select * from user where uid = %s;'''
    result = curs.execute(sql, [username])
    conn.commit()
    if result == None: 
        #username doesn't exist in db, so we can continue with registration
        return False
    else:
        return True

if __name__ == '__main__':
    dbi.cache_cnf()   # defaults to ~/.my.cnf
    dbi.use('techship_db') 
    conn = dbi.connect()
    # print("By Company:")
    # print(getByCompany(conn,"Google"))
    # print("By Role:")
    # print(getByRole(conn,"Software Engineering"))
    # print("By Experience:")
    
    # fav = handleFavorite('jamie', 'https://careers.google.com/jobs/results/100877793807475398-software-engineering-intern-associates-summer-2021/')

    # test = getFavorites(conn, 'jamie')
    # print(test)

    # print(getByExperience(conn, "Senior"))
    # insertApplication("http://www.test.com","test","Data Science","Fall","2022","Freshman")
    # insertCompany("test2")
Ejemplo n.º 13
0
def init_db():
    dbi.cache_cnf()
    dbi.use('sclark4_db')  # or whatever db
Ejemplo n.º 14
0
def startup():
    dbi.cache_cnf()
    dbi.use('tbanerji_db')
Ejemplo n.º 15
0
def init_db():
    dbi.cache_cnf()
    dbi.use('housemate_db') 
Ejemplo n.º 16
0
        '''
        SELECT user.name,`datetime`,content,title FROM post
        INNER JOIN user ON user.userID=authorID WHERE post.content like %s or post.title like %s;
        ''', ['%' + keyword + "%", '%' + keyword + "%"])
    return curs.fetchall()


def updatePost(conn, postID, title, content):
    '''Edits post with specified postID and given information.'''
    curs = dbi.dict_cursor(conn)
    curs.execute(
        '''
        UPDATE post
        SET title=%s, content=%s
        WHERE postID=%s;''', [title, content, postID])
    conn.commit()


def deletePost(conn, postID):
    '''Deletes post with specified postID.'''
    curs = dbi.dict_cursor(conn)
    curs.execute('''
        DELETE from post WHERE postID=%s
    ''', [postID])
    conn.commit()


if __name__ == '__main__':
    dbi.cache_cnf()
    dbi.use('wcscdb_db')
    conn = dbi.connect()