From d3116d1d3c77d98daa0b69ea45ac628ef91ec029 Mon Sep 17 00:00:00 2001 From: luxagraf Date: Wed, 28 Aug 2024 12:45:16 -0500 Subject: gtd: added author name to wiredposts so I can filter --- app/gtd/admin.py | 4 ++-- app/gtd/models.py | 36 ++++++++++++++++++++++++++++++++++++ app/gtd/urls.py | 5 +++++ app/gtd/views.py | 12 ++++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) diff --git a/app/gtd/admin.py b/app/gtd/admin.py index 643ca73..7335727 100644 --- a/app/gtd/admin.py +++ b/app/gtd/admin.py @@ -9,9 +9,9 @@ from .models import ( ) @admin.register(WiredPost) class WiredPostAdmin(admin.ModelAdmin): - list_display = ('title', 'date_last_pub', 'category', 'update_frequency', 'needs_update', 'post_status') + list_display = ('title', 'url', 'date_last_pub', 'category', 'update_frequency', 'needs_update', 'post_status') search_fields = ['title'] - list_filter = ['post_status', 'post_type', 'update_frequency'] + list_filter = ['post_status', 'author', 'post_type', 'update_frequency'] filter_horizontal = ('update_schedule',) class Media: diff --git a/app/gtd/models.py b/app/gtd/models.py index 2ea18ab..90f181e 100644 --- a/app/gtd/models.py +++ b/app/gtd/models.py @@ -250,6 +250,42 @@ class WiredPost(models.Model): super(WiredPost, self).save() +def update_outdoor_feed(): + import requests + source = requests.get("https://www.wired.com/feed/tag/commerce/latest/json").json() + for item in source['items']: + for tag in item['tags']: + if tag == "outdoor" or tag == "outdoors": + print(item['title']) + +def scrape_wired_tag_page(url): + import requests + from bs4 import BeautifulSoup + content = requests.get(url) + soup = BeautifulSoup(content.text, 'html.parser') + with open("tempfile.csv", 'a') as f: + for item in soup.find_all("a", class_="summary-item__hed-link"): + title = item.get_text() + link = item['href'] + author = item.find_next_sibling('div').get_text() + guide_string = "%s, %s, %s \n" % (title, link, author) + f.write(guide_string) + +''' +with open('tempfile.csv') as f: + import csv + reader = csv.reader(f, escapechar='\\') + for row in reader: + hed = row[0].strip() + url = row[1].strip() + author = row[2].strip() + _, created = WiredPost.objects.get_or_create( + title=hed, + url=url, + author=author + ) +''' + @receiver(post_save, sender=WiredPost) def post_save_events(sender, update_fields, created, instance, **kwargs): post_save.disconnect(post_save_events, sender=WiredPost) diff --git a/app/gtd/urls.py b/app/gtd/urls.py index dd794fb..78e4393 100644 --- a/app/gtd/urls.py +++ b/app/gtd/urls.py @@ -15,6 +15,11 @@ urlpatterns = [ views.WiredGenerateREIDealCodeView.as_view(), name="reicode" ), + path( + r'wiredpost/outdoor', + views.OutdoorPlanningView.as_view(), + name="outdoor" + ), path( r'todo', views.GTDNoteTODOView.as_view(), diff --git a/app/gtd/views.py b/app/gtd/views.py index cdbd29e..4bc2170 100644 --- a/app/gtd/views.py +++ b/app/gtd/views.py @@ -3,6 +3,8 @@ from django.views.generic.base import TemplateView from django.urls import reverse, reverse_lazy from django.db.models import Q +from taxonomy.models import Category + from .models import ( GTDNote, GTDProject, @@ -300,6 +302,16 @@ class WiredGenerateREIDealCodeView(TemplateView): template_name = "gtd/reideal_code.html" +class OutdoorPlanningView(ListView): + model = WiredPost + template_name = 'gtd/wiredpost_table.html' + + def get_queryset(self): + cat = Category.objects.get(name="Outdoor") + return WiredPost.objects.filter(category=cat).order_by("-needs_update") + + + class GTDNoteDeleteView(DeleteView): # specify the model you want to use model = GTDNote -- cgit v1.2.3-70-g09d2