def convert_comment(db, site, root_url, filename): logger.info('convert %s' % filename) d = {} content = '' with open(filename) as f: for line in f: match = regex.match(line) if match: d[match.group(1)] = match.group(2) else: break is_header = True for line in f: if is_header: if line.strip(): is_header = False else: continue content = content + line # create DB record comment = Comment(site=site, author_name=d['author'], content=content) if 'email' in d: comment.author_email = d['email'].strip() if 'site' in d: comment.author_site = d['site'].strip() if 'url' in d: url = remove_from_string(d['url'], 'https://') url = remove_from_string(url, 'http://') comment.url = remove_from_string(url, root_url) # comment.url = remove_from_string(url, '/') # else: # comment.url = d['article'] if 'date' in d: pub = datetime.datetime.strptime(d['date'], '%Y-%m-%d %H:%M:%S') comment.created = pub comment.published = pub comment.save()