add message
This commit is contained in:
parent
7ce105c332
commit
e964957abc
|
@ -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,)
|
||||
|
|
|
@ -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)
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -96,10 +96,10 @@ def detail_notice(request, notice_id):
|
|||
detail['type'] = 'douyin'
|
||||
else:
|
||||
detail['type'] = 'qita'
|
||||
results['media'] = detail
|
||||
detail['status'] = m.status
|
||||
results['media'] = detail
|
||||
else:
|
||||
detail['group_id'] = notice.group_id
|
||||
results['groupId'] = notice.group_id
|
||||
results['added'] = notice.added.strftime("%Y-%m-%d %H:%M:%S")
|
||||
results['updated'] = notice.updated.strftime("%Y-%m-%d %H:%M:%S")
|
||||
return JsonResponse({'status': 'success', 'message': results})
|
||||
|
|
|
@ -72,7 +72,7 @@ def create_task(request):
|
|||
for u in users:
|
||||
g = Group.objects.get(id=group)
|
||||
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'})
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue