如何从Python读取/修改HTML5本地存储的本地文件? [英] How to read/modify a local file of HTML5 Local Storage from Python?

查看:599
本文介绍了如何从Python读取/修改HTML5本地存储的本地文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个 Ubuntu Webapp ,我想使用一个小小的黑客.

从Web应用程序中,我可以使用HTML5存储/检索值:

if (localStorage.getItem('showNotifications')) {
    // Enabling notifications...
}

我在Ubuntu中找到了该文件:

/home/costales/.local/share/Telegramzhukovgithubio/Local Storage/http_zhukov.github.io_0.localstorage

我想启动一个独立的Python对话框,该对话框具有一些首选项(显示通知,自动启动...),该python应用程序会在该文件中读取/写入值,然后Webapp会读取它并设置该配置. /p>

是否可以在Python中从.localstorage文件读取/写入该值?拜托,如何?预先感谢!

解决方案

有效的方法:)

import sqlite3
conn = sqlite3.connect('/home/costales/.local/share/Telegramzhukovgithubio/Local Storage/http_zhukov.github.io_0.localstorage')
c = conn.cursor()
c.execute("SELECT key,value FROM ItemTable where key='count'")
print c.fetchone()
conn.close()

I did an Ubuntu Webapp and I'd like to create a Preferences dialog with a litte hack.

From the webapp I can storage/retrieve values with HTML5:

if (localStorage.getItem('showNotifications')) {
    // Enabling notifications...
}

I found this file in Ubuntu:

/home/costales/.local/share/Telegramzhukovgithubio/Local Storage/http_zhukov.github.io_0.localstorage

I'd like to launch an independent Python dialog with a few preferences (show notifications, autostart...), that python app reads/writes values in that file, then the webapp will read it and setting that configuration.

Is possible to read/write that values from the .localstorage file in Python? Please,how? Thanks in advance!

解决方案

This worked :)

import sqlite3
conn = sqlite3.connect('/home/costales/.local/share/Telegramzhukovgithubio/Local Storage/http_zhukov.github.io_0.localstorage')
c = conn.cursor()
c.execute("SELECT key,value FROM ItemTable where key='count'")
print c.fetchone()
conn.close()

这篇关于如何从Python读取/修改HTML5本地存储的本地文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