[Zope] bookmark importer

Philipp Dunkel philipp@zreal.net
Fri, 10 Nov 2000 21:01:27 -0800


Hello guys I' have here a pyton file that allows you to import your
bookmarks from IE.
The following prob is that it works on windows98 zope 2.2.2  and not on a
unix system.
The file temp.txt stays empty and you get the message 'unable to export
favourites'

anyone any idea?




def GetBookmark(self):
    import string
    if self.REQUEST['HTTP_USER_AGENT']=='PostFavorites':
 print self.REQUEST.cookies
        file = self.REQUEST.stdin
 if file:
            file.seek(0)
            LBook=[]
            while 1:
                line = file.readline()
                if not line: break
                LBook.append(line)
        RBookmarkList=RList(LBook[RFirst(LBook):len(LBook)])
        print RBookmarkList
        ftemp = open('temp.txt','w')
        ftemp.write(RBookmarkList)
        ftemp.close()
        return 'RBookmarkList'
    else:
        s='<A
HREF=''javascript:window.external.ImportExportFavorites(false,'
        s=s+'"http://aegis:8080/Bookmarker");'
        s=s+'window.location.reload();>Click me...</A><P>'
        ftemp = open('temp.txt','r')
        if ftemp:
          l=ftemp.readline()
          ftemp.close()
          ftemp = open('temp.txt','w')
          ftemp.close()
          if l:
            s=s+l
        return s

def RFirst(l):
  import string
  for i in range(len(l)):
    if (string.find(l[i],"<DL>")>-1): return i
  return None

def RLast(l):
  import string
  k=0
  for i in range(len(l)):
    if string.find(l[i],"<DL>")>-1: k=k+1
    if string.find(l[i],"</DL>")>-1: k=k-1
    if k==0: return i

def RList(LD):
  import string
  Dict=''
  LDict=''
  iLast=0
  for i in range(len(LD)):
    if i>=iLast :
      l=LD[i]
      if (string.find(l,"<DT><A HREF")>-1):
        s=l[string.find(l,"<A HREF")+9:len(l)]
        s0=s[0:string.find(s,'"')]
        s=s[string.find(s,">")+1:len(s)]
        s=s[0:string.find(s,"<")]
        Dict='{title:"'+s+'", url:"'+s0+'"}'
        if LDict=="":
          LDict=Dict
        else:
          LDict=LDict+','+Dict
      if (string.find(l,"<DT>")>-1) and (string.find(l,"<A HREF")==-1):
        s=l[string.find(l,"<DT>")+4:len(l)]
        s=s[string.find(s,">")+1:len(s)]
        s=s[0:string.find(s,"<")]
        iFirst=i+1
        iLast=RLast(LD[iFirst:len(LD)])+iFirst
        LDNew=RList(LD[iFirst:iLast])
        Dict='{'+s+':['+LDNew+']}'
        if LDict=="":
          LDict=Dict
        else:
          LDict=LDict+','+Dict
  return LDict

TIA

Rishi