Beispiel #1
0
def view_character():
    DA = DataAccess()
    abilities = DA.getAbilities().all()
    weaknesses = DA.getWeaknesses().all()
    perks = DA.getPerks().all()
    flaws = DA.getFlaws().all()
    return render_template('view_character.html', abilities=abilities, weaknesses=weaknesses,
                           perks=perks, flaws=flaws)
Beispiel #2
0
def add_character_to_game_json():
    DA = DataAccess()
    messageList = {}
    messageList[0] = {}
    char_id = request.args.get('char_id', 0, type=str)
    game_id = request.args.get('game_id', 0, type=str)
    ret = DA.addCharacterToGame(game_id, char_id)
    messageList[0]['message'] = ret
    
    return jsonify(messageList)
Beispiel #3
0
def character_edit():
    if 'username' not in session:
        return render_template('login_required.html', message='edit this character')
    DA = DataAccess()
    abilities = DA.getAbilities().all()
    weaknesses = DA.getWeaknesses().all()
    perks = DA.getPerks().all()
    flaws = DA.getFlaws().all()
    return render_template('character_edit.html', abilities=abilities, weaknesses=weaknesses,
                           perks=perks, flaws=flaws)
Beispiel #4
0
def remove_character_from_game_json():
    DA = DataAccess()
    messageList = {}
    messageList[0] = {}
    char_id = request.args.get('char_id', 0, type=str)
    game_id = request.args.get('game_id', 0, type=str)
    ret = DA.removeCharacterFromGame(game_id, char_id)
    messageList[0]['message'] = ret
    
    return jsonify(messageList)
Beispiel #5
0
def get_games_json():
    DA= DataAccess()
    games = DA.getGames()
    gameList = {}

    for game in games:
        gameList[game.id] = {}
        gameList[game.id]['owner_id'] = game.owner_id
        gameList[game.id]['name'] = game.name

    return jsonify(gameList)
Beispiel #6
0
def all_perks_json():
    DA = DataAccess()
    perks = DA.getPerks().all()
    
    perk_info = {}
    for a in perks:
        perk_info[a.id] = {}
        perk_info[a.id]['id'] = a.id
        perk_info[a.id]['name'] = a.name

    return jsonify(perk_info)
Beispiel #7
0
def all_weaknesses_json():
    DA = DataAccess()
    weaknesses = DA.getWeaknesses().all()
    
    weaknesses_info = {}
    for a in weaknesses:
        weaknesses_info[a.id] = {}
        weaknesses_info[a.id]['id'] = a.id
        weaknesses_info[a.id]['name'] = a.name

    return jsonify(weaknesses_info)
Beispiel #8
0
def all_flaws_json():
    DA = DataAccess()
    flaws = DA.getFlaws().all()
    
    flaw_info = {}
    for a in flaws:
        flaw_info[a.id] = {}
        flaw_info[a.id]['id'] = a.id
	flaw_info[a.id]['name'] = a.name

    return jsonify(flaw_info)
Beispiel #9
0
def create_game():
    DA = DataAccess()

    if request.method == 'POST':
        if 'owner_id' in request.form:
            owner_id = request.form['owner_id']
            name = request.form['game_name']
            game = DA.addGame(owner_id, name)
            return render_template('games.html')
        else:
            return render_template('games.html')
    else:
        return render_template('games.html')
Beispiel #10
0
def all_abilities_json():
    DA = DataAccess()
    abilities = DA.getAbilities().all()
    
    abilities_info = {}
    for a in abilities:
        abilities_info[a.id] = {}
        abilities_info[a.id]['id'] = a.id
        abilities_info[a.id]['name'] = a.name
        #abilities_info['abilities'].setdefault(a.id, {})['id'] = a.id
        #abilities_info['abilities'].setdefault(a.id, {})['name'] = a.name

    return jsonify(abilities_info)
Beispiel #11
0
def delete_game():
    DA = DataAccess()

    if request.method == 'POST':
        if 'game_id' in request.form:
            game_id = request.form['game_id']
            DA.deleteGame(game_id)
            #print 'game deleted'
            return render_template('games.html')
        else:
            return render_template('games.html')
    else:
        return render_template('games.html')
