Completed
Pull Request — master (#480)
by Jace
02:01
created

generate_sample_images()   B

Complexity

Conditions 6

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 11
nop 0
dl 0
loc 13
rs 8.6666
c 0
b 0
f 0
1
"""Prerender common images used in the application."""
2
3
import asyncio
4
5
from memegen.settings import ProductionConfig
6
from memegen.factory import create_app
7
from memegen.domain import Text
8
9
10
async def generate_sample_images():
11
    app = create_app(ProductionConfig)
12
    async with app.app_context():
13
14
        options = []
15
        for template in app.template_service.all():
16
            for text in [Text("_"), template.sample_text]:
17
                for watermark in ["", "memegen.link"]:
18
                    options.append((template, text, watermark))
19
20
        print(f"Generating {len(options)} sample images...")
21
        for template, text, watermark in options:
22
            app.image_service.create(template, text, watermark=watermark)
23
24
25
if __name__ == '__main__':
26
    asyncio.run(generate_sample_images())
27