Difference between revisions of "Update bookmarks from file"

From MythTV Official Wiki
Jump to: navigation, search
m (UpdateBookmarksFromFile moved to Update bookmarks from file: removing CamelCase)
Line 2: Line 2:
  
 
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.
 
+
{{Code box|bookmarks.py|
{{Box File|bookmarks.py|
 
 
<pre>
 
<pre>
 
#Assumes you're using MySQL
 
#Assumes you're using MySQL
Line 40: Line 39:
 
</pre>
 
</pre>
 
}}
 
}}
 +
 
[[Category:Python Scripts]]
 
[[Category:Python Scripts]]

Revision as of 14:30, 7 April 2007

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]