添加ping_baidu 命令

liangliangyy 9 years ago
parent 02ea37086e
commit 3892ad0aa7

@ -18,7 +18,7 @@ from django.conf import settings
class sipder_notify():
def __baidu_notify(self, url):
def baidu_notify(self, url):
try:
result = requests.post(settings.BAIDU_NOTIFY_URL, data=url)
print(result.text)
@ -32,5 +32,5 @@ class sipder_notify():
print(e)
def notify(self, url):
self.__baidu_notify(url)
self.baidu_notify(url)
self.__google_notify()

@ -0,0 +1,33 @@
#!/usr/bin/env python
# encoding: utf-8
"""
@version: ??
@author: liangliangyy
@license: MIT Licence
@contact: liangliangyy@gmail.com
@site: https://www.lylinux.org/
@software: PyCharm
@file: ping_baidu.py
@time: 2017/1/17 下午15:29
"""
from django.core.management.base import BaseCommand, CommandError
from blog.models import Article
from DjangoBlog.spider_notify import sipder_notify
class Command(BaseCommand):
help = 'notify baidu url'
def handle(self, *args, **options):
notify = sipder_notify()
for article in Article.objects.filter(status='p'):
try:
url = article.get_full_url()
notify.baidu_notify(url=url)
self.stdout.write(self.style.SUCCESS('Successfully notify article id : "%s"' % article.pk))
except Exception as e:
self.stdout.write('error:' + str(e))
self.stdout.write(self.style.SUCCESS('finish notify'))

@ -4,6 +4,7 @@ from django.conf import settings
# from django.template.defaultfilters import slugify
from uuslug import slugify
from DjangoBlog.spider_notify import sipder_notify
from django.contrib.sites.models import Site
class Article(models.Model):
@ -74,7 +75,7 @@ class Article(models.Model):
self.slug = slugify(self.title)
try:
notify = sipder_notify()
notify.notify(self.get_absolute_url())
notify.notify(self.get_full_url())
except Exception as e:
print(e)
super().save(*args, **kwargs)
@ -91,6 +92,11 @@ class Article(models.Model):
info = (self._meta.app_label, self._meta.model_name)
return reverse('admin:%s_%s_change' % info, args=(self.pk,))
def get_full_url(self):
site = Site.objects.get_current().domain
article_url = "https://{site}{path}".format(site=site, path=self.get_absolute_url())
return article_url
'''
class BlogPage(models.Model):

Loading…
Cancel
Save