コード例 #1
0
def create_new_db(db_file, db_content):
    """ This function creates a new SQLite3 file and loads provided
        db content into that database.

        :returns: Nothing
        """

    print('Test data to be imported: ', db_start_data)

    # Delete database file if it exists currently
    if os.path.exists(db_file):
        os.remove(db_file)
        print('Removed db file ', db_file)

    # Create the database
    db.create_all()

    # Iterate over start data dictionary and add content to db
    for company in db_content:
        c = Company(c_id=company['c_id'], c_name=company['c_name'], \
        c_legent=company['c_legent'], c_shacap=company['c_shacap'], \
        c_other=company['c_other'])
        for note in company.get('notes'):
            text, ts = note
            c.notes.append(Note(content=text))
        db.session.add(c)

    print('Imported test data rows into db ', db_file)
    db.session.commit()
コード例 #2
0
    def run(self):
        from setup import db, db_session, engine, app
        from models import Room, User

        models.PSABase.metadata.create_all(engine)
        db.create_all()
        db_session.commit()

        db_session.add(Room(name='Glass Room 1', reservable=True))
        db_session.add(Room(name='Glass Room 2', reservable=False))
        db_session.add(User(id=app.config['SUDO_USERID'], admin=True))
        db_session.commit()
コード例 #3
0
def migrate_db():
    db.create_all()
    schema = NoteSchema()
    session = schema.Meta.sqla_session

    csv_path = os.path.join(base_dir, 'notes', 'db', 'note.csv')
    notes_csv = open(csv_path, 'r').readlines()[2:]

    try:
        for note in notes_csv:
            items = note.strip().split(',')
            print(items)
            note_o = schema.load({
                'datetime': items[1],
                'user': items[2],
                'content': items[3]
            })
            session.add(note_o)
        session.commit()
    except Exception as e:
        print(e)
        return 'Something went wrong', 400

    return 'migration successful', 200
コード例 #4
0
ファイル: main.py プロジェクト: dgiart/final05_python_2021
from setup import app, db
from rest.rest_departments import rest_departments_blueprint
from views.view_departments import view_departments_blueprint
from views.view_employees import view_employees_blueprint
from rest.rest_employees import rest_employees_blueprint
from flask import render_template, request, jsonify
from models.models import Department, Employee
db.create_all()

app.register_blueprint(rest_departments_blueprint, url_prefix='/rest/departments')
app.register_blueprint(rest_employees_blueprint, url_prefix='/rest/employees')
app.register_blueprint(view_departments_blueprint, url_prefix='/view/departments')
app.register_blueprint(view_employees_blueprint, url_prefix='/view/employees')


@app.route('/')
def index():
    data = request.get_json()
    print(data)
    return render_template('index.html')


if __name__ == '__main__':
    app.run(debug=True)
コード例 #5
0
		entry = {'name': osinfo.system, 'data': []}
		for (dateinfo, gamestarts) in GameStart.get_grouped_by_day(osinfo.gamestarts):
			entry['data'].append([unix_time(datetime(*dateinfo)), len(list(gamestarts))])
		startstats.append(entry)
				
	return render_template('show_gamestarts.html', gamestarts=gamestart_list, osstats=osstats, startstats=startstats)

@app.route('/mapstarts')
def show_mapstarts():
	mapstarts = MapStart.query.all()
	maps = Map.query.all()
	mapdata = {}
	for map in maps:
		mapdata[map.mapname] = len(map.mapstarts)
	mapdata = []
	for map in maps:
		mapdata.append([map.mapname, len(map.mapstarts)])
	return render_template('show_mapstarts.html', mapstarts=mapstarts, mapdata=mapdata)

def unix_time(dt):
	epoch = datetime.utcfromtimestamp(0)
	delta = dt - epoch
	return delta.total_seconds()*1000


# Run application
if __name__ == '__main__':
	db.app = app
	db.init_app(app)
	db.create_all()
	app.run()
コード例 #6
0
 def make_db(self):
     print "[*] Creating Database!"
     db.create_all()
     db.session.add(User('admin', 'admin', admin=1))
     db.session.commit()
     print "[+] Database created: /tmp/llw.db"
コード例 #7
0
def init_db():
    db.create_all(app=app)
コード例 #8
0
ファイル: models.py プロジェクト: mturiansky/imgurclone
	def make_db(self):
		print "[*] Creating database!"
		db.create_all()
コード例 #9
0
	def make_db(self):
		print "[*] Creating Database!"
		db.create_all()
		db.session.add(User('admin', 'admin', admin=1))
		db.session.commit()
		print "[+] Database created: /tmp/llw.db"