Beispiel #12
0
def get_add_rights_json():
    DA= DataAccess()
    game_owner = DA.getGameOwner(request.args.get('game_id', 0, type=str))
    user = request.args.get('user_id', 0, type=str)
    #print game_owner
    #print user
    rightsList = {}
    rightsList[0] = {}
    if user == game_owner:
        #print 'user is owner'
        rightsList[0]['can_add'] = 'Y'
    else:
        #print 'user not owner'
        rightsList[0]['can_add'] = 'N'

    return jsonify(rightsList)
Beispiel #13
0
def get_searched_characters_json():
    DA = DataAccess()
    characters_object = []

    name = request.args.get('char_name', 0, type=str)
    owner_name = request.args.get('owner_name', 0, type=str)
    
    ##print name
    #print owner_name
    
    characters_object = []
    
    if name == '':
	if owner_name != '':
	    #print 'just owner'
	    characters_object = DA.searchGameCharactersUserOnly(owner_name)
    if owner_name == '':
	if name != '':
	    #print 'just name'
	    characters_object = DA.searchGameCharactersNameOnly(name)
    
    if name != '' and owner_name != '':
	#print 'both'
	characters_object = DA.searchGameCharacters(name, owner_name)
    
    character_list = {}
    
    for char_obj in characters_object:
        character_list[char_obj.id] = {}
        character_list[char_obj.id]['char_id'] = char_obj.id
        character_list[char_obj.id]['user_id'] = char_obj.user_id
        character_list[char_obj.id]['name'] = char_obj.name
        character_list[char_obj.id]['combat_notes'] = char_obj.combat_notes
        character_list[char_obj.id]['defense'] = char_obj.defense
        character_list[char_obj.id]['health'] = char_obj.health
        character_list[char_obj.id]['endurance'] = char_obj.endurance
        character_list[char_obj.id]['tv'] = char_obj.tv
        character_list[char_obj.id]['background'] = char_obj.background
        character_list[char_obj.id]['appearance'] = char_obj.appearance
        character_list[char_obj.id]['personality'] = char_obj.personality
        character_list[char_obj.id]['other_notes'] = char_obj.other_notes
        character_list[char_obj.id]['portrait_url'] = char_obj.portrait_url
        character_list[char_obj.id]['icon_url'] = char_obj.icon_url
       
    ##print character_list
    return jsonify(character_list)
Beispiel #14
0
    def addClientCharacter(self, cchar):
        DA = DataAccess()
        session = DA.getSession()
        character = Character(user_id=cchar.user_id, name=cchar.name,
                        combat_notes=cchar.combat_notes, defense=cchar.defense,
                        health=cchar.health, endurance=cchar.endurance,
                        tv=cchar.tv, background=cchar.background,
                        appearance=cchar.appearance, personality=cchar.personality,
                        other_notes=cchar.other_notes)
        session.add(character)
        session.commit()
        cchar.id = character.id
        for at in cchar.attacks:
            attack = CharacterAttack(character_id=character.id, name=at.name,
                                roll=at.roll, dx=at.dx, end=at.end, note=at.note)
            session.add(attack)
            session.commit()
            for pk in at.perks:
                aperk = AttackPerk(perk_id=pk.perk_id, attack_id=attack.id,
                                   multiplier=pk.multiplier, note=pk.note)
                session.add(aperk)
                session.commit()
            for fl in at.flaws:
                aflaw = AttackFlaw(flaw_id=fl.flaw_id, attack_id=attack.id,
                                   multiplier=fl.multiplier, note=fl.note)
                session.add(aflaw)
                session.commit()

        for ab in cchar.abilities:
            cability = CharacterAbility(ability_id=ab.ability_id,
                               character_id=character.id,
                               ability_value=ab.value,
                               ability_note=ab.note)
            session.add(cability)
            session.commit()

        for wk in cchar.weaknesses:
            cweakness = CharacterWeakness(weakness_id=wk.weakness_id,
                               character_id=character.id,
                               weakness_value=wk.value,
                               weakness_note=wk.note)
            session.add(cweakness)
            session.commit()
        session.commit()

        print cchar.id
