diff options
author | luxagraf <sng@luxagraf.net> | 2024-07-23 09:43:50 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2024-07-23 09:43:50 -0500 |
commit | 9b2f5bb2de9e77b90207b001aaafaf9a148a6272 (patch) | |
tree | 6a230094dbe88a511543f13092fb341a66b519c8 | |
parent | 32406626b91809fa5a7e7ad4a7633667fba2a84a (diff) |
gtd: added pub_date updater
-rw-r--r-- | app/gtd/templates/gtd/wiredpost_table.html | 1 | ||||
-rw-r--r-- | app/gtd/urls.py | 5 | ||||
-rw-r--r-- | app/gtd/views.py | 27 |
3 files changed, 33 insertions, 0 deletions
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 @@ <main class="content"> <div class="results"> <div style="font-size:11px; text-align: right;"><a href="{% url 'gtd:wiredpost-update-overdue' %}">update overdue</a></div> + <div style="font-size:11px; text-align: right;"><a href="{% url 'gtd:wiredpost-update-pubdate' %}">update pubdate</a></div> <table class="sortable" id="result_list"> <thead> <tr> 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 @@ -109,6 +109,11 @@ urlpatterns = [ 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(), name="wiredpost-create" 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) + |