def _GetAspellIndex(root=None): RAD = RemoteAspellDictionary response, content = urlcacheopen(httpjoin(root or RAD.ROOT, '0index.html'), decode=False) if not response.ok: print 'Unhandled HTTP response code: %r' % response return () soup = soupify(content) results = {} for row in soup.find('a', attrs=dict(name='0.50')).findAllNext('tr'): contents = row.findAll('td') if len(contents) == 4: id, name_english, name_native, dictionary_path = contents id = id.find(href=True) if id is None: continue id = id['href'] if id not in results: dictionary_path = dictionary_path.find(href=True) if dictionary_path is None: continue dictionary_path = dictionary_path['href'] name_english = name_english.renderContents(None).decode('xml') name_native = name_native.renderContents(None).decode( 'xml').strip() or None results[id] = RAD(id, name_english, name_native, id, dictionary_path) return results.values()
def _GetAspellIndex(root=None): RAD = RemoteAspellDictionary response, content = urlcacheopen(httpjoin(root or RAD.ROOT,'0index.html'), decode=False) if not response.ok: print 'Unhandled HTTP response code: %r' % response return () soup = soupify(content) results = {} for row in soup.find('a', attrs=dict(name='0.50')).findAllNext('tr'): contents = row.findAll('td') if len(contents) == 4: id, name_english, name_native, dictionary_path = contents id = id.find(href=True) if id is None: continue id = id['href'] if id not in results: dictionary_path = dictionary_path.find(href=True) if dictionary_path is None: continue dictionary_path = dictionary_path['href'] name_english = name_english.renderContents(None).decode('xml') name_native = name_native.renderContents(None).decode('xml').strip() or None results[id] = RAD(id, name_english, name_native, id, dictionary_path) return results.values()
def loadimages(self): try: self.img_sm = urlcacheopen(self.thumbnail_url) except: self.imb_sm = 'javascript' if self.img_sm and 'javascript' in self.img_sm: self.img_sm = None try: self.img_lg = urlcacheopen(self.web_url) except: self.img_lg = 'javascript' if self.img_lg and 'javascript' in self.img_lg: self.img_lg = None
def fetch_sig(self, root=None): ''' Fetches the .sig file for the remote dictionary file. Returns True if successful, else False. If successful, sets _needs_update to be True if the file has changed (that is, if it was fetched from the server and not the local cache). ''' if self.sig is None: response, content = urlcacheopen(self.get_digest_location(root)) if not response.ok: return False self.sig = content self.needs_update = not response.fromcache return True
def DownloadAllDictionaries(infodict, towhere, root=None): if root is None: root = RemoteAspellDictionary.ROOT for id in infodict: name = infodict[id]['name_english'] bz2path = infodict[id]['location'] localpath = path(towhere) / bz2path bz2path = httpjoin(root,bz2path) localpath = localpath.expand() print ('Downloading %s (%s) from %s to %s... ' % (name, id, bz2path, localpath)), response, content = urlcacheopen(bz2path) print response.reason if response.ok: if not localpath.parent.isdir(): localpath.parent.makedirs() with open(localpath, 'wb') as f: f.write(content)
def DownloadAllDictionaries(infodict, towhere, root=None): if root is None: root = RemoteAspellDictionary.ROOT for id in infodict: name = infodict[id]['name_english'] bz2path = infodict[id]['location'] localpath = path(towhere) / bz2path bz2path = httpjoin(root, bz2path) localpath = localpath.expand() print('Downloading %s (%s) from %s to %s... ' % (name, id, bz2path, localpath)), response, content = urlcacheopen(bz2path) print response.reason if response.ok: if not localpath.parent.isdir(): localpath.parent.makedirs() with open(localpath, 'wb') as f: f.write(content)