Beispiel #15
0
 def _importMetaData(self):
     from dataAccess import DataAccess
     dao = DataAccess()
     from xml.etree import ElementTree as et
     import os
     sensors = et.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'sensor_metadata.xml'))
     
     for sensor in sensors.getroot().findall("./sensor"):
         x = float(sensor.get('x', 0))
         y = float(sensor.get('y', 0))
         d = float(sensor.get('direction', 0))
         sid = int(sensor.get('id'))
         sql = "UPDATE `%s`" % (self._dao._sensorTable)
         sql += " SET `xCoord` = %(x)s, `yCoord` = %(y)s, `orientation` = %(d)s  WHERE `sensorId` = %(id)s" 
         args = {'x': x,
                 'y': y,
                 'd': d,
                 'id': sid}
         
         dao.saveData(sql, args)
Beispiel #16
0
 def _importMetaData(self):
     """ No longer used, merged data from the old sensors xml file into the database """
     from dataAccess import DataAccess
     dao = DataAccess()
     from xml.etree import ElementTree as et
     import os
     sensors = et.parse(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'sensor_metadata.xml'))
     
     for sensor in sensors.getroot().findall("./sensor"):
         x = float(sensor.get('x', 0))
         y = float(sensor.get('y', 0))
         d = float(sensor.get('direction', 0))
         sid = int(sensor.get('id'))
         sql = "UPDATE `%s`" % (self._dao._sensorTable)
         sql += " SET `xCoord` = %(x)s, `yCoord` = %(y)s, `orientation` = %(d)s  WHERE `sensorId` = %(id)s" 
         args = {'x': x,
                 'y': y,
                 'd': d,
                 'id': sid}
         
         dao.saveData(sql, args)
Beispiel #17
0
def character_list_json():
    DA = DataAccess()
    characters_object = DA.getCharacters(request.args.get('name', 0, type=str))
    character_list = {}
    
    for char_obj in characters_object:
        character_list[char_obj.id] = {}
        character_list[char_obj.id]['char_id'] = char_obj.id
        character_list[char_obj.id]['user_id'] = char_obj.user_id
        character_list[char_obj.id]['name'] = char_obj.name
        character_list[char_obj.id]['combat_notes'] = char_obj.combat_notes
        character_list[char_obj.id]['defense'] = char_obj.defense
        character_list[char_obj.id]['health'] = char_obj.health
        character_list[char_obj.id]['endurance'] = char_obj.endurance
        character_list[char_obj.id]['tv'] = char_obj.tv
        character_list[char_obj.id]['background'] = char_obj.background
        character_list[char_obj.id]['appearance'] = char_obj.appearance
        character_list[char_obj.id]['personality'] = char_obj.personality
        character_list[char_obj.id]['other_notes'] = char_obj.other_notes
        character_list[char_obj.id]['portrait_url'] = char_obj.portrait_url
        character_list[char_obj.id]['icon_url'] = char_obj.icon_url
       
    return jsonify(character_list)
Beispiel #18
0
def get_game_room_json():
    DA= DataAccess()
    characters = DA.getGameCharacters(request.args.get('game_id', 0, type=str))
    game_owner = DA.getGameOwner(request.args.get('game_id', 0, type=str))
    user = request.args.get('user_id', 0, type=str)
    #print game_owner
    #print user
    charList = {}

    for char in characters:
        charList[char.id] = {}
        charList[char.id]['owner_id'] = char.user_id
        charList[char.id]['char_name'] = char.name
        charList[char.id]['char_id'] = char.id
        if user == char.user_id:
            charList[char.id]['can_edit'] = 'Y'
        else:
            charList[char.id]['can_edit'] = 'N'
        if user == game_owner:
            charList[char.id]['can_remove'] = 'Y'
        else:
            charList[char.id]['can_remove'] = 'N'

    return jsonify(charList)
Beispiel #19
0
    def deleteClientCharacter(self, char_id):
        DA = DataAccess()
        session = DA.getSession()
        character = DA.getCharacter(char_id)
        if character != None:
            session.delete(character)
            for atk in DA.getCharAttacks(char_id):
                session.delete(atk)
                for pk in DA.getAttackPerks(atk.id):
                    session.delete(pk)
                for fl in DA.getAttackFlaws(atk.id):
                    session.delete(fl)

            for abi in DA.getCharAbilities(char_id):
                session.delete(abi)

            for wkn in DA.getCharWeaknesses(char_id):
                session.delete(wkn)

            session.commit()
