Skip to content

Commit

Permalink
new layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ilude committed Apr 17, 2024
1 parent e0bc2d2 commit 3254773
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [

{
"name": "Python Debugger: Flask",
"type": "debugpy",
"request": "launch",
"module": "flask",
"envFile": "${workspaceFolder}/.devcontainer/.env",
"env": {
"FLASK_APP": "app/app.py",
"FLASK_DEBUG": "True",
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
.PHONY: run
SITE_PACKAGES := $(shell pip show pip | grep '^Location' | cut -d' ' -f2-)

# read and include .devcontainer/.env exporting all variables
ifneq (,$(wildcard .devcontainer/.env))
include .devcontainer/.env
export
endif

run: $(SITE_PACKAGES)
python3 app/app.py

Expand Down
12 changes: 8 additions & 4 deletions app/models/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ def __init__(self, widget) -> None:

if self.needs_update or self.old_cache_path.exists():
# schedule job to run right now
print(f'[{datetime.now()}] {self.name} scheduled for immediate update now!')
self.scheduler.add_job(self.update, 'date', run_date=datetime.now())

@property
def needs_update(self):
force_update = os.getenv("ONBOARD_FEED_FORCE_UPDATE", "False") == "True"
# if there is no last_updated time, or if it's more than an hour ago
return self._last_updated is None or self._last_updated < datetime.now() - timedelta(hours=1)
return force_update or self._last_updated is None or self._last_updated < datetime.now() - timedelta(hours=1)

@property
def old_cache_path(self):
Expand Down Expand Up @@ -141,7 +143,7 @@ def download(self, feed_url: str) -> list[FeedArticle]:
)
)

return self.apply_filters(articles)
return articles

def processors(self, articles: list[FeedArticle]) -> list[FeedArticle]:
if 'process' in self.widget:
Expand All @@ -160,7 +162,7 @@ def processors(self, articles: list[FeedArticle]) -> list[FeedArticle]:
return articles

def save_articles(self, articles: list[FeedArticle]):
print(f"[{datetime.now()}] Starting cache save for {self.name} to file {self.cache_path}")
#print(f"[{datetime.now()}] Starting cache save for {self.name} to file {self.cache_path}")

if self.old_cache_path.exists():
articles += self.load_cache(self.old_cache_path)
Expand All @@ -172,7 +174,9 @@ def save_articles(self, articles: list[FeedArticle]):

# using article.id remove duplicates from articles
all_articles = list(dict((article.id, article) for article in all_articles).values())


all_articles = self.apply_filters(all_articles)

all_articles = self.processors(all_articles)

# sort articles in place by pub_date newest to oldest
Expand Down
5 changes: 4 additions & 1 deletion app/models/feed_article.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def __post_init__(self):
self.id = calculate_sha1_hash(self.link)

self.original_title = unidecode.unidecode(self.original_title)
self.title = re.sub(r'\s+', ' ', self.original_title).strip()
self.original_title = re.sub(r'\s+', ' ', self.original_title).strip()

if not self.title:
self.title = self.original_title

summary = self.description.replace('\n', ' ').replace('\r', ' ').strip()
summary = BeautifulSoup(html.unescape(summary), 'lxml').text
Expand Down

0 comments on commit 3254773

Please sign in to comment.