From 9b2f5bb2de9e77b90207b001aaafaf9a148a6272 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Tue, 23 Jul 2024 09:43:50 -0500 Subject: gtd: added pub_date updater --- app/gtd/templates/gtd/wiredpost_table.html | 1 + app/gtd/urls.py | 5 +++++ app/gtd/views.py | 27 +++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/app/gtd/templates/gtd/wiredpost_table.html b/app/gtd/templates/gtd/wiredpost_table.html index ee56aa1..d6458bd 100644 --- a/app/gtd/templates/gtd/wiredpost_table.html +++ b/app/gtd/templates/gtd/wiredpost_table.html @@ -6,6 +6,7 @@
update overdue
+
update pubdate
diff --git a/app/gtd/urls.py b/app/gtd/urls.py index 2d883c1..fb62846 100644 --- a/app/gtd/urls.py +++ b/app/gtd/urls.py @@ -108,6 +108,11 @@ urlpatterns = [ views.WiredPostUpdateOverdueView.as_view(), name="wiredpost-update-overdue" ), + path( + r'wiredposts/update-pub-date', + views.UpdateDateView.as_view(), + name="wiredpost-update-pubdate" + ), path( r'wiredpost/create', views.WiredPostCreateView.as_view(), diff --git a/app/gtd/views.py b/app/gtd/views.py index cb3cefd..e0381d2 100644 --- a/app/gtd/views.py +++ b/app/gtd/views.py @@ -332,3 +332,30 @@ class GTDOutcomeDeleteView(DeleteView): model = GTDOutcome success_url = "/gtd/outcomes" template_name = "gtd/confirm_delete.html" + + + + +from datetime import datetime +from bs4 import BeautifulSoup +import requests + +def scrape_date(url): + return time + +class UpdateDateView(RedirectView): + permanent = False + url = "/gtd/wiredposts" + query_string = True + + def get_redirect_url(self, *args, **kwargs): + for post in WiredPost.objects.all(): + if post.url: + content = requests.get(url) + soup = BeautifulSoup(content.text, 'html.parser') + time = datetime.strptime(soup.time['datetime'][:-6], "%Y-%m-%dT%H:%M:%S").date() + if time != post.date_last_pub: + post.date_last_pub = time + post.save() + return super().get_redirect_url(*args, **kwargs) + -- cgit v1.2.3-70-g09d2