Beispiel #20
0
import os
from dataAccess import DataAccess

from dotenv import load_dotenv
from flask import Flask, jsonify, request
from flask_cors import CORS

port = int(os.getenv('PORT', 3000))

app = Flask(__name__)
CORS(app)

dataAccess = DataAccess()


@app.route('/api/votes', methods=['POST'])
def api_post_votes():
    try:
        json_data = request.get_json()

        dataAccess.addVote(float(json_data['latitude']),
                           float(json_data['longitude']),
                           int(json_data['vote']),
                           "Foundation Technopark Zurich")

        return jsonify({}), 201
    except Exception as e:
        return jsonify(**{"error": e})


@app.route('/api/votes', methods=['GET'])
Beispiel #21
0
    def getClientCharacter(self, char_id):
        DA = DataAccess()
        char = DA.getCharacter(char_id)
        ability_list = []
        for ab in DA.getCharAbilities(char.id):
            ability_list.append(ClientAbility(ab.ability_id, DA.getAbilityDetails(ab.ability_id).name,
                                              ab.ability_value, ab.ability_note))

        weakness_list = []
        for wk in DA.getCharWeaknesses(char.id):
            weakness_list.append(ClientWeakness(wk.weakness_id,DA.getWeaknessDetails(wk.weakness_id).name,
                                                wk.weakness_value, wk.weakness_note))

        attack_list = []
        for at in DA.getCharAttacks(char.id):
            perks = []
            for pk in DA.getAttackPerks(at.id):
                perks.append(ClientPerk(pk.perk_id, DA.getPerkDetails(pk.perk_id).name, pk.multiplier, pk.note))
            flaws = []
            for fl in DA.getAttackFlaws(at.id):
                flaws.append(ClientFlaw(fl.flaw_id, DA.getFlawDetails(fl.flaw_id).name, fl.multiplier, fl.note))
            attack_list.append(ClientAttack(at.name, perks, flaws, at.roll,
                                            at.dx, at.end, at.note))

        cchar = ClientCharacter(char.user_id, char.name, char.combat_notes,
                            ability_list, weakness_list, attack_list,
                            char.defense, char.health, char.endurance, char.tv,
                            char.background, char.appearance, char.personality,
                            char.other_notes, char.portrait_url, char.icon_url)
        cchar.id = char_id
        return cchar        
Beispiel #22
0
            pkfl += " " + fl.toString()
        print "  " + pkfl
        print "  " + atk.note
        print "  roll:" + atk.roll
        print "  dx:" + atk.dx
        print "  cost:" + atk.end
    print " def:" + char.defense
    print " hp:" + char.health
    print " end:" + char.endurance
    print " tv:" + char.tv
    




DA = DataAccess()
#DA.addBaseData()

#DA.addDummyCharacter()
#DA.printDummyCharacter()

    

