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)
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'])
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()