def run(self): self.prepare_data() self.prepare_nlp_parser() views = self.extract() self.release_nlp_parser() write_json('./data/news_views_final.json', views) print('finished extract views')
def format_data(outpath='./data/news_content.json'): data = query_db() res = [] for news in data: content = news.content if content is None: continue content_json = text2json(content) res.append(content_json) write_json(outpath,res)
def format_data(outpath='./data/news_content.json'): dirpath = os.path.dirname(outpath) init_folder(dirpath) data = query_db() res = [] for news in data: content = news.content if content is None: continue content_json = text2json(content.replace('\\n', '\n')) res.append(content_json) write_json(outpath, res)
def extract(inpath='./data/news_content.json',outpath='./data/news_views.json'): data = read_json(inpath) all_sents = [] for news in data: for frag in news: para = frag['para'] sents = frag['sents'] all_sents.append(sents) views_infos = extract_views(all_sents) views_infos = process_views(views_infos) write_json(outpath,views_infos) print(os.path.abspath(os.path.curdir)) print('successfully extract views from all news...')
def post(self): resp = {'Created': False, 'FileName': 'N/A'} try: incoming_data = request.json['FileData'] except Exception as err: log.error(err) return make_response(jsonify(resp), 400) file_name = make_file_name() try: write_json(file_name, incoming_data) except Exception as err: log.error('FAILED write') log.error(err) return make_response(jsonify(resp), 400) resp['Created'], resp['FileName'] = True, file_name return jsonify(resp)