qiancj
1 year ago
2 changed files with 44 additions and 0 deletions
@ -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 |
@ -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…
Reference in new issue