diff --git a/app/models.py b/app/models.py index fbe1bd7..750ed16 100644 --- a/app/models.py +++ b/app/models.py @@ -9,8 +9,12 @@ class Clone(db.Document): created_at = db.DateTimeField(default=datetime.datetime.now, required=True) username = db.StringField(required=True, unique=True) - patterns = db.ListField(db.StringField(), required=True) - vocabulary = db.DictField(required=True) + + # Mad-lib Tweet patterns. + patterns = db.ListField(db.StringField(), required=True, default=[]) + + # { POS tag: words } + vocabulary = db.DictField(required=True, default={}) meta = { 'allow_inheritance': True, @@ -18,18 +22,11 @@ class Clone(db.Document): 'ordering': ['-created_at'] } - def imprint(self, username): + def imprint(self): """ Generate a clone for a given Twitter user. """ - self.username = username - user_tweets = twitter.tweets(username, count=2000) - - # { POS tag: words } - self.vocabulary = {} - - # Mad-lib Tweet patterns. - self.patterns = [] + user_tweets = twitter.tweets(self.username, count=2000) for tweet in user_tweets: text = tweet['body'] diff --git a/app/routes/clones.py b/app/routes/clones.py index 0844104..62041f4 100644 --- a/app/routes/clones.py +++ b/app/routes/clones.py @@ -16,7 +16,7 @@ def clones(): if form.validate_on_submit(): username = form.username.data clone = Clone.objects.get_or_create(username=username) - clone.imprint(username) + clone.imprint() clone.save() return redirect(url_for('clones.clone', username=username)) return render_template('clones/create.jade', form=form)