add message

This commit is contained in:
baoliang 2020-10-22 00:29:06 +08:00
parent 7ce105c332
commit e964957abc
6 changed files with 24 additions and 28 deletions

View File

@ -170,7 +170,7 @@ class Userprofile(models.Model):
return Userprofile.objects.filter(organization__level__level=1) return Userprofile.objects.filter(organization__level__level=1)
def __str__(self): def __str__(self):
if self.is_leve1: if self.is_level1:
return '省级管理员%s' % (self.name,) return '省级管理员%s' % (self.name,)
elif self.is_level2: elif self.is_level2:
return '市级管理员%s' % (self.name,) return '市级管理员%s' % (self.name,)

View File

@ -4,7 +4,6 @@ import requests
import random import random
from parsel import Selector from parsel import Selector
from channels.db import database_sync_to_async from channels.db import database_sync_to_async
from .exceptions import ClientError
from django.conf import settings from django.conf import settings
from itertools import chain from itertools import chain
@ -40,6 +39,8 @@ def detect_type(url):
return 'toutiao' return 'toutiao'
elif 'ixigua.com' in url: elif 'ixigua.com' in url:
return 'xigua' return 'xigua'
elif 'gansudaily.com.cn' in url:
return 'xgs'
else: else:
return 'other' 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", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
} }
r = requests.get(url, headers=headers) r = requests.get(url, headers=headers)
r.encoding='utf-8'
print(r.text)
selector = Selector(text=r.text) selector = Selector(text=r.text)
if t == 'weixin': if t == 'weixin':
og_title = selector.xpath( og_title = selector.xpath(
@ -61,23 +64,20 @@ def parse(url):
'//head/meta[@property="og:url"]/@content').get() '//head/meta[@property="og:url"]/@content').get()
og_image = selector.xpath( og_image = selector.xpath(
'//head/meta[@property="og:image"]/@content').get() '//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': 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( og_description = selector.xpath(
'//head/meta[@name="description"]/@content').get() '//head/meta[@name="description"]/@content').get()
og_url = url og_url = url
og_image = None og_image = None
else: else:
og_title = selector.xpath('//head/title/text()') og_title = selector.xpath('//head/title/text()').get()
og_description = selector.xpath( og_description = selector.xpath(
'//head/meta[@name="description"]/@content').get() '//head/meta[@name="description"]/@content').get()
og_url = url og_url = url
@ -85,17 +85,6 @@ def parse(url):
return (og_title, og_description, og_url, og_image) 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): def model_to_dict(instance, fields):
opts = instance._meta opts = instance._meta
data = {} data = {}
@ -121,6 +110,13 @@ def queryset_to_list(q, fields):
if __name__ == '__main__': if __name__ == '__main__':
# sent_sms_code('13993199566') # 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( 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) print(og_title, og_description, og_url, og_image)

View File

@ -96,10 +96,10 @@ def detail_notice(request, notice_id):
detail['type'] = 'douyin' detail['type'] = 'douyin'
else: else:
detail['type'] = 'qita' detail['type'] = 'qita'
results['media'] = detail
detail['status'] = m.status detail['status'] = m.status
results['media'] = detail
else: else:
detail['group_id'] = notice.group_id results['groupId'] = notice.group_id
results['added'] = notice.added.strftime("%Y-%m-%d %H:%M:%S") results['added'] = notice.added.strftime("%Y-%m-%d %H:%M:%S")
results['updated'] = notice.updated.strftime("%Y-%m-%d %H:%M:%S") results['updated'] = notice.updated.strftime("%Y-%m-%d %H:%M:%S")
return JsonResponse({'status': 'success', 'message': results}) return JsonResponse({'status': 'success', 'message': results})

View File

@ -72,7 +72,7 @@ def create_task(request):
for u in users: for u in users:
g = Group.objects.get(id=group) g = Group.objects.get(id=group)
content = '%s在群组“%s”发布了任务,请查收消息' % (profile, g.name) content = '%s在群组“%s”发布了任务,请查收消息' % (profile, g.name)
Notice.create_normal_notice(u.user_id, content, group.id) Notice.create_normal_notice(u.user_id, content, group)
return JsonResponse({'status': 'success'}) return JsonResponse({'status': 'success'})