Exemple #1
0
def load_pieces():
    """Load pieces from piece.txt into database."""

    print "Pieces"

    for i, row in enumerate(open("data/piece.txt")):
        row = row.rstrip()

        title, pg_id, comp, lyr, pub_yr, onv, ov, lang, oi, to, te, d = row.split(
            ", ")

        piece = Piece(title=title,
                      page_id=pg_id,
                      composer=comp,
                      lyricist=lyr,
                      publication_year=pub_yr,
                      original_num_voices=onv,
                      original_voicing=ov,
                      original_language=lang,
                      original_instrumentation=oi,
                      text_original=to,
                      text_english=te,
                      description=d)

        # Add to the session.
        db.session.add(piece)

    # Commit the session/data to the dbase.
    db.session.commit()
Exemple #2
0
def post():
	if request.method == 'GET':
		return render_template('/post.html')
	else:
		pic_url=request.form.get('pic_url')
		description = request.form.get('description')
		piece=Piece(pic_url = pic_url, description = description)
		session.add(piece)
		session.commit()
		return redirect(url_for('my_feed'))
Exemple #3
0
def create_piece():
    global active_piece
    type = choice(ALL_PIECES)
    active_piece = Piece("*", type, (4, 0), b)
    active_piece_sprites.clear()
    colour = choice(COLOURS)
    for p in active_piece:
        sprite = scene.layers[1].add_sprite("tile",
                                            pos=grid_to_screen(*p),
                                            color=colour,
                                            scale=0.75)
        active_piece_sprites.append(sprite)
Exemple #4
0
def process_form():

    # gets data from piece form
    user_id = current_user.user_id
    clothing_type = request.form.get("clothing_type")
    img_url = request.form.get("img_url")
    categories = request.form.getlist("category")
    c_id = request.form.get("c_id")
    desc = request.form.get("desc")
    other_desc = request.form.get("other_desc")
    cost = request.form.get("cost")

    if other_desc:
        desc = other_desc

    new_piece = Piece(times_worn=0,
                      desc=desc,
                      clothing_type=clothing_type,
                      user_id=user_id,
                      img_url=img_url,
                      cost=cost,
                      cost_per_use=cost)

    db.session.add(new_piece)
    db.session.commit()

    for item in categories:
        check_category = Category.query.filter(Category.category == item)
        check_category = check_category.first()

        # creates new category in categories table
        if not check_category:
            check_category = Category(category=item)
            db.session.add(check_category)
            db.session.commit()

        new_category_piece = CategoryPiece(piece_id=new_piece.piece_id,
                                           cat_id=check_category.cat_id)
        db.session.add(new_category_piece)
        db.session.commit()

    print("\nPOST REQUEST IS HAPPENING\n")

    return c_id
Exemple #5
0
def add_piece(ttl, pg_id, comp, lrc, pb_yr, onv, ov, ol, oi, to, te, desc):
    """Adds piece to the database."""

    piece = Piece(title=ttl,
                  page_id=pg_id,
                  composer=comp,
                  lyricist=lrc,
                  publication_year=pb_yr,
                  original_num_voices=onv,
                  original_voicing=ov,
                  original_language=ol,
                  original_instrumentation=oi,
                  text_original=to,
                  text_english=te,
                  description=desc)

    # Add to the session.
    db.session.add(piece)

    # Commit the session/data to the dbase.
    db.session.commit()

    return piece.piece_id
Exemple #6
0
from model import Base, User, Piece
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine('sqlite:///project.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
new_user = User(username = "******", p)

new_piece = Piece(title="Test Title", description="Test Description", pic_url="http://www.louvre.fr/sites/default/files/imagecache/940x768/medias/medias_images/images/louvre-portrait-de-lisa-gherardini-epouse-de-francesco-del-giocondo-dite-monna-lisa-la-gioconda-ou-la-jocon.jpg")
Exemple #7
0
def process_piece(row):
    """Load pieces from webpage into database."""

    data = row.find_all('td')

    title = data[1].string
    composer_name = data[2].string
    composer_id = db.session.query(
        Composer.composer_id).filter(Composer.name == composer_name).one()[0]

    period_str = data[3].encode('utf8').lstrip('<td>').rstrip(
        '</td>').strip().lower()
    if len(period_str) > 2:
        period = period_str[0].upper() + period_str[1:]
    else:
        period = None

    level = None
    key = None
    tonality = None

    if data[4].string == 'Prep':
        level = 0
    elif data[4].string != None:
        level = int(str(data[4].string))

    if ' in ' in title:
        split = title.split(' ')
        string = split[split.index('in') + 1].rstrip(',.:)"')
        lowerstring = string.lower()

        try:
            string_next = split[split.index('in') + 2].rstrip(',.:)"')
        except Exception as e:
            string_next = ''

        if 'C sharp' in title or 'C-sharp' in title:
            key = "c#"
        elif 'F sharp minor' in title:
            key = "f#"
        elif "B flat Minor" in title:
            key = "bb"
        elif string_next.lower() == 'minor' or string_next.lower() == 'min':
            key = lowerstring
        elif string_next.lower() == 'sharp':
            key = string + '#'
        elif string_next.lower() == 'flat':
            key = string + 'b'
        elif len(string) == 1 and string != ' ':
            key = string
        elif len(string) == 2 and (string[1] == '#' or string[1] == 'b'):
            key = string
        elif len(string) > 2:
            if string[1] == ',':
                key = string[0]
            elif 'sharp' in string:
                key = string[0] + '#'
            elif 'flat' in string:
                key = string[0] + 'b'
        else:
            key = None
    else:
        key = None

    if key != None:
        if key[0].isupper():
            tonality = 'Major'
        else:
            tonality = 'Minor'

    piece = Piece(title=title,
                  composer_id=composer_id,
                  period=period,
                  level=level,
                  key=key,
                  tonality=tonality)

    return piece