Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4f1be2e89d |
28
main.py
28
main.py
@ -1,3 +1,5 @@
|
|||||||
|
import random
|
||||||
|
import string
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from random import randint
|
from random import randint
|
||||||
from typing import AsyncGenerator
|
from typing import AsyncGenerator
|
||||||
@ -59,3 +61,29 @@ async def root():
|
|||||||
r = randint(1, cnt)
|
r = randint(1, cnt)
|
||||||
record = await RawData.get(id=r)
|
record = await RawData.get(id=r)
|
||||||
return {"title": record.title, "content": record.content}
|
return {"title": record.title, "content": record.content}
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_price():
|
||||||
|
return round(random.uniform(10.0, 1000.0), 2)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_sales():
|
||||||
|
return random.randint(100, 10000)
|
||||||
|
|
||||||
|
|
||||||
|
def generate_random_batch_number():
|
||||||
|
return ''.join(random.choices(string.ascii_uppercase + string.digits, k=10))
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/product/")
|
||||||
|
async def get_product_info(name: str):
|
||||||
|
price = generate_random_price()
|
||||||
|
sales = generate_random_sales()
|
||||||
|
batch_number = generate_random_batch_number()
|
||||||
|
|
||||||
|
return {
|
||||||
|
"name": name,
|
||||||
|
"price": price,
|
||||||
|
"sales": sales,
|
||||||
|
"batch_number": batch_number
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user