Browse Source

added the routers

pull/2/head
qiancj 1 year ago
parent
commit
f6eb910c70
  1. 14
      routers/__init__.py
  2. 30
      routers/fortune.py

14
routers/__init__.py

@ -0,0 +1,14 @@
# encoding: utf-8
"""
@author: Qiancj
@contact: qiancj@risenenergy.com
@file: __init__.py
@create-time: 2023-03-08 14:34
@description: The new python script
"""
__all__ = [
"FortuneAPI"
]
from routers.fortune import FortuneAPI

30
routers/fortune.py

@ -0,0 +1,30 @@
# encoding: utf-8
"""
@author: Qiancj
@contact: qiancj@risenenergy.com
@file: fortune
@create-time: 2023-03-08 14:34
@description: The new python script
"""
import os
from base64 import b64encode
from operator import itemgetter
from django.http import HttpResponse
from rest_framework.viewsets import ViewSet
from plugins import FortuneManager, fortune_config
class FortuneAPI(ViewSet):
@staticmethod
def fortune_today(request):
gid, uid, nickname = itemgetter(*("gid", "uid", "nickname"))(request.data)
fm = FortuneManager()
fm.divine(gid, uid, nickname)
pic_path = fortune_config.fortune_path / "out" / f"{gid}_{uid}.png"
with open(pic_path, "rb") as pic:
pies = pic.read()
os.remove(pic_path)
out = b64encode(pies).decode()
return HttpResponse(out)
Loading…
Cancel
Save