<s> import os <EOL> os . environ . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> import django <EOL> django . setup ( ) <EOL> from django . contrib . auth . models import User as DjangoUser <EOL> from patchwords . models import * <EOL> import datetime , random <EOL> def populate ( ) : <EOL> populate_user ( ) <EOL> populate_category ( ) <EOL> populate_story ( ) <EOL> populate_paragraph ( ) <EOL> populate_like ( ) <EOL> populate_favourite ( ) <EOL> def populate_user ( ) : <EOL> add_user ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , date_of_birth = datetime . date ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> ) ) <EOL> add_user ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , date_of_birth = datetime . date ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) ) <EOL> add_user ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> add_user ( "<STR_LIT:test>" , "<STR_LIT>" , "<STR_LIT:test>" , "<STR_LIT>" ) <EOL> def populate_category ( ) : <EOL> add_category ( "<STR_LIT>" ) <EOL> add_category ( "<STR_LIT>" ) <EOL> add_category ( "<STR_LIT>" ) <EOL> add_category ( "<STR_LIT>" ) <EOL> add_category ( "<STR_LIT>" ) <EOL> add_category ( "<STR_LIT>" ) <EOL> add_category ( "<STR_LIT>" ) <EOL> add_category ( "<STR_LIT>" ) <EOL> add_category ( "<STR_LIT>" ) <EOL> def trim_newline ( s ) : <EOL> if s [ - <NUM_LIT:1> ] == "<STR_LIT:\n>" : <EOL> s = s [ : - <NUM_LIT:1> ] <EOL> return s <EOL> def populate_story ( ) : <EOL> users = User . objects . all ( ) <EOL> categories = Category . objects . all ( ) <EOL> titles_file = open ( "<STR_LIT>" , "<STR_LIT:r>" ) <EOL> titles = [ trim_newline ( l ) for l in titles_file ] <EOL> titles_file . close ( ) <EOL> for t in titles : <EOL> add_story ( t , random . choice ( users ) , random . choice ( categories ) ) <EOL> def populate_paragraph ( ) : <EOL> sentences_file = open ( "<STR_LIT>" , "<STR_LIT:r>" ) <EOL> sentences = [ trim_newline ( l ) for l in sentences_file ] <EOL> sentences_file . close ( ) <EOL> users = User . objects . all ( ) <EOL> stories = Story . objects . all ( ) <EOL> for s in stories : <EOL> paragraphs = [ ] <EOL> para = add_paragraph ( random . choice ( sentences ) , s , None , s . author ) <EOL> paragraphs . append ( para ) <EOL> for i in range ( <NUM_LIT:2> ) : <EOL> para = add_paragraph ( random . choice ( sentences ) , s , random . choice ( paragraphs ) , random . choice ( users ) ) <EOL> paragraphs . append ( para ) <EOL> def populate_like ( ) : <EOL> users = User . objects . all ( ) <EOL> paras = Paragraph . objects . all ( ) <EOL> for i in range ( <NUM_LIT:8> ) : <EOL> add_like ( random . choice ( users ) , random . choice ( paras ) ) <EOL> def populate_favourite ( ) : <EOL> users = User . objects . all ( ) <EOL> stories = Story . objects . all ( ) <EOL> for i in range ( <NUM_LIT:6> ) : <EOL> add_favourite ( random . choice ( users ) , random . choice ( stories ) ) <EOL> def add_user ( username , email , password , bio = "<STR_LIT>" , date_of_birth = None , picture = "<STR_LIT>" ) : <EOL> django_user = DjangoUser . objects . get_or_create ( username = username , email = email ) [ <NUM_LIT:0> ] <EOL> django_user . set_password ( password ) <EOL> django_user . save ( ) <EOL> print django_user <EOL> user = UserProfile . objects . get_or_create ( user = django_user , bio = bio , date_of_birth = date_of_birth , picture = picture ) [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" , user <EOL> return user <EOL> def add_category ( title ) : <EOL> cat = Category . objects . get_or_create ( title = title ) [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" , cat <EOL> return cat <EOL> def add_story ( title , author , category ) : <EOL> story = Story . objects . get_or_create ( title = title , author = author , category = category ) [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" , story <EOL> return story <EOL> def add_paragraph ( content , story , parent , author , end = False ) : <EOL> para = Paragraph . objects . get_or_create ( content = content , story = story , parent = parent , author = author , end = end ) [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" , para <EOL> return para <EOL> def add_like ( user , paragraph ) : <EOL> like = Like . objects . get_or_create ( user = user , paragraph = paragraph ) [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" , like <EOL> return like <EOL> def add_favourite ( user , story ) : <EOL> fav = Favourite . objects . get_or_create ( user = user , story = story ) [ <NUM_LIT:0> ] <EOL> print "<STR_LIT>" , fav <EOL> return fav <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> print "<STR_LIT>" <EOL> populate ( ) </s>
