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("?")
|
pics=Picture.objects.order_by("?")
|
||||||
|
|
||||||
def get_random_picture():
|
def get_random_picture():
|
||||||
with open("./jsons/pics.json") as f:
|
return pics[0].name+".webp"
|
||||||
pictures = json.load(f)
|
|
||||||
return random.choice(pictures)
|
|
|
@ -2,7 +2,7 @@
|
||||||
from azure.storage.blob import BlobServiceClient
|
from azure.storage.blob import BlobServiceClient
|
||||||
import os
|
import os
|
||||||
import json
|
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'):
|
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())
|
# print(os.getcwd())
|
||||||
try:
|
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():
|
if not Picture.objects.filter(name=file.split('.')[0]).exists():
|
||||||
Picture.objects.create(name=file.split('.')[0])
|
Picture.objects.create(name=file.split('.')[0])
|
||||||
print("File number: " + str(len(existing_files)))
|
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:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue