|
2 | 2 | import uuid
|
3 | 3 | import random
|
4 | 4 | from datetime import datetime, timedelta
|
| 5 | +import requests |
| 6 | +from dotenv import load_dotenv |
| 7 | +import sys |
| 8 | +import os |
| 9 | + |
| 10 | +load_dotenv() |
5 | 11 |
|
6 | 12 | def create_mock_slides(db_path: str, count: int):
|
7 | 13 | conn = sqlite3.connect(db_path)
|
8 | 14 | cursor = conn.cursor()
|
9 | 15 |
|
10 |
| - filetypes = ["jpg", "png", "gif", "mp4"] |
11 | 16 | now = datetime.utcnow()
|
12 | 17 |
|
13 | 18 | slides = []
|
14 | 19 | for i in range(count):
|
15 | 20 | slide_id = str(uuid.uuid4())
|
| 21 | + |
| 22 | + try: |
| 23 | + image_path = f"../{os.environ['IMAGE_PATH']}/{slide_id}.jpg" |
| 24 | + except KeyError: |
| 25 | + sys.exit("Error: IMAGE_DIR environment variable is not set.") |
| 26 | + |
| 27 | + # Get random image from picsum.photos |
| 28 | + image = requests.get(f"https://picsum.photos/1920/1080").content |
| 29 | + |
| 30 | + with open(image_path, "wb") as image_file: |
| 31 | + image_file.write(image) |
| 32 | + |
16 | 33 | caption = f"Slide nr. {i}!"
|
17 | 34 | start_date = now + timedelta(days=random.randint(-10, 10))
|
18 | 35 | end_date = start_date + timedelta(days=random.randint(1, 10))
|
19 | 36 | active = random.choice([True, False])
|
20 |
| - filetype = random.choice(filetypes) |
21 | 37 |
|
22 |
| - slides.append((slide_id, caption, start_date, end_date, active, filetype)) |
| 38 | + slides.append((slide_id, caption, start_date, end_date, active, "jpg")) |
23 | 39 |
|
24 | 40 | cursor.executemany("""
|
25 | 41 | INSERT INTO slides (id, caption, start_date, end_date, active, filetype)
|
|
0 commit comments