From 947b1078f6a53957b11691443a43f90a07447be6 Mon Sep 17 00:00:00 2001 From: tianyi Date: Tue, 30 Apr 2024 01:41:56 +0000 Subject: [PATCH] using database instead of json --- backend/randpic/random_picture.py | 4 +--- backend/randpic/update_pics.py | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/backend/randpic/random_picture.py b/backend/randpic/random_picture.py index fd45586..3d3186a 100644 --- a/backend/randpic/random_picture.py +++ b/backend/randpic/random_picture.py @@ -5,6 +5,4 @@ from .models import Picture pics=Picture.objects.order_by("?") def get_random_picture(): - with open("./jsons/pics.json") as f: - pictures = json.load(f) - return random.choice(pictures) \ No newline at end of file + return pics[0].name+".webp" \ No newline at end of file diff --git a/backend/randpic/update_pics.py b/backend/randpic/update_pics.py index 6e66091..cb2e7c9 100644 --- a/backend/randpic/update_pics.py +++ b/backend/randpic/update_pics.py @@ -2,7 +2,7 @@ from azure.storage.blob import BlobServiceClient import os import json -from models import Picture +from .models import Picture def update_pictures(container='tianyi-random', remotedir='', secretdir='/home/tianyi/repos/TianyiMoe/backend/secret.txt', jsondir='/home/tianyi/repos/TianyiMoe/backend/jsons/pics.json'): # print(os.getcwd()) try: @@ -15,8 +15,6 @@ def update_pictures(container='tianyi-random', remotedir='', secretdir='/home/ti if not Picture.objects.filter(name=file.split('.')[0]).exists(): Picture.objects.create(name=file.split('.')[0]) print("File number: " + str(len(existing_files))) - with open(jsondir, 'w') as f: - json.dump(existing_files, f, indent=4, sort_keys=True) except Exception as e: print(e)