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

import django
django.setup()

###FAKE POP SCRIPT
import random
from first_app.models import AccessRecord,WebPage,Topic
from faker import Faker

fakegen = Faker()
topics = ['Searched', 'Social', 'Market', 'News', 'Games']

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

def populate(N=5):
    for entry in range(N):
        top = addTopic()
        fake_url =  fakegen.url()
        fake_date = fakegen.date()
        fake_name = fakegen.company()

        webpage = WebPage.objects.get_or_create(topic=top, url=fake_url,name =fake_name  )[0]
        accs_record = AccessRecord.objects.get_or_create(name=webpage, date = fake_date)[0]

if __name__ == '__main__' :
    print('Populate the script')
    populate(20)
    print('populaton complete')
