def saveReqToFile(req, fileName): printTab("Saving %s to %s" % (req.url, fileName)) setupTestData() #Save to file the content of request... theFile = getFilePath(fileName) with open(theFile, 'wb') as f: # Is possible to do f.write(theFile.content) # However, this is the recommend way for (possible) large responses # Write in chunks... I decide in 512. # http://stackoverflow.com/questions/13137817/how-to-download-image-using-requests for chunk in req.iter_content(512): f.write(chunk)
articles.append(createArticle( title=entry.title, description=entry.description, source=source, date=entry.published )) printExplain("To save several objects, use the batcher") batcher = ParseBatcher() batcher.batch_save(articles) print "Our news sources:" for source in sources.values(): printTab(source.title) print "The news from ", sources.values()[0].title for new in Article.Query.filter(source=sources.values()[0]): printSubTitle(new.title) print new.description printTitle("Conclusion") print """ Parse.com provide a easy way of store/query data, with not admin skills. Is not a replacemente for a proper Sql database (like postgresql or sql server) but provide a flexible data model apropiated for quick development and/or scalable acces to data, where the data must be denormalized anyway.. """
The first, is a URL link to a main topic, then the actual news. The other is just the new. """ # Set recursive=False to get only the first level of tags. If is True, # It will get all the tags below the tree, complicating the logic to # separate the 2 kinds of news... for event in tableEvents: ulNew = event.find_all("tr")[2].td.find_all('ul', recursive=False) for ul in ulNew: for li in ul.find_all('li', recursive=False): subUls = li.find_all('ul') # Is a headline + new(s)? if len(subUls): for subUl in subUls: processNews(subUl.find_all('li')) else: # Is a normal headline processNews([li]) for category in sorted(news): headlines = news[category] printSubTitle(category.encode('ascii', 'ignore')) for headline in headlines: printTab(headline.encode('ascii', 'ignore')) print