-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_image.py
More file actions
30 lines (19 loc) · 779 Bytes
/
random_image.py
File metadata and controls
30 lines (19 loc) · 779 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from random import randint
URL_ROOT = "https://raw.githubusercontent.com/JoshuaPeddle/ImageTransfer-server/master/random_images/"
# Get a list of filenames from random_images folder, these corrospond to the
# images that will be used for the random route
def load_image_names():
return [f for f in os.listdir("./random_images") if not f.startswith('.')]
random_images = load_image_names()
def generate_random_image_urls(n):
n = int(n)
if n > len(random_images):
n = len(random_images)
if n == 1:
return URL_ROOT + random_images[randint(0, len(random_images) - 1)]
urls = []
for i in range(n):
urls.append(URL_ROOT + random_images[randint(0, len(random_images) - 1)])
return urls
# Path: models/models.py