-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathcommands.py
33 lines (29 loc) · 1.15 KB
/
commands.py
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
31
32
33
"""
In this file, you can add as many commands as you want using the @app.cli.command decorator
Flask commands are usefull to run cronjobs or tasks outside of the API but sill in integration
with youy database, for example: Import the price of bitcoin every night as 12am
"""
import click
from api.models import db, Users
def setup_commands(app):
"""
This is an example command "insert-test-users" that you can run from the command line
by typing: $ flask insert-test-users 5
Note: 5 is the number of users to add
"""
@app.cli.command("insert-test-users") # Name of our command
@click.argument("count") # Argument of out command
def insert_test_users(count):
print("Creating test users")
for x in range(1, int(count) + 1):
user = Users()
user.email = "test_user" + str(x) + "@test.com"
user.password = "123456"
user.is_active = True
db.session.add(user)
db.session.commit()
print("User: ", user.email, " created.")
print("All test users created")
@app.cli.command("insert-test-data")
def insert_test_data():
pass