summaryrefslogtreecommitdiff
path: root/app/links/models.py
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2018-04-08 15:44:23 -0400
committerluxagraf <sng@luxagraf.net>2018-04-08 15:44:23 -0400
commit179b60bfe0fd5f4333040ef343ac472b2cf8b993 (patch)
tree5b76b08a87e582a78fd1f1c1c2bd834bfb71b301 /app/links/models.py
parent8cbaf47761faeb45b78503e093fbbd1314194802 (diff)
cleaned up stuff admin
Diffstat (limited to 'app/links/models.py')
-rw-r--r--app/links/models.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/links/models.py b/app/links/models.py
index 46867e7..52d6e2b 100644
--- a/app/links/models.py
+++ b/app/links/models.py
@@ -1,5 +1,6 @@
import requests
import datetime
+from random import randint
from django.template.defaultfilters import striptags
from django.urls import reverse
from django.utils.html import format_html
@@ -15,6 +16,25 @@ from taggit.managers import TaggableManager
from utils.widgets import markdown_to_html
+def random_link():
+ """
+ Emails me a random link everyday (via cron)
+ """
+ total = Link.objects.all().count()
+ pk = randint(1, total)
+ try:
+ link = Link.objects.get(pk=pk)
+ except Link.DoesNotExist:
+ try:
+ link = Link.objects.get(pk=pk+1)
+ except Link.DoesNotExist:
+ link = Link.objects.get(pk=pk+91)
+ subject = "today's link: %s" % link.title
+ body = "%s\n\n%s\n\n\nvisit site:%s\n\n\ndelete link: https://live.luxagraf.net/admin/links/link/%s/" % (link.title, link.description, link.url, link.pk)
+ msg = EmailMessage(subject, striptags(body), 'sng@luxagraf.net', ['sng@luxagraf.net'])
+ msg.send()
+
+
def get_source(source):
url = "http://heckyesmarkdown.com/go/?read=1&preview=0&showframe=0&output=json&u=%s" % (source)
r = requests.get(url, timeout=15.001)