yiorgos icon

loader.py

yiorgos | PRO | 10/15/19 02:11:30 PM UTC | 0 ⭐ | 484 👁️ | Never ⏰ | []
Python |

610 B

|

None

|

0 👍

/

0 👎

from datetime import datetime
from faker import Faker
from elasticsearch import Elasticsearch
import random
 
fake = Faker()
es = Elasticsearch()
 
tables = [ fake.first_name().lower() for i in range(5) ]
 
n = 0
while True:
    n += 1
    doc = { 'name': fake.first_name(),
        'surname': fake.last_name(),
        'company': fake.company(),
        'address': fake.address(),
        'email': fake.ascii_safe_email(),
        'timestamp': datetime.now(),
    }
 
    t = random.choice(tables)
    res = es.index(index=t, doc_type="faker", id=n, body=doc)
    print("{} {}".format(n, res['result']))

Comments