Skip to content

Commit

Permalink
bookmark bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ilude committed May 8, 2024
1 parent 7595ede commit 31fed09
Show file tree
Hide file tree
Showing 19 changed files with 535 additions and 881 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"redhat.ansible",
"redhat.vscode-yaml",
"ms-python.black-formatter",
"ms-python.isort"
"ms-python.isort",
"ms-python.autopep8"
],
"settings": {
"dev.containers.copyGitConfig": false,
Expand Down
170 changes: 81 additions & 89 deletions app/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import models.layout
import asyncio
import json
import logging
import os
import secrets
Expand All @@ -20,98 +20,91 @@
logger.setLevel(logging.DEBUG)

copy_default_to_configs()

from models.layout import layout
layout = models.layout.Layout()

app = Flask(__name__)
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True
app.secret_key = os.environ.get("FLASK_SECRET_KEY", secrets.token_hex())


if os.environ.get("FLASK_DEBUG", "False") == "True":
cache_config={
'CACHE_TYPE': 'null'
}
cache_config = {
'CACHE_TYPE': 'null'
}
else:
# 600 seconds = 10 minutes
cache_config={
'CACHE_TYPE': 'simple',
'CACHE_DEFAULT_TIMEOUT': 600
}
from flask_minify import Minify
Minify(app=app, html=True, js=True, cssless=True)
# 600 seconds = 10 minutes
cache_config = {
'CACHE_TYPE': 'simple',
'CACHE_DEFAULT_TIMEOUT': 600
}
from flask_minify import Minify
Minify(app=app, html=True, js=True, cssless=True)

cache = Cache(app, config=cache_config)
page_timeout = int(os.environ.get('ONBOARD_PAGE_TIMEOUT', 600))

assets = Environment(app)

css = Bundle(
'css/*.css',
filters="cssmin",
output="assets/common.css"
'css/*.css',
filters="cssmin",
output="assets/common.css"
)
assets.register('css_all', css)
css.build()



@app.context_processor
def inject_current_date():
return {
'today_date': datetime.now(),
'site_title': os.environ.get('ONBOARD_SITE_TITLE', 'OnBoard'),
}

def load_bookmarks():
try:
with open(pwd.joinpath('configs/bookmarks.json'), 'r', encoding='utf-8') as f:
return json.load(f)
except Exception as ex:
logger.error(f"Error: {ex} loading bookmarks")
return None
favicon_finder = models.layout.FaviconFinder()
return {
'today_date': datetime.now(),
'site_title': os.environ.get('ONBOARD_SITE_TITLE', 'OnBoard'),
'favicon_exists': favicon_finder.favicon_exists,
}


@app.route('/')
@app.route('/tab/<tab_name>')
@cache.cached(timeout=page_timeout, unless=lambda: layout.is_modified)
def index(tab_name=None):
# Load feeds and bookmarks
if layout.is_modified():
layout.reload()
# Load feeds and bookmarks
if layout.is_modified():
layout.reload()

bookmarks = load_bookmarks()
return render_template('index.html', layout=layout, tab_name=tab_name, skip_htmx=False)

return render_template('index.html', bookmarks = bookmarks, layout=layout, tab_name=tab_name, skip_htmx=False)

@app.route('/feed/<feed_id>')
def feed(feed_id):
feed = layout.get_feed(feed_id)
#logger.debug(f"{feed.name} - {feed.display_items[0].title}")
return render_template(feed.template, widget=feed, skip_htmx=True)
feed = layout.get_feed(feed_id)
# logger.debug(f"{feed.name} - {feed.display_items[0].title}")
return render_template(feed.template, widget=feed, skip_htmx=True)


@app.route('/click_events')
def click_events():
df = link_tracker.get_click_events()
html = df.to_html(classes='data', index=False)
response = make_response(html)
response.headers["Content-Type"] = "text/html"
return response
df = link_tracker.get_click_events()
html = df.to_html(classes='data', index=False)
response = make_response(html)
response.headers["Content-Type"] = "text/html"
return response


@app.route('/redirect/<feed_id>/<link_id>')
def track(feed_id, link_id):
link = layout.get_link(feed_id, link_id)
link_tracker.track_click_event(feed_id, link_id, link)
logger.info(f"redirecting to {link}")
return redirect(link, code=302)
link = layout.get_link(feed_id, link_id)

link_tracker.track_click_event(feed_id, link_id, link)

logger.info(f"redirecting to {link}")
return redirect(link, code=302)


@app.route('/feed/<feed_id>/refresh')
def refresh(feed_id):
layout.refresh_feed(feed_id)
return redirect('/', code=302)
layout.refresh_feed(feed_id)
return redirect('/', code=302)


###############################################################################
Expand All @@ -120,41 +113,40 @@ def refresh(feed_id):
#
###############################################################################

if __name__ == '__main__':
port = int(os.environ.get("FLASK_PORT", os.environ.get("ONBOARD_PORT", 9830)))
development = bool(os.environ.get("FLASK_ENV", "development") == "development")
if development:
app.run(port=port, debug=bool(os.environ.get("FLASK_DEBUG", "True")))
if bool(os.environ.get('WERKZEUG_RUN_MAIN')):
print("")
layout.stop_scheduler()
app.logger.info("Shutting down...")

sys.exit()
else:
try:
from hypercorn.config import Config
from hypercorn.asyncio import serve

shutdown_event = asyncio.Event()

def _signal_handler(*_: Any) -> None:
logger.info("Shutting down...")
layout.stop_scheduler()
shutdown_event.set()

config = Config()
config.accesslog="-"
config.errorlog="-"
config.loglevel="DEBUG"
config.bind = f"0.0.0.0:{port}"
loop = asyncio.new_event_loop()
loop.add_signal_handler(signal.SIGTERM, _signal_handler)
loop.run_until_complete(
serve(app, config, shutdown_trigger=shutdown_event.wait)
)
except KeyboardInterrupt:
logger.info("\nShutting down...")
layout.stop_scheduler()
sys.exit()

if __name__ == '__main__':
port = int(os.environ.get("FLASK_PORT", os.environ.get("ONBOARD_PORT", 9830)))
development = bool(os.environ.get("FLASK_ENV", "development") == "development")
if development:
app.run(port=port, debug=bool(os.environ.get("FLASK_DEBUG", "True")))
if bool(os.environ.get('WERKZEUG_RUN_MAIN')):
print("")
layout.stop_scheduler()
app.logger.info("Shutting down...")

sys.exit()
else:
try:
from hypercorn.config import Config
from hypercorn.asyncio import serve

shutdown_event = asyncio.Event()

def _signal_handler(*_: Any) -> None:
logger.info("Shutting down...")
layout.stop_scheduler()
shutdown_event.set()

config = Config()
config.accesslog = "-"
config.errorlog = "-"
config.loglevel = "DEBUG"
config.bind = f"0.0.0.0:{port}"
loop = asyncio.new_event_loop()
loop.add_signal_handler(signal.SIGTERM, _signal_handler)
loop.run_until_complete(
serve(app, config, shutdown_trigger=shutdown_event.wait)
)
except KeyboardInterrupt:
logger.info("\nShutting down...")
layout.stop_scheduler()
sys.exit()
7 changes: 0 additions & 7 deletions app/archive/file_data.py

This file was deleted.

87 changes: 0 additions & 87 deletions app/archive/layout.py

This file was deleted.

Loading

0 comments on commit 31fed09

Please sign in to comment.