def update_downloaded_chapter(self, downloaded_chapter): """ :param downloaded_chapter: downloaded chapter that has just updated to story Get all story data and 'date' = current_date If 'date' isn't existed on story['downloaded'] : Add new If date existed on story['downloaded'] and 'newest_chapter' isn't exist on that 'date': Add new chapter to date Update new value to story['downloaded'] """ if self.is_story_existed(): post = self.get_story()['downloaded'] date = utils.get_current_date() if date not in post: post[date] = [downloaded_chapter] elif downloaded_chapter not in post[date]: post[date].append(downloaded_chapter) post[date] = sorted(post[date], key=utils.sort_order_by_numeric) self.collection.update_one({'_id': self.story_name}, {'$set': {'downloaded': post}}) else: print 'Story "{0}" is NOT existed'.format(self.story_name)
def get_downloaded_chapter_by_date(self, t=utils.get_current_date()): return {x['_id']: x['downloaded'][t] for x in self.collection.find({'downloaded.{0}'.format(t): {'$exists': True}}, projection={'_id': 1, 'downloaded.{0}'.format(t): 1})}