Update bookmarks from file

From MythTV Official Wiki
Jump to: navigation, search

This is some very basic Python code to simply remove all the existing websites and replace them with ones from your bookmarks file.

I'm not sure where to send this to make it available, hopefully this page will get spotted and shuffled off into the right place.

Script.png bookmarks.py

#Assumes you're using MySQL
import MySQLdb

#------ Settings ---------
bookmarksFile = "~/bookmarks.html"
db = MySQLdb.connect(host="mythdbserver", user="mythtv", passwd="mythtv", db="mythconverg")
#-------------------------

#Remove all existing website entries
deleter = db.cursor()
deleter.execute("DELETE FROM websites")

bookmarks = open(bookmarksFile,"r+t")
cursor = db.cursor()
urls=[]
currentGroupName = "Auto"
for line in bookmarks:
	urlStart=line.find("http")
	if urlStart !=-1:
		urlEnd= line.find('"',urlStart)
		url = line[urlStart:urlEnd]
		if not url in urls:			
			descStart=line.find('>',urlEnd)
			descEnd = line.find('<',descStart)
			dsc=line[descStart+1:descEnd]
			cursor.execute("INSERT INTO websites (grp, dsc, url) VALUES ('" + currentGroupName + "','" + dsc + "','" + url + "')")
			urls.append(url)

	groupNameFound = line.startswith("    <DT><H3")
	if groupNameFound:
		groupNameStarts=line.find(">",11)
		groupNameEnds=line.find("<",groupNameStarts)
		currentGroupName=line[groupNameStarts+1:groupNameEnds]