def handle(self, *args, **options): self.before_handle() f_name = "__js-1-50.json" f = open('fake/fake_threads/' + f_name, encoding='utf-8') s = json.load(f) s.reverse() # for i in s: # if not i['tittle']: # print(i) if not len(s): return j = 1 for i in s: self.get_data_ready(i) t = Thread() t.main_class = self.main_class_instance t.sub_class = self.sub_class_instance t.tittle = i['tittle'] if not '?' in t.tittle: t.tittle = t.tittle + "?" print(str(j), t.tittle) j = j + 1 t.create_user = self.user if i['content']: t.content = i['content'][0] else: t.content = "" t.like = self.like t.dislike = self.dislike t.reply = self.reply t.view = self.view t.save() self.add_comment(t.id, i['comment'])
def handle(self, *args, **options): self.before_handle() f_name = self.filename f = open('fake/fake_threads/' + f_name, encoding='utf-8') s = json.load(f) s.reverse() # for i in s: # if not i['tittle']: # print(i) if not len(s): return j = 1 for i in s: # if j < 19: # j = j+1 # continue try: self.get_data_ready(i) t = Thread() t.main_class = self.main_class_instance t.sub_class = self.sub_class_instance t.tittle = i['tittle'] if not '?' in t.tittle: t.tittle = t.tittle + "?" print(str(j), t.tittle) j = j + 1 t.create_user = self.user if i['content']: t.content = str(i['content'][0]) else: t.content = "" t.like = self.like t.dislike = self.dislike t.reply = self.reply t.view = self.view t.save() import jieba.posseg as pseg from forum.models import TAG accept_type = [ 'n', 'ns', 'eng', 'nr', 'l', 'vn', 'nz', 's', 'j', 'nt', 'nrt' ] s = t.tittle words = pseg.cut(s) for word, flag in words: if flag in accept_type: tag = TAG() tag.thread = t tag.name = word[:30] tag.save() self.add_comment(t.id, i['comment']) except: pass