forked from castilhocp/arkhrec
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
93 lines (66 loc) · 2.43 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import os
from typing import Collection
from flask import (
Flask, render_template, session
)
import arkhrec.general_helpers
import arkhrec.data_helpers
def create_app(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
SECRET_KEY='dev',
# DATABASE=os.path.join(app.instance_path, 'flaskr.sqlite'),
# CACHE_TYPE="SimpleCache", # Flask-Caching related configs
# CACHE_DEFAULT_TIMEOUT=300
)
# cache=Cache(app)
if test_config is None:
# load the instance config, if it exists, when not testing
app.config.from_pyfile('config.py', silent=True)
else:
# load the test config if passed in
app.config.from_mapping(test_config)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
from . import deck
app.register_blueprint(deck.bp)
from . import card
app.register_blueprint(card.bp)
from . import investigator
app.register_blueprint(investigator.bp)
from . import card_collection
app.register_blueprint(card_collection.bp)
from . import map
app.register_blueprint(map.bp)
@app.route('/')
def index():
return render_template('index.html')
@app.context_processor
def cycles_processor():
if not arkhrec.data_helpers.gCycles:
read_cycles(app)
return dict(cycles=arkhrec.data_helpers.gCycles)
@app.before_first_request
def before_first_request():
arkhrec.data_helpers.get_collection()
read_cycles(app)
return app
def read_cycles(app):
import json
with open(os.path.join(app.root_path, 'datafiles', 'cycles.json'), 'r') as f:
cycles = json.load(f)
with open(os.path.join(app.root_path, 'datafiles', 'packs.json'), 'r') as f:
packs = json.load(f)
arkhrec.data_helpers.gCycles = dict()
for cycle in cycles:
if cycle['code'] in arkhrec.data_helpers.PACKS_WITHOUT_PLAYER_CARDS:
continue
arkhrec.data_helpers.gCycles[cycle['code']] = {'code': cycle['code'], 'name': cycle['name'], 'position': cycle['position'], 'packs': []}
for pack in packs:
if pack['cycle_code'] in arkhrec.data_helpers.PACKS_WITHOUT_PLAYER_CARDS:
continue
arkhrec.data_helpers.gCycles[pack['cycle_code']]['packs'].append(pack)