def create_story(self): story = Story() story.headline = "This Is A Test Story" #normally slugify will be handled by the UI story.slug = slugify(story.headline) summary = "Like I said in the headline, this is a test story." #TODO add an author(s) story.save() return story
try: #seeing if the story is in the db already or not. story = Story.objects.get( id= entry.link.split("/")[-3] ) print "Story %s already in the db" % entry.link.split("/")[-3] except: story = Story() print "Story %s not found. inserting into db" % entry.link.split("/")[-3] #now we need to get our story id from the url #we take the link from the entry. split it by / and then grab the 3rd item from the end story.id = entry.link.split("/")[-3] story.short_url = "http://www.news-leader.com/article/2010%s" % story.id story.long_url = entry.link story.active = True story.category = entry.link.split("/")[-4] story.headline = entry.title story.summary = entry.summary story.date_published = datetime.datetime( entry.updated_parsed[0], entry.updated_parsed[1], entry.updated_parsed[2], entry.updated_parsed[3], entry.updated_parsed[4], entry.updated_parsed[5] ) print "saving story" story.save() #keyword section try: keyword = Keyword.objects.get(story_id=story, keyword="crime") print "keyword already exists" except: keyword = Keyword() print "inserting keyword" keyword.story = story keyword.keyword = "crime"