【问题标题】:Where to store location data, which changes every second, for remote access存储位置数据的位置,每秒更改一次,用于远程访问
【发布时间】:2021-07-31 19:26:02
【问题描述】:

你好,希望你们一切都好。

我的 Android 设备上有一个 Python 脚本,它每秒获取位置数据(纬度和经度)。我希望这些不断变化的数据也可供少数其他人使用。他们需要每秒钟从 Python 脚本中获取设备的确切位置。我有一个我相信我可以使用的 cPanel 主机,但是,我没有以前的经验,我需要找到最简单的方法。简而言之,我有 cPanel 主机,我可以使用它来存储即时数据。但是,我不知道如何配置 cPanel 来存储数据。配置完成后,我应该使用哪个 Python 模块将数据发送到网络?

【问题讨论】:

    标签: python hosting cpanel


    【解决方案1】:

    我建议将该数据上传到 SQL 数据库。你还没有分享你的代码,所以我不能提供一个准确的例子,但你应该在你的 python 脚本中做这样的事情:

    import mysql.connector
    from mysql.connector import Error
    
    # database connection
    try:
        conn = mysql.connector.connect(
            host='localhost', database='coordinates_db', user='****', password='****')
    except Error as e:
        print(e)
    
    cursor = conn.cursor()
    
    
    # Latitude and Longitude example coordinates
    Latitude = '-27.51757'
    Longitude =  '49.66617'
    
    
    # Insert coordinates to database
    insert_query = f'INSERT INTO coordinates (Latitude, Longitude) VALUES ("{Latitude}, {Longitude}");'
    cursor.execute(insert_query)
    conn.commit()
    

    这应该是 SQL:

    /* Execute this line block to create a coordinates table */
    create table coordinates(
    id int auto_increment primary key,
    Latitude varchar(100),
    Longitude varchar(100)
    );
    
    /* Execute this line block to view coordinates table */
    Select * from coordinates;
    

    您当然必须将 python 文件中的数据库配置替换为您自己的数据库配置,您可以在 cpanel 中找到该配置。

    【讨论】:

    • 非常感谢您的详细解答!将很快检查代码和您的建议!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多