Skip to content

Commit

Permalink
fix iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
ilude committed Apr 18, 2024
1 parent 4160632 commit ddd54fa
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def inject_current_date():

@app.route('/')
@app.route('/tab/<tab_name>')
@cache.cached(timeout=page_timeout, unless=lambda: layout.is_modified)
#@cache.cached(timeout=page_timeout, unless=lambda: layout.is_modified)
def index(tab_name=None):
# Load feeds and bookmarks
layout.reload()
Expand Down
9 changes: 9 additions & 0 deletions app/models/iframe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from models.widget import Widget


class Iframe(Widget):
src: str

def __init__(self, widget) -> None:
super().__init__(widget)
self.src = widget['src']
6 changes: 6 additions & 0 deletions app/models/row.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from models.utils import from_list


class Row:
columns: list['Column'] = []

@staticmethod
def from_dict(dictionary: dict) -> 'Row':
from models.column import Column
from models.widget import Widget
row = Row()
if 'columns' in dictionary:
row.columns = from_list(Column.from_dict, dictionary['columns'])
else:
column = Column()
column.widgets = from_list(Widget.from_dict, dictionary['widgets'])
row.columns = [column]
return row
2 changes: 1 addition & 1 deletion app/models/tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def from_dict(dictionary: dict) -> 'Tab':
from models.column import Column
from models.row import Row
tab = Tab()
tab.name = dictionary['name']
tab.name = dictionary['tab']
if 'rows' in dictionary:
tab.rows = from_list(Row.from_dict, dictionary['rows'])
else:
Expand Down
10 changes: 8 additions & 2 deletions app/models/widget.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
from pathlib import Path
from models.utils import pwd


class Widget:
widget: dict
Expand All @@ -8,8 +10,8 @@ class Widget:

def __init__(self, widget):
self.widget = widget

template_path = Path(os.path.join('templates', self.__class__.__name__.lower() + '.html'))
template_path = pwd.joinpath('templates', self.__class__.__name__.lower() + '.html')
if template_path.exists():
self.template = template_path.name
else:
Expand Down Expand Up @@ -51,11 +53,15 @@ def get(self, key, default=None):
@staticmethod
def from_dict(widget: dict) -> 'Widget':
from models.bookmarks import Bookmarks
from models.iframe import Iframe
from models.feed import Feed

