From e964957abcf9861f2460ca3598852bdc5f48ef81 Mon Sep 17 00:00:00 2001 From: baoliang Date: Thu, 22 Oct 2020 00:29:06 +0800 Subject: [PATCH] add message --- dashboard/models.py | 2 +- polls/utils.py | 44 ++++++++---------- polls/views/__pycache__/notice.cpython-38.pyc | Bin 4273 -> 4277 bytes polls/views/__pycache__/task.cpython-38.pyc | Bin 3879 -> 3877 bytes polls/views/notice.py | 4 +- polls/views/task.py | 2 +- 6 files changed, 24 insertions(+), 28 deletions(-) diff --git a/dashboard/models.py b/dashboard/models.py index 63eb3b2..c97319c 100644 --- a/dashboard/models.py +++ b/dashboard/models.py @@ -170,7 +170,7 @@ class Userprofile(models.Model): return Userprofile.objects.filter(organization__level__level=1) def __str__(self): - if self.is_leve1: + if self.is_level1: return '省级管理员%s' % (self.name,) elif self.is_level2: return '市级管理员%s' % (self.name,) diff --git a/polls/utils.py b/polls/utils.py index 00b388e..2974b24 100644 --- a/polls/utils.py +++ b/polls/utils.py @@ -4,7 +4,6 @@ import requests import random from parsel import Selector from channels.db import database_sync_to_async -from .exceptions import ClientError from django.conf import settings from itertools import chain @@ -40,6 +39,8 @@ def detect_type(url): return 'toutiao' elif 'ixigua.com' in url: return 'xigua' + elif 'gansudaily.com.cn' in url: + return 'xgs' else: return 'other' @@ -51,6 +52,8 @@ def parse(url): "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", } r = requests.get(url, headers=headers) + r.encoding='utf-8' + print(r.text) selector = Selector(text=r.text) if t == 'weixin': og_title = selector.xpath( @@ -61,23 +64,20 @@ def parse(url): '//head/meta[@property="og:url"]/@content').get() og_image = selector.xpath( '//head/meta[@property="og:image"]/@content').get() - elif t == 'xigua': - og_title = selector.xpath( - '//head/meta[@property="og:title"]/@content').get() - og_description = selector.xpath( - '//head/meta[@property="og:description"]/@content').get() - og_url = selector.xpath( - '//head/meta[@property="og:url"]/@content').get() - og_image = selector.xpath( - '//head/meta[@property="og:image"]/@content').get() elif t == 'toutiao': - og_title = selector.xpath('//head/title/text()') + og_title = selector.xpath('//head/title/text()').get() + og_description = selector.xpath( + '//head/meta[@name="description"]/@content').get() + og_url = url + og_image = None + elif t == 'xgs': + og_title = selector.xpath('//head/title/text()').get() og_description = selector.xpath( '//head/meta[@name="description"]/@content').get() og_url = url og_image = None else: - og_title = selector.xpath('//head/title/text()') + og_title = selector.xpath('//head/title/text()').get() og_description = selector.xpath( '//head/meta[@name="description"]/@content').get() og_url = url @@ -85,17 +85,6 @@ def parse(url): return (og_title, og_description, og_url, og_image) -@database_sync_to_async -def get_room_or_error(room_id, user): - """ - Tries to fetch a room for the user, checking permissions along the way. - """ - # Check if the user is logged in - if not user.is_authenticated: - raise ClientError("USER_HAS_TO_LOGIN") - - - def model_to_dict(instance, fields): opts = instance._meta data = {} @@ -121,6 +110,13 @@ def queryset_to_list(q, fields): if __name__ == '__main__': # sent_sms_code('13993199566') + # og_title, og_description, og_url, og_image = parse( + # 'https://mp.weixin.qq.com/s/EhX0Pm1e0FAfse0zz9ow8Q') + # og_title, og_description, og_url, og_image = parse( + # 'https://m.toutiao.com/i6883651337003729420/?tt_from=weixin&utm_campaign=client_share&app=news_article&utm_source=weixin&iid=1494959660475024&utm_medium=toutiao_android&wxshare_count=1') + # og_title, og_description, og_url, og_image = parse( + # 'http://www.gov.cn/xinwen/2020-10/13/content_5550906.htm') og_title, og_description, og_url, og_image = parse( - 'https://mp.weixin.qq.com/s/EhX0Pm1e0FAfse0zz9ow8Q') + 'http://xgs.gansudaily.com.cn/pages/h5/hot/b3297046a53e47f594ed19db90c1183c.html') + print(og_title, og_description, og_url, og_image) diff --git a/polls/views/__pycache__/notice.cpython-38.pyc b/polls/views/__pycache__/notice.cpython-38.pyc index 3eea7172c8f9ba6e799a1e6078d1b8b0ae04341f..61c10729548247f297fd678560e858b8afbe46ea 100644 GIT binary patch delta 143 zcmdm}xK)uWl$V!_0SF>PH*#HPmt@TntYJ$Lw_&JZt6@%&uwlsKs$t3!s$rh|i~XfY z5g$>kg5;F%Q&t`QlC8o(o T`S=;VH%IcM!mvJ770dipIU(uku0t((Hemi;a