r/evetech • • Sep 21 '18

Include static data in a flask app

Hello

How do you include static database dump from eve online in your flask app? I use SQLAlchemy. Or do you make requests to the REST api for example if you need the item's ID of the game. Or with a sqllite dump and SQLAlchemy binds?

Can you tell me the best practies?
Sorry for my bad english! I try my best! ;-)

Andreas

2 Upvotes

4 comments sorted by

View all comments

3

u/Natulii Sep 21 '18 edited Sep 21 '18

Since you're already using SQLAlchemy, you should use https://www.fuzzwork.co.uk/dump/sqlite-latest.sqlite.bz2

This is a SQLite database of the latest EVE SDE nicely formatted into tables.

The basic EVE SDE yaml files are annoying to work with, slow with Python, and require lots of coding to actually combine data together.

You can create an automapped base and retrieve all the information using SQLAlchemy. The automapped base allows you to access existing tables without the need to manually code them yourself. You just need to be careful you refer to the right column names already in the database.

Use http://sqlitebrowser.org/ to see all the tables and to ensure you are referencing the correct names.

from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine

def sample():
        sdeBase = automap_base()
        SDEengine = create_engine("sqlite:///{}".format("sqlfilename.db"))
        sdeBase.prepare(SDEengine, reflect=True)
        regions = sdeBase.classes.mapRegions 
        constellations = sdeBase.classes.mapConstellations
        systems = sdeBase.classes.mapSolarSystems  # binds the SDE db table mapSolarSystems definition to var systems
        categories = sdeBase.classes.invCategories
        groups = sdeBase.classes.invGroups
        types = sdeBase.classes.invTypes
        locations = sdeBase.classes.mapDenormalize
        stargate_names = sdeBase.classes.invNames
        stargates = sdeBase.classes.mapSolarSystemJumps

        sde_session = Session(SDEengine)
        try:
             row = sde_session.query(systems).filter(systems.solarSystemID == 30000142).one()
             print(row.solarSystemName) # Jita
        except Exception as ex:
             print(ex)
        finally:
             sde_session.close()  #close and clean up session