Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
interrogator committed Aug 21, 2019
1 parent 192e854 commit 0b6efb9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
20 changes: 9 additions & 11 deletions buzzword/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@
from .parts.main import CONFIG, CORPORA, CORPUS_META, INITIAL_TABLES, app
from .parts.tabs import _make_tabs

# where downloadable CSVs get stored
if not os.path.isdir("csv"):
os.makedirs("csv")
# where uploaded corpora are stored
if not os.path.isdir("uploads"):
os.makedirs("uploads")
# where downloadable CSVs/corpora get stored
for path in {"csv", "uploads"}:
if not os.path.isdir(path):
os.makedirs("csv")


def _get_layout():
"""
Function for layout. Could be helpful in future to do it this way.
"""
loc = dcc.Location(id="url", refresh=False)
# user storage for searches, tables, and click counts
search_store = dcc.Store(id='session-search', data=dict())
tables_store = dcc.Store(id='session-tables', data=dict())
click_clear = dcc.Store(id='session-clicks-clear')
click_table = dcc.Store(id='session-clicks-table')
click_clear = dcc.Store(id='session-clicks-clear', data=-1)
click_table = dcc.Store(id='session-clicks-table', data=-1)
content = html.Div(id="page-content")
stores = [search_store, tables_store, click_clear, click_table]
return html.Div([loc] + stores + [content])
Expand Down Expand Up @@ -62,8 +61,7 @@ def _get_explore_layout(slug):
Get (and maybe generate) the explore layout for this slug
"""
gen = (k for k, v in CORPUS_META.items() if v["slug"] == slug)
name = next(gen, None)
name = name or slug
name = next(gen, slug)
# store the default explore for each corpus in a dict for speed
if slug in LAYOUTS:
return LAYOUTS[slug]
Expand All @@ -89,7 +87,7 @@ def _choose_correct_page(pathname):
if not pathname:
return start.layout
else:
return "404"
return "404. Page not found: {}".format(pathname)


if __name__ == "__main__":
Expand Down
11 changes: 7 additions & 4 deletions buzzword/parts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@

def _get_corpus_config(local_conf, global_conf):
"""
get some configs, from json, backup from global, or none
Return global conf plus individual settings for corpus
"""
conf = dict()
conf = {**global_conf}
settings = {"max_dataset_rows", "drop_columns", "add_governor", "load"}
for setting in settings:
from_global = global_conf.get(setting)
conf[setting] = local_conf.get(setting, from_global)
loc = local_conf.get(setting)
if loc is not None:
conf[setting] = loc
return conf


def _get_corpora(corpus_meta):
"""
Load in all available corpora and make their initial tables
This is run when the app starts up
"""
corpora = dict()
tables = dict()
Expand Down

0 comments on commit 0b6efb9

Please sign in to comment.