#DA.printAbilities()
#DA.printWeaknesses()
#DA.printFlaws()
#DA.printPerks()
#addDummyClientCharacter2()
#addDummyClientCharacter3()
#addDummyClientCharacter4()
Beispiel #23
0
def addDummyClientCharacter4():
    DA = DataAccess()
    attacks = []
    a1perks = []
    a1perks.append(ClientPerk('11', DA.getPerkDetails(11).name, '1',''))
    a1perks.append(ClientPerk('10', DA.getPerkDetails(10).name,'1',''))
    a1flaws = []
    a1flaws.append(ClientFlaw('5', DA.getFlawDetails(5).name, '1',''))
    a1flaws.append(ClientFlaw('1', DA.getPerkDetails(1).name, '1',''))
    attacks.append(ClientAttack('Fan of Codex', a1perks, a1flaws, '5', '4',
                            '0', 'Says Hi to Codex'))
    a2perks = []
    a2perks.append(ClientPerk('1', DA.getPerkDetails(1).name, '1',''))
    a2perks.append(ClientPerk('3', DA.getPerkDetails(3).name, '1',''))
    a2flaws = []
    a2flaws.append(ClientFlaw('15', DA.getFlawDetails(15).name, '1',''))
    a2flaws.append(ClientFlaw('3', DA.getFlawDetails(3).name, '1',''))
    attacks.append(ClientAttack('Backstab', a2perks, a2flaws, '7', '2',
                            '15', 'does double damage if unseen by target'))
    abilities = []
    abilities.append(ClientAbility('17', DA.getAbilityDetails(17).name, '+3', ''))
    abilities.append(ClientAbility('3', DA.getAbilityDetails(3).name, '+1', ''))
    abilities.append(ClientAbility('2', DA.getAbilityDetails(2).name, '+5', ''))
    weaknesses = []
    weaknesses.append(ClientWeakness('21', DA.getWeaknessDetails(21).name, '-3',''))
    weaknesses.append(ClientWeakness('1', DA.getWeaknessDetails(1).name,'-1',''))
    weaknesses.append(ClientWeakness('2', DA.getWeaknessDetails(2).name,'-5','(Eye Sight)'))

    Leon = ClientCharacter('*****@*****.**', 'Jacob', '', abilities,
                 weaknesses, attacks, '9', '10', '10',
                 '1', 'Smells Funny', 'Looks Funny', 'Funny',
                 '', '', '')

    CDA.addClientCharacter(Leon)
Beispiel #24
0
def updateDummyClientCharacter4(char_id):
    DA = DataAccess()
    attacks = []
    a1perks = []
    a1perks.append(ClientPerk('1', DA.getPerkDetails(11).name, '1',''))
    a1perks.append(ClientPerk('2', DA.getPerkDetails(10).name,'1',''))
    a1flaws = []
    a1flaws.append(ClientFlaw('1', DA.getFlawDetails(5).name, '1',''))
    a1flaws.append(ClientFlaw('2', DA.getPerkDetails(1).name, '1',''))
    attacks.append(ClientAttack('Sleep', a1perks, a1flaws, '5', '4',
                            '0', 'Take A Nap'))
    a2perks = []
    a2perks.append(ClientPerk('4', DA.getPerkDetails(1).name, '1',''))
    a2perks.append(ClientPerk('3', DA.getPerkDetails(3).name, '1',''))
    a2flaws = []
    a2flaws.append(ClientFlaw('4', DA.getFlawDetails(15).name, '1',''))
    a2flaws.append(ClientFlaw('3', DA.getFlawDetails(3).name, '1',''))
    attacks.append(ClientAttack('Backstab', a2perks, a2flaws, '7', '2',
                            '15', 'does double damage if unseen by target'))
    abilities = []
    abilities.append(ClientAbility('1', DA.getAbilityDetails(17).name, '+1', ''))
    abilities.append(ClientAbility('2', DA.getAbilityDetails(3).name, '+1', ''))
    abilities.append(ClientAbility('3', DA.getAbilityDetails(2).name, '+1', ''))
    weaknesses = []
    weaknesses.append(ClientWeakness('1', DA.getWeaknessDetails(21).name, '-5',''))
    weaknesses.append(ClientWeakness('2', DA.getWeaknessDetails(1).name,'-5',''))
    weaknesses.append(ClientWeakness('3', DA.getWeaknessDetails(2).name,'-5',''))

    Leon = ClientCharacter('*****@*****.**', 'Jacobugath', '', abilities,
                 weaknesses, attacks, '1', '10', '10',
                 '1', 'Mighty Warrior', 'Looks Like Godzilla', 'Sleepy',
                 '', '', '')

    CDA.updateClientCharacter(Leon, char_id)
