You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
from django.http import JsonResponse |
|
from django_redis import get_redis_connection |
|
from django.shortcuts import render |
|
from django.views.decorators.csrf import csrf_exempt |
|
from rest_framework import viewsets |
|
|
|
from group.serializers import GroupFuncsSerializer |
|
from group.utils.update_group_data import * |
|
from group.utils.main_process import main_update_process |
|
|
|
|
|
# Create your views here. |
|
@csrf_exempt |
|
def get_group_data(request): |
|
redis_conn = get_redis_connection() |
|
redis_key = f"group_data_{datetime.strftime(datetime.now(), '%Y-%m-%d')}" |
|
if not redis_conn.exists(redis_key): |
|
main_update_process() |
|
if redis_conn.exists(redis_key): |
|
print('获取Redis数据') |
|
redis_value = json.loads(redis_conn.get(redis_key)) |
|
result_dict = { |
|
'status': 'success', |
|
'data': redis_value, |
|
} |
|
else: |
|
result_dict = { |
|
'status': 'fail', |
|
'data': [], |
|
} |
|
return JsonResponse(result_dict, json_dumps_params={'ensure_ascii': False}) |
|
|
|
|
|
class GroupFuncsViewSet(viewsets.ModelViewSet): |
|
queryset = GroupFuncs.objects.all() |
|
serializer_class = GroupFuncsSerializer
|
|
|