Python模拟产生实时信令

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liuge36/article/details/86237135

模拟信令的生成

import random
import time
import os

infos = [
        "116.191031,39.988585",
        "116.389275,39.925818",
        "116.287444,39.810742",
        "116.481707,39.940089",
        "116.410588,39.880172",
        "116.394816,39.91181",
        "116.416002,39.952917"
]

phones = [
    "13888888888","13877777777","13866666666",
    "15788888888","15777777777","15766666666",
    "18288888888","18277777777","18266666666"
]

def sample_phone():
    return random.sample(phones,1)[0]

def sample_info():
    return random.sample(infos,1)[0]

def generate_log(count=5):
    time_str = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime())
    f = open(os.path.dirname(os.path.realpath(__file__))+"/auto.log","a+")
    while count >=1:
        query_log = "{phone}\t{info}\t[{time_str}]".format(phone=sample_phone(),info=sample_info(),time_str=time_str)
        print(query_log)

        f.write(query_log+"\n")
        count = count -1
if __name__ == '__main__':
    generate_log(10)



在上linux的定时执行任务就能实现,信令的实时模拟。

猜你喜欢

转载自blog.csdn.net/liuge36/article/details/86237135