Skip to content

Commit

Permalink
Merge branch 'hotfix/20190416-reading-files'
Browse files Browse the repository at this point in the history
  • Loading branch information
secondfry committed Apr 16, 2019
2 parents 065813b + 6d6fabb commit b45d14f
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions src/shortcircuit/model/evedb.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
# evedb.py

import csv
import io
import os
from PySide2 import QtCore

from .utility.singleton import Singleton


def dict_from_csvqfile(file_path: str):
path = file_path.split('/')
path.insert(0, 'resources')
path.insert(0, '..')
path = os.sep.join(path)
f = open(path, 'r')
reader = csv.reader(f, delimiter=';')
class FileReader:
def __init__(self, file_path: str):
self.reader = None
self.qfile = QtCore.QFile(file_path)
self.status = self.qfile.open(QtCore.QIODevice.ReadOnly | QtCore.QIODevice.Text)

return reader
def __iter__(self):
return self

def __next__(self):
if self.qfile.atEnd():
raise StopIteration
ret = self.qfile.decodeName(self.qfile.readLine()) # I'm kinda sorry, but not at all
if not ret:
raise StopIteration
return ret

@staticmethod
def get_dict_from_csv_qfile(file_path: str):
return csv.reader(FileReader(file_path), delimiter=';')


class EveDb(metaclass=Singleton):
Expand Down Expand Up @@ -42,12 +55,12 @@ class EveDb(metaclass=Singleton):
)

def __init__(self):
self.gates = [[int(rows[0]), int(rows[1])] for rows in dict_from_csvqfile("database/system_jumps.csv")]
self.gates = [[int(rows[0]), int(rows[1])] for rows in FileReader.get_dict_from_csv_qfile(':database/system_jumps.csv')]
self.system_desc = {
int(rows[0]): [rows[1], rows[2], float(rows[3])]
for rows in dict_from_csvqfile("database/system_description.csv")
for rows in FileReader.get_dict_from_csv_qfile(':database/system_description.csv')
}
self.wh_codes = {rows[0]: int(rows[1]) for rows in dict_from_csvqfile("database/statics.csv")}
self.wh_codes = {rows[0]: int(rows[1]) for rows in FileReader.get_dict_from_csv_qfile(':database/statics.csv')}

# TODO properly type this
def get_whsize_by_code(self, code):
Expand Down

0 comments on commit b45d14f

Please sign in to comment.