import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'pro.settings')

import django
django.setup()

# fake def
import random
from fa.models import AccessRecord , Webpage , Topic
from faker import Faker

fakegen = Faker()
topics = ['search', 'social', 'market place', 'news','games']

def add_topic():
    t = Topic.objects.get_or_create(top_name = random.choice(topics))[0]
    t.save()
    return t


def pop(N=5):

    for entry in range(N):
        top = add_topic()

        fake_url = fakegen.url()
        fake_date = fakegen.date_time()
        fake_name = fakegen.company()

        webpg = Webpage.objects.get_or_create(topic=top,url=fake_url,name=fake_name)[0]
        acc_rec = AccessRecord.objects.get_or_create(name=webpg , date=fake_date)[0]


if __name__ == '__main__':
    print("poulate data")
    pop(40)
    print("completed")
