def testRecentStoriesForReal(self): mc = MediaCloud(self._config.get("api", "user"), self._config.get("api", "pass")) # test basic fetch stories = mc.recentStories() self.assertEquals(len(stories), mc.DEFAULT_STORY_COUNT) # test story limit stories = mc.recentStories(10) self.assertEquals(len(stories), 10) for story in stories: self.assertFalse(story.has_key("first_raw_download_file")) # test raw download option stories = mc.recentStories(10, True) for story in stories: self.assertTrue(story.has_key("first_raw_download_file"))
To Install: >>> import nltk >>> nltk.download() [ select d for Download ] [ enter "stopwords" as the identifier ] [ enter "punkt" as the identifier ] ''' config = ConfigParser.ConfigParser() config.read('mc-client.config') # set up a connection to a local DB db = StoryDatabase('mediacloud', config.get('db','host'), config.get('db','port') ) # connect to MC and fetch some articles mc = MediaCloud( config.get('api','user'), config.get('api','pass') ) results = mc.recentStories() print "Fetched "+str(len(results))+" stories" # set up my callback function that adds readability score to the story pub.subscribe(mediacloud.examples.addFleshKincaidGradeLevelToStory, StoryDatabase.EVENT_PRE_STORY_SAVE) # save all the stories in the db (this will fire the callback above) saved = 0 for story in results: worked = db.addStory(story) if worked: saved = saved + 1 print "Saved "+str(saved)+" stories"
def testRecentStories(self): mc = MediaCloud(None, None, True) stories = mc.recentStories() self.assertEquals(len(stories), 30)