Beispiel #25
0
def addDummyClientCharacter2():
    DA = DataAccess()
    attacks = []
    a1perks = []
    a1perks.append(ClientPerk('1', DA.getPerkDetails(1).name, '1',''))
    a1perks.append(ClientPerk('16', DA.getPerkDetails(16).name,'1',''))
    a1flaws = []
    a1flaws.append(ClientFlaw('2', DA.getFlawDetails(2).name, '1',''))
    a1flaws.append(ClientFlaw('14', DA.getPerkDetails(14).name, '1',''))
    attacks.append(ClientAttack('Fan of Blades', a1perks, a1flaws, '5', '4',
                            '0', 'throws 6 blades infront of him in a cone'))
    a2perks = []
    a2perks.append(ClientPerk('3', DA.getPerkDetails(3).name, '1',''))
    a2perks.append(ClientPerk('5', DA.getPerkDetails(5).name, '1',''))
    a2flaws = []
    a2flaws.append(ClientFlaw('5', DA.getFlawDetails(5).name, '1',''))
    a2flaws.append(ClientFlaw('8', DA.getFlawDetails(8).name, '1',''))
    attacks.append(ClientAttack('Backstab', a2perks, a2flaws, '7', '2',
                            '15', 'does double damage if unseen by target'))
    abilities = []
    abilities.append(ClientAbility('7', DA.getAbilityDetails(7).name, '+3', ''))
    abilities.append(ClientAbility('13', DA.getAbilityDetails(13).name, '+1', ''))
    abilities.append(ClientAbility('32', DA.getAbilityDetails(32).name, '+5', ''))
    weaknesses = []
    weaknesses.append(ClientWeakness('2', DA.getWeaknessDetails(2).name, '-3',''))
    weaknesses.append(ClientWeakness('14', DA.getWeaknessDetails(14).name,'-1',''))
    weaknesses.append(ClientWeakness('28', DA.getWeaknessDetails(28).name,'-5','(Eye Sight)'))

    Leon = ClientCharacter('*****@*****.**', 'Leon', '', abilities,
                 weaknesses, attacks, '4', '35', '70',
                 '25', 'Born on the Streets', 'Cloaked', 'Sullen',
                 '', '', '')

    CDA.addClientCharacter(Leon)
Beispiel #26
0
def addDummyClientCharacter3():
    DA = DataAccess()
    attacks = []
    a1perks = []
    a1perks.append(ClientPerk('15', DA.getPerkDetails(15).name, '1',''))
    a1perks.append(ClientPerk('10', DA.getPerkDetails(10).name,'1',''))
    a1flaws = []
    a1flaws.append(ClientFlaw('12', DA.getFlawDetails(12).name, '1',''))
    a1flaws.append(ClientFlaw('11', DA.getPerkDetails(11).name, '1',''))
    attacks.append(ClientAttack('Bomba', a1perks, a1flaws, '7', '7',
                            '15', 'Oh Yeah'))
    a2perks = []
    a2perks.append(ClientPerk('6', DA.getPerkDetails(6).name, '1',''))
    a2perks.append(ClientPerk('1', DA.getPerkDetails(1).name, '1',''))
    a2flaws = []
    a2flaws.append(ClientFlaw('1', DA.getFlawDetails(1).name, '1',''))
    a2flaws.append(ClientFlaw('4', DA.getFlawDetails(4).name, '1',''))
    attacks.append(ClientAttack('StarScream', a2perks, a2flaws, '7', '2',
                            '15', 'does double damage if unseen by target'))
    abilities = []
    abilities.append(ClientAbility('17', DA.getAbilityDetails(17).name, '+3', ''))
    abilities.append(ClientAbility('1', DA.getAbilityDetails(1).name, '+1', ''))
    abilities.append(ClientAbility('30', DA.getAbilityDetails(30).name, '+5', ''))
    weaknesses = []
    weaknesses.append(ClientWeakness('21', DA.getWeaknessDetails(21).name, '-3',''))
    weaknesses.append(ClientWeakness('24', DA.getWeaknessDetails(24).name,'-1',''))
    weaknesses.append(ClientWeakness('20', DA.getWeaknessDetails(20).name,'-5','(Eye Sight)'))

    Leon = ClientCharacter('*****@*****.**', 'Amy', '', abilities,
                 weaknesses, attacks, '5', '40', '50',
                 '22', 'Born on in the USA', 'Dress', 'Exited',
                 '', '', '')

    CDA.addClientCharacter(Leon)
