using database instead of json
This commit is contained in:
parent
fc316bba8b
commit
947b1078f6
|
@ -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)
|
||||
return pics[0].name+".webp"
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue