Python CLI编辑Firefox书签? [英] Python CLI to edit Firefox bookmarks?

查看:66
本文介绍了Python CLI编辑Firefox书签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人做过Python CLI来编辑Firefox书签吗? 我的世界观是Unix文件树.我要

  • 在给定或所有子树的给定或所有字段中查找/re/
  • cd
  • 具有上下文的
  • mv this ../there/

无论使用bookamrks.html还是places.sqlite都是次要的-更简单.
补充说明:我很乐意退出Firefox,在CLI中编辑书签,在Firefox中导入新数据库. 换句话说,数据库锁定是有争议的.首先,让我们看一下粗略的CLI的代码.

(为什么是文本CLI而不是GUI? CLI对我来说更简单,并且可以轻松编程例如 mv old-bookmarks to 2009/same-structure/. 尽管如此,链接到用于Firefox或其他任何工具的非常好的书签GUI也会很有用.)

解决方案

假设我们正在谈论的是Firefox 3或更高版本,则书签将保存在SQLite文件中,即配置文件文件夹中的org/Places.sqlite"rel =" nofollow noreferrer> places.sqlite .因此,您需要一个例程来查找配置文件文件夹(取决于您的平台),然后才能加载SQLite文件.

该模式丰富且有点复杂,但是有据可查,当然,借助Python的SQLite支持,您可以进行交互式浏览.

当然,Firefox在数据库运行时会将其锁定.对于只读访问,您可以将places.sqlite复制到一个临时文件中,然后打开并浏览该文件.按照您的要求执行更改,但是,最好是要求用户退出Firefox(如果这是不可接受的,则可以探索Firefox是否提供一种要求其合作的方式).

这是您想到的吗...?

Has anyone done a Python CLI to edit Firefox bookmarks ? My worldview is that of Unix file trees; I want

  • find /re/ in given or all fields in given or all subtrees
  • cd
  • ls with context
  • mv this ../there/

Whether it uses bookamrks.html or places.sqlite is secondary -- whatever's easier.
Clarification added: I'd be happy to quit Firefox, edit bookmarks in the CLI, import the new database in Firefox. In otherwords, database locking is a moot point; first let's see code for a rough cut CLI.

(Why a text CLI and not a GUI ? CLIs are simpler (for me), and one could easily program e.g. mv old-bookmarks to 2009/same-structure/. Nonetheless links to a really good bookmarker GUI, for Firefox or anything else, would be useful too.)

解决方案

Assuming we're talking about Firefox 3 or better, the bookmarks are kept in a SQLite file, places.sqlite in the profile folder. So you need a routine to find the profile folder (depending on your platform) and then you can load the SQLite file.

The schema's rich and a bit complicated, but well documented, and of course with Python's SQLite support you can explore it interactively.

Of course, Firefox keeps the DB locked when it's running. For read-only access, you can just copy places.sqlite into a temporary file, then open and explore that one; to perform changes as you seem to require, however, it seems best to require the user to quit Firefox (if that's unacceptable, you could explore if Firefox offers a way to ask for its cooperation).

Is this the kind of things you had in mind...?

这篇关于Python CLI编辑Firefox书签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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