Beispiel #27
0
def main():

    # Create a database object
    data_access = DataAccess()

    root = ET.parse('resource/Library.xml')
    elements = root.findall('dict/dict/dict')
    print('Number of tracks: ', len(elements))

    for entry in elements:
        if lookup(entry, 'Track ID') is None: continue
        name = lookup(entry, 'Name')
        artist = lookup(entry, 'Artist')
        title = lookup(entry, 'Album')
        rating = lookup(entry, 'Rating')
        genre = lookup(entry, 'Genre')
        count = lookup(entry, 'Track Count')
        length = lookup(entry, 'Total Time')

        if name is None or artist is None or genre is None or title is None:
            continue

        print('Name : ', name)
        print('Artist: ', artist)
        print('Album: ', title)
        print('Rating: ', rating)
        print('Genre: ', genre)
        print('Count: ', count)
        print('Total time: ', length)

        # Populate the artist TABLE
        data_access.insert('INSERT OR IGNORE INTO ARTIST(name) VALUES(?);',
                           (artist, ))
        artist_rows = data_access.query(
            'SELECT id  FROM ARTIST WHERE name = ?;', (artist, ))
        artist_id = artist_rows[0]

        # Populate the genre TABLE
        data_access.insert('INSERT OR IGNORE INTO GENRE(name) VALUES(?);',
                           (genre, ))
        genre_rows = data_access.query('SELECT id FROM GENRE WHERE name = ?;',
                                       (genre, ))
        genre_id = genre_rows[0]

        # Populate the album TABLE
        data_access.insert(
            'INSERT OR IGNORE INTO ALBUM(title, artist_id) VALUES(?, ?)', (
                title,
                artist_id,
            ))
        album_rows = data_access.query('SELECT id FROM ALBUM where title = ?',
                                       (title, ))
        album_id = album_rows[0]

        # Populate the tracks
        data_access.insert(
            'INSERT OR REPLACE INTO TRACK (title, album_id, genre_id, len, rating, count) VALUES (?, ?, ?, ?, ?, ?)',
            (
                title,
                album_id,
                genre_id,
                length,
                rating,
                count,
            ))

        data_access.commit()
Beispiel #28
0
    def updateClientCharacter(self, cchar, char_id):
        DA = DataAccess()
        session = DA.getSession()
        character = DA.getCharacter(char_id)
        character.user_id=cchar.user_id
        character.name=cchar.name
        character.combat_notes=cchar.combat_notes
        character.defense=cchar.defense
        character.health=cchar.health
        character.endurance=cchar.endurance
        character.tv=cchar.tv
        character.background=cchar.background
        character.appearance=cchar.appearance
        character.personality=cchar.personality
        character.other_notes=cchar.other_notes
        session.add(character)
        session.commit()
        cchar.id = character.id
        for atk in DA.getCharAttacks(char_id):
            session.delete(atk)
            for pk in DA.getAttackPerks(atk.id):
                session.delete(pk)
            for fl in DA.getAttackFlaws(atk.id):
                session.delete(fl)
            
        for at in cchar.attacks:
            attack = CharacterAttack(character_id=character.id, name=at.name,
                                roll=at.roll, dx=at.dx, end=at.end, note=at.note)
            session.add(attack)
            session.commit()
            for pk in at.perks:
                aperk = AttackPerk(perk_id=pk.perk_id, attack_id=attack.id,
                                   multiplier=pk.multiplier, note=pk.note)
                session.add(aperk)
                session.commit()
            for fl in at.flaws:
                aflaw = AttackFlaw(flaw_id=fl.flaw_id, attack_id=attack.id,
                                   multiplier=fl.multiplier, note=fl.note)
                session.add(aflaw)
                session.commit()

        for abi in DA.getCharAbilities(char_id):
            session.delete(abi)
            
        for ab in cchar.abilities:
            cability = CharacterAbility(ability_id=ab.ability_id,
                               character_id=character.id,
                               ability_value=ab.value,
                               ability_note=ab.note)
            session.add(cability)
            session.commit()

        for wkn in DA.getCharWeaknesses(char_id):
            session.delete(wkn)
            
        for wk in cchar.weaknesses:
            cweakness = CharacterWeakness(weakness_id=wk.weakness_id,
                               character_id=character.id,
                               weakness_value=wk.value,
                               weakness_note=wk.note)
            session.add(cweakness)
            session.commit()
        session.commit()