ui.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:dnflow 作者: DocNow 项目源码 文件源码
def sample(date_path):
    try:
        sample_size = int(request.form.get('sample_size', None))
    except ValueError:
        return redirect(url_for('summary', date_path=date_path))
    summary = json.load(open('data/%s/summary.json' % date_path, 'r'))
    num_tweets = summary['num_tweets']
    tweet_index = np.arange(num_tweets)
    shuffle(tweet_index)
    tweet_index = tweet_index[0:sample_size]
    counter = 0
    with open('data/%s/sample.csv' % date_path, 'w') as sample_file:
        writer = csv.writer(sample_file) 
        writer.writerow(json2csv.get_headings())
        with open('data/%s/tweets.json' % date_path,'r') as tweets_file:
            for line in tweets_file:
                tweet = json.loads(line)
                if counter in tweet_index:
                    writer.writerow(json2csv.get_row(tweet))
                counter += 1
    return redirect(url_for('summary', date_path=date_path))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号