Exemple #1
0
 def parse_new_posts(self, filename_list):
     for filename in filename_list:
         post_content = self.database.get_item('posts', filename)['content']
         if post_content:
             post_tmp = Post(filename=filename)
             post_tmp.parse_from_db(post_content)
             dir_name = os.path.join(settings.PUBLISH_DIR, post_tmp.url.strip("/\\"))
             file_path = os.path.join(dir_name, 'index.html')
             if os.path.exists(file_path):
                 os.remove(file_path)
             else:
                 logger.warning("Field to remove file: '{0}".format(post_tmp.title))
         post_tmp = Post(filename=filename)
         file_content = open(os.path.join(filename),'r')\
             .read().decode('utf8')
         if not post_tmp.check_illegal(file_content, filename=filename):
             # If the post_content is not illegal, pass it.
             logger.warning("This post doesn't have a correct format: '{0}".format(filename))
             continue
         else:
             post_tmp.parse()
         self.posts.append(post_tmp)
         self.new_posts.append(post_tmp)
         post_dict = post_tmp.__dict__.copy()
         post_dict['pub_time'] = time.mktime(
             post_dict['pub_time'].timetuple())
         post_dict.pop('config', None)
         last_mod_time = os.path.getmtime(
             os.path.join(filename))
         post_dict_in_db = {
             'last_mod_time': last_mod_time,
             'content': post_dict}
         self.database.set_item('posts', filename, post_dict_in_db)
Exemple #2
0
 def parse_new_posts(self, filename_list):
     for filename in filename_list:
         post_content = self.database.get_item('posts', filename)['content']
         if post_content:
             post_tmp = Post(filename=filename)
             post_tmp.parse_from_db(post_content)
             dir_name = os.path.join(settings.PUBLISH_DIR,
                                     post_tmp.url.strip("/\\"))
             file_path = os.path.join(dir_name, 'index.html')
             if os.path.exists(file_path):
                 os.remove(file_path)
             else:
                 logger.warning("Field to remove file: '{0}".format(
                     post_tmp.title))
         post_tmp = Post(filename=filename)
         file_content = open(os.path.join(filename),'r')\
             .read().decode('utf8')
         if not post_tmp.check_illegal(file_content, filename=filename):
             # If the post_content is not illegal, pass it.
             logger.warning(
                 "This post doesn't have a correct format: '{0}".format(
                     filename))
             continue
         else:
             post_tmp.parse()
         self.posts.append(post_tmp)
         self.new_posts.append(post_tmp)
         post_dict = post_tmp.__dict__.copy()
         post_dict['pub_time'] = time.mktime(
             post_dict['pub_time'].timetuple())
         post_dict.pop('config', None)
         last_mod_time = os.path.getmtime(os.path.join(filename))
         post_dict_in_db = {
             'last_mod_time': last_mod_time,
             'content': post_dict
         }
         self.database.set_item('posts', filename, post_dict_in_db)