match widget['type']:
case 'feed':
return Feed(widget)
case 'bookmarks':
return Bookmarks(widget)
case 'iframe':
return Iframe(widget)
case _:
return Widget(widget)
125 changes: 91 additions & 34 deletions notebooks/new_layout.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,64 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"\n",
"def mean_time_between_updates(datetime_list):\n",
" \"\"\"\n",
" Calculates the mean time between updates given a list of datetime objects.\n",
" \n",
" Parameters:\n",
" datetime_list (list): A list of datetime objects.\n",
" \n",
" Returns:\n",
" datetime.timedelta: The mean time between updates.\n",
" \"\"\"\n",
" if len(datetime_list) < 2:\n",
" return None\n",
" \n",
" datetime_list.sort()\n",
" \n",
" time_deltas = [datetime_list[i] - datetime_list[i-1] for i in range(1, len(datetime_list))]\n",
" \n",
" mean_delta = sum(time_deltas, datetime.timedelta()) / len(time_deltas)\n",
" \n",
" return mean_delta"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEBUG:models.feed:creating cron job for Lawrence Person's BattleSwarm Blog\n",
"DEBUG:models.feed:creating cron job for Cafe Hayek\n",
"DEBUG:models.feed:creating cron job for Slashdot\n",
"DEBUG:models.feed:creating cron job for Real Clear Politics\n",
"DEBUG:models.feed:creating cron job for Instapundit\n",
"DEBUG:models.feed:creating cron job for Twitchy\n",
"DEBUG:models.feed:Saved 89 articles for Real Clear Politics to cache file /workspaces/onboard/cache/PNNNGwgThj9YxWMIm1iJGmeaaw.json\n",
"DEBUG:models.feed:creating cron job for Hacker News\n",
"DEBUG:models.feed:Saved 96 articles for Twitchy to cache file /workspaces/onboard/cache/Codknty83tluqUPuKvetT0w2aMw.json\n",
"DEBUG:models.feed:Saved 14 articles for Lawrence Person's BattleSwarm Blog to cache file /workspaces/onboard/cache/tLpigiHqXoGa1pfAK0IEQDfM.json\n",
"DEBUG:models.feed:Saved 16 articles for Cafe Hayek to cache file /workspaces/onboard/cache/iedE0cn45RqQskGl6a2QZAgz6c.json\n",
"DEBUG:models.feed:creating cron job for Selfhosted - Rising\n",
"DEBUG:models.feed:Saved 64 articles for Slashdot to cache file /workspaces/onboard/cache/mQcWhIWynsupJ6bCw5BNmUKR7ks.json\n",
"DEBUG:models.feed:Saved 132 articles for Hacker News to cache file /workspaces/onboard/cache/49e8mtQjux4h7yxH6GVrdyFX9yI.json\n",
"DEBUG:models.feed:creating cron job for Selfhosted - Top Today\n",
"DEBUG:models.feed:creating cron job for Lawrence Person's BattleSwarm Blog\n",
"DEBUG:models.feed:creating cron job for Cafe Hayek\n",
"DEBUG:models.feed:creating cron job for Slashdot\n",
"DEBUG:models.feed:creating cron job for Real Clear Politics\n",
"DEBUG:models.feed:creating cron job for Instapundit\n",
"DEBUG:models.feed:creating cron job for Twitchy\n",
"DEBUG:models.feed:creating cron job for Hacker News\n",
"DEBUG:models.feed:Saved 112 articles for Selfhosted - Rising to cache file /workspaces/onboard/cache/Umia8PPsn6pvvZOL7KlaBuVbnQ.json\n",
"DEBUG:models.feed:Saved 90 articles for Selfhosted - Top Today to cache file /workspaces/onboard/cache/IxquBM5SsEE9rJbcEZZjbJCISU.json\n",
"DEBUG:models.feed:creating cron job for Selfhosted - Rising\n",
"DEBUG:models.feed:creating cron job for Selfhosted - Top Today\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"DEBUG:processors.title_editor:1/3: True current hash: bZnbeQxpGcqSN4VHbz4aqqiaXI processed hash: None\n",
"DEBUG:processors.title_editor:1/3: True current hash: bZnbeQxpGcqSN4VHbz4aqqiaXI processed hash: None\n",
"DEBUG:processors.title_editor:2/3: True current hash: bZnbeQxpGcqSN4VHbz4aqqiaXI processed hash: None\n",
"DEBUG:processors.title_editor:2/3: True current hash: bZnbeQxpGcqSN4VHbz4aqqiaXI processed hash: None\n",
"DEBUG:processors.title_editor:3/3: True current hash: bZnbeQxpGcqSN4VHbz4aqqiaXI processed hash: None\n",
"DEBUG:processors.title_editor:3/3: True current hash: bZnbeQxpGcqSN4VHbz4aqqiaXI processed hash: None\n",
"DEBUG:models.feed:Saved 315 articles for Instapundit to cache file /workspaces/onboard/cache/0lyOvFNojDx30pO95HS2dfzXM0.json\n",
"DEBUG:models.feed:Saved 315 articles for Instapundit to cache file /workspaces/onboard/cache/0lyOvFNojDx30pO95HS2dfzXM0.json\n",
"DEBUG:models.feed:Saved 14 articles for Lawrence Person's BattleSwarm Blog to cache file /workspaces/onboard/cache/tLpigiHqXoGa1pfAK0IEQDfM.json\n",
"DEBUG:models.feed:Saved 96 articles for Twitchy to cache file /workspaces/onboard/cache/Codknty83tluqUPuKvetT0w2aMw.json\n",
"DEBUG:models.feed:Saved 16 articles for Cafe Hayek to cache file /workspaces/onboard/cache/iedE0cn45RqQskGl6a2QZAgz6c.json\n",
"DEBUG:processors.title_editor:1/1: True current hash: bZnbeQxpGcqSN4VHbz4aqqiaXI processed hash: None\n",
"DEBUG:models.feed:Saved 112 articles for Selfhosted - Rising to cache file /workspaces/onboard/cache/Umia8PPsn6pvvZOL7KlaBuVbnQ.json\n",
"DEBUG:models.feed:Saved 65 articles for Slashdot to cache file /workspaces/onboard/cache/mQcWhIWynsupJ6bCw5BNmUKR7ks.json\n",
"DEBUG:models.feed:Saved 133 articles for Hacker News to cache file /workspaces/onboard/cache/49e8mtQjux4h7yxH6GVrdyFX9yI.json\n",
"DEBUG:models.feed:Saved 316 articles for Instapundit to cache file /workspaces/onboard/cache/0lyOvFNojDx30pO95HS2dfzXM0.json\n",
"DEBUG:models.feed:Saved 100 articles for Real Clear Politics to cache file /workspaces/onboard/cache/PNNNGwgThj9YxWMIm1iJGmeaaw.json\n",
"DEBUG:models.feed:Saved 90 articles for Selfhosted - Top Today to cache file /workspaces/onboard/cache/IxquBM5SsEE9rJbcEZZjbJCISU.json\n"
]
}
],
"source": [
"import sys\n",
"\n",
Expand All @@ -46,13 +73,14 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Here’s a letter to the Wall St\n",
"George Will continues to warn \n",
"is from page 291 of GMU Econ a\n",
"In my latest column for AIER, \n",
Expand All @@ -61,8 +89,7 @@
"Richard Epstein and John Yoo c\n",
"is from page 128 of David Schm\n",
"Arnold Kling is understandably\n",
"is from page 205 of the origin\n",
"Andrew Heaton on greedflation-\n"
"is from page 205 of the origin\n"
]
}
],
Expand All @@ -77,6 +104,36 @@
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"\n",
"def mean_time_between_updates(datetime_list):\n",
" \"\"\"\n",
" Calculates the mean time between updates given a list of datetime objects.\n",
" \n",
" Parameters:\n",
" datetime_list (list): A list of datetime objects.\n",
" \n",
" Returns:\n",
" datetime.timedelta: The mean time between updates.\n",
" \"\"\"\n",
" if len(datetime_list) < 2:\n",
" return None\n",
" \n",
" datetime_list.sort()\n",
" \n",
" time_deltas = [datetime_list[i] - datetime_list[i-1] for i in range(1, len(datetime_list))]\n",
" \n",
" mean_delta = sum(time_deltas, datetime.timedelta()) / len(time_deltas)\n",
" \n",
" return mean_delta"
]
},
{
"cell_type": "code",
"execution_count": 29,
Expand Down

0 comments on commit ddd54fa

Please sign in to comment.