Difference between revisions of "Update bookmarks from file"
From MythTV Official Wiki
(A trivial script to replace websites with ones from your bookmarks) |
m (Mentioned that this code is Python in case it's not obvious) |
||
Line 1: | Line 1: | ||
− | This is some very basic code to simply remove all the existing websites and replace them with ones from your bookmarks file. | + | This is some very basic [http://www.python.org 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. | 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. |
Revision as of 00:53, 4 August 2006
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.
#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]