diff options
author | luxagraf <sng@luxagraf.net> | 2024-08-28 12:45:16 -0500 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2024-08-28 12:45:16 -0500 |
commit | d3116d1d3c77d98daa0b69ea45ac628ef91ec029 (patch) | |
tree | 3791dd20d40b8f81ebf1a4d3cb2629f11343ace5 | |
parent | 45d3c43735f47e11bbe717b73f05f471750a39f2 (diff) |
gtd: added author name to wiredposts so I can filter
-rw-r--r-- | app/gtd/admin.py | 4 | ||||
-rw-r--r-- | app/gtd/models.py | 36 | ||||
-rw-r--r-- | app/gtd/urls.py | 5 | ||||
-rw-r--r-- | 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 @@ -16,6 +16,11 @@ urlpatterns = [ name="reicode" ), path( + r'wiredpost/outdoor', + views.OutdoorPlanningView.as_view(), + name="outdoor" + ), + path( r'todo', views.GTDNoteTODOView.as_view(), name="todo-list" 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 |