summaryrefslogtreecommitdiff
path: root/app/links
diff options
context:
space:
mode:
Diffstat (limited to 'app/links')
-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)