将指定json格式的内容,写入文件中,构造测试数据

import sys
import datetime
import random
import string
import time

target = open("testdata.txt", 'a')
#指定需要产生多少条json数据
for i in range(100):
now = datetime.datetime.now()
now_time = now.strftime('%Y-%m-%d %H:%M:%S')
today = now.strftime('%Y-%m-%d')
add_time = ''.join(random.sample(string.digits, 10))
data="{\"log_ds\": \"" + today + "\"," + "\"log_id\": \"addfriend\", \"log_ts\": \"" + now_time + "\"," + "\"region\": 1, \"server\": \"6\", \"add_time\": " + add_time + "," + "\"host_pid\": \"1419395816029523974\", \"friend_pid\": \"1210342673502494726\", \"friend_count\": 1, \"adddouble.test\": 1.25}"

print(data)
target.writelines(str(data) + '\n')
time.sleep(0.01)
target.close()
posted on 2020-05-12 13:45  该用户很懒  阅读(413)  评论(0编辑  收藏  举报