|
|
|
|
@ -14,20 +14,41 @@
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
|
|
|
from blog.models import Article
|
|
|
|
|
from blog.models import Article, Tag, Category
|
|
|
|
|
from DjangoBlog.spider_notify import sipder_notify
|
|
|
|
|
from django.contrib.sites.models import Site
|
|
|
|
|
|
|
|
|
|
site = Site.objects.get_current().domain
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Command(BaseCommand):
|
|
|
|
|
help = 'notify baidu url'
|
|
|
|
|
|
|
|
|
|
def add_arguments(self, parser):
|
|
|
|
|
parser.add_argument('data_type', type=str, choices=['all', 'article', 'tag', 'category'],
|
|
|
|
|
help='article : all article,tag : all tag,category: all category,all: All of these')
|
|
|
|
|
|
|
|
|
|
def get_full_url(self, path):
|
|
|
|
|
url = "https://{site}{path}".format(site=site, path=path)
|
|
|
|
|
return url
|
|
|
|
|
|
|
|
|
|
def handle(self, *args, **options):
|
|
|
|
|
type = options['data_type']
|
|
|
|
|
self.stdout.write('start get %s' % type)
|
|
|
|
|
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))
|
|
|
|
|
urls = []
|
|
|
|
|
if type == 'article' or type == 'all':
|
|
|
|
|
for article in Article.objects.filter(status='p'):
|
|
|
|
|
urls.append(article.get_full_url())
|
|
|
|
|
if type == 'tag' or type == 'all':
|
|
|
|
|
for tag in Tag.objects.all():
|
|
|
|
|
url = tag.get_absolute_url()
|
|
|
|
|
urls.append(self.get_full_url(url))
|
|
|
|
|
if type == 'category' or type == 'all':
|
|
|
|
|
for category in Category.objects.all():
|
|
|
|
|
url = category.get_absolute_url()
|
|
|
|
|
urls.append(self.get_full_url(url))
|
|
|
|
|
|
|
|
|
|
self.stdout.write(self.style.SUCCESS('start notify %d urls' % len(urls)))
|
|
|
|
|
notify.baidu_notify(urls)
|
|
|
|
|
self.stdout.write(self.style.SUCCESS('finish notify'))
|
|
|
|
|
|