示例#1
0
 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')
示例#2
0
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)
示例#3
0
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)
示例#4
0
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...')
示例#5
0
    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)