Implemented profiles.
This commit is contained in:
parent
0f57fff0aa
commit
58ed69c2cf
@ -1,6 +1,11 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from app.app import Application as BaseApplication, get_timestamp
|
from app.app import Application as BaseApplication, get_timestamp
|
||||||
from faker import Faker
|
from faker import Faker
|
||||||
|
from faker.providers import internet
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class Application(BaseApplication):
|
class Application(BaseApplication):
|
||||||
@ -11,17 +16,41 @@ class Application(BaseApplication):
|
|||||||
|
|
||||||
self.router.add_get("/", self.index_handler)
|
self.router.add_get("/", self.index_handler)
|
||||||
self.fake = Faker()
|
self.fake = Faker()
|
||||||
|
self.fake.add_provider(internet)
|
||||||
|
|
||||||
async def index_handler(self, request):
|
async def index_handler(self, request):
|
||||||
|
|
||||||
name = None
|
name = None
|
||||||
|
profile = None
|
||||||
while True:
|
while True:
|
||||||
name = self.fake.name()
|
name = self.fake.name()
|
||||||
if await self.is_name_used(name):
|
if await self.is_name_used(name):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
profile = self.fake.profile()
|
||||||
|
profile.update(
|
||||||
|
{
|
||||||
|
"uid": str(uuid.uuid4()),
|
||||||
|
"name": name,
|
||||||
|
"ipv4_private": self.fake.ipv4_private(),
|
||||||
|
"ipv4_public": self.fake.ipv4_public(),
|
||||||
|
"ipv6": self.fake.ipv6(True),
|
||||||
|
"mac_address": self.fake.mac_address(),
|
||||||
|
"username":self.fake.user_name(),
|
||||||
|
"description": self.fake.text(),
|
||||||
|
"created":get_timestamp()
|
||||||
|
}
|
||||||
|
)
|
||||||
break
|
break
|
||||||
await self.register_name_used(name)
|
profile = json.dumps(profile,default=str)
|
||||||
return web.json_response(name, content_type="application/json")
|
profile = json.loads(profile)
|
||||||
|
for key, value in profile.items():
|
||||||
|
if type(value) == list:
|
||||||
|
profile[key] = str(value)
|
||||||
|
await self.insert('profile',profile)
|
||||||
|
await self.register_name_used(profile['name'])
|
||||||
|
profile = json.dumps(profile,indent=2)
|
||||||
|
return web.Response(text=profile,content_type="application/json")
|
||||||
|
|
||||||
async def is_name_used(self, name):
|
async def is_name_used(self, name):
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user