summaryrefslogtreecommitdiff
path: root/app/gtd/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'app/gtd/models.py')
-rw-r--r--app/gtd/models.py36
1 files changed, 36 insertions, 0 deletions
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)