using database
This commit is contained in:
parent
892ae58b9a
commit
fc316bba8b
|
@ -1,5 +1,6 @@
|
|||
backend/__pycache__
|
||||
backend/randpic/__pycache__
|
||||
backend/randpic/migrations/__pycache__
|
||||
backend/tianyi/__pycache__
|
||||
backend/db.sqlite3
|
||||
backend/secret.txt
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
# Generated by Django 5.0.4 on 2024-04-30 01:11
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Picture',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('description', models.TextField()),
|
||||
('author', models.CharField(max_length=100)),
|
||||
('author_url', models.URLField()),
|
||||
('original_url', models.URLField()),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -2,6 +2,7 @@
|
|||
from azure.storage.blob import BlobServiceClient
|
||||
import os
|
||||
import json
|
||||
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:
|
||||
|
@ -10,6 +11,9 @@ def update_pictures(container='tianyi-random', remotedir='', secretdir='/home/ti
|
|||
blob_service_client = BlobServiceClient.from_connection_string(connect_str)
|
||||
container_client = blob_service_client.get_container_client(container)
|
||||
existing_files=[blob.name.split("/")[-1] for blob in container_client.list_blobs(name_starts_with=remotedir)]
|
||||
for file in existing_files:
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue