-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
main.py
65 lines (54 loc) · 1.3 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
"""
Main FastAPI app.
"""
# -*- coding: utf-8 -*-
from typing import List
from fastapi import FastAPI, Query
from description import desc
from helpers import emojis, passwd, random_users
from pydantic_models import Emoji, Password, Person
app = FastAPI(
title="Something Random...",
description=desc,
version="0.0.1",
docs_url="/",
)
@app.get("/person", response_model=List[Person], tags=["Randomness..."])
async def random_persons(
num: int = Query(
5,
title="Get a random list of people.",
ge=1,
le=50,
)
) -> List[Person]:
"""
Get a random list of persons.
The defautl is 5
"""
persons = random_users.create(iterations=num)
return persons
@app.get("/password", response_model=Password, tags=["Randomness..."])
async def random_password(
num: int = Query(
8,
title="Length of password.",
le=64,
),
hashing: bool = Query(
False,
title="Return an MD5 hashed password",
),
):
"""
Generate a random password.
"""
password = passwd(num, hashing)
return {"password": password}
@app.get("/emoji", response_model=Emoji, tags=["Randomness..."])
async def random_emoji():
"""
Return a random emoji.
"""
return {"emoji": emojis()}