forked from liangliangyy/DjangoBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspider_notify.py
More file actions
42 lines (34 loc) · 886 Bytes
/
spider_notify.py
File metadata and controls
42 lines (34 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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: spider_notify.py
@time: 2017/1/15 下午1:41
"""
from django.contrib.sitemaps import ping_google
import requests
from django.conf import settings
class SpiderNotify():
@staticmethod
def baidu_notify(urls):
try:
data = '\n'.join(urls)
result = requests.post(settings.BAIDU_NOTIFY_URL, data=data)
print(result.text)
except Exception as e:
print(e)
@staticmethod
def __google_notify():
try:
ping_google('/sitemap.xml')
except Exception as e:
print(e)
@staticmethod
def notify(url):
SpiderNotify.baidu_notify(url)
SpiderNotify.__google_notify()