def dump_text(url, out, fmt='%05d.txt', max_size=None, fid=1, max_fid=2500): utils.mkdir(out) fn = utils.join(out, fmt) if max_size is None: max_size = 4 * 1024 * 1024 zm = ZhhanzMan() zc = ZhCalc() fout = utils.openfile(fn % fid, 'w') records = [] for text in extract_text(url): prop = zc.calc(text) if zc.calc(text) > 1e-2: records.append(prop) fout.write(zm.s2t(text)) ft = fout.tell() progress = (ft / max(ft, max_size)) * 100 print(end=f'FID: {fid}/{max_fid}, File Size: {progress:5.2f}%\r') if fout.tell() >= max_size: fout.close() fid += 1 if fid > max_fid: break fout = utils.openfile(fn % fid, 'w') fout.close() with open('statistic.pkl', 'wb') as pkl: import pickle as pk pk.dump(records, pkl)
def __init__(self, filename, hash_key, key_persist, value_persist, block_size): self.hash_key = hash_key self.value_file = openfile(filename + '.dictionary') self.key_file = openfile(filename + '.posting') self.key_persist = key_persist self.value_persist = value_persist self.block_size = block_size self.index_cache = {} self.insert_index_cache = {}
def __init__(self, order, filename, persist): self.order = order self.persist = persist self.file = openfile(filename) self.file.seek(0, 2) self.filesize = self.file.tell()
def radiosobterurlstream(name,url): #GA("None","Radio - " + name) mensagemprogresso.create('TV Portuguesa','A carregar...') mensagemprogresso.update(0) if re.search('www.radios.pt',url): link=abrir_url(url) try: endereco=re.compile('<param name="url" value="(.+?)"').findall(link)[0] except: xbmc.executebuiltin("XBMC.Notification(Fightnight Music,Não é possível ouvir esta rádio.,'500000',)") return idradio=url.replace('http://www.radios.pt/portalradio/Sintonizador/?radio_id=','').replace('&scope=0','') thumbnail='http://www.radio.com.pt/APR.ROLI.WEB/Images/Logos/'+ idradio +'.gif' else: urlfinal='http://www.radioonline.com.pt/ajax/player.php?clear_s_name=' + url link= clean(abrir_url(urlfinal)) try: player=re.compile('soundManager.createSound\({(.+?)autoLoad').findall(link)[0] except: player=False try: endereco=re.compile('url: "(.+?)"').findall(player)[0].replace(';','') if re.search('serverURL',player): rtmp=re.compile('serverURL: "(.+?)"').findall(player)[0] #rtmp=rtmp.replace('rtmp://195.23.102.206','rtmp://195.23.102.209') #tempfix rtmp=rtmp.replace(':1936','') #tempfix endereco=rtmp + ' playPath=' + endereco except:endereco=False if not endereco: try:endereco=re.compile('<param name="URL" value="(.+?)"').findall(link)[0] except: try: endereco=re.compile('<object data="(.+?)"').findall(link)[0] except: endereco=False if not endereco: xbmc.executebuiltin("XBMC.Notification(TV Portuguesa,Não é possível ouvir esta rádio.,'500000',)") mensagemprogresso.close() return try:thumbnail=re.compile('<img id="station-logo-player" src="(.+?)"').findall(link)[0] except: thumbnail='' if re.search('.asx',endereco): nomeasx='stream.asx' path = xbmc.translatePath(os.path.join(pastaperfil)) lib=os.path.join(path, nomeasx) downloader(endereco,lib) texto= openfile(nomeasx) endereco = xbmc.PlayList(1) endereco.clear() streams=re.compile('<ref.+?"(.+?)"/>').findall(texto) for musica in streams: listitem = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=thumbnail) listitem.setInfo("music", {"Title":name}) endereco.add(musica,listitem) else: pass mensagemprogresso.close() listitem = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=thumbnail) listitem.setInfo("music", {"Title":name}) xbmc.Player().play(endereco,listitem)
def updateChannelList(self): idx=-1 listControl = self.getControl(6000) listControl.reset() canaison=openfile('canaison') canaison=canaison.replace('[','') lista=re.compile('B](.+?)/B]').findall(canaison) for nomecanal in lista: idx=int(idx+1) if idx==0: idxaux=' ' else: idxaux='%4s.' % (idx) item = xbmcgui.ListItem(idxaux + ' %s' % (nomecanal), iconImage = '') item.setProperty('idx', str(idx)) item.setProperty('chname', '[B]' + nomecanal + '[/B]') listControl.addItem(item)
def updateChannelList(self): idx = -1 listControl = self.getControl(6000) listControl.reset() canaison = openfile('canaison') canaison = canaison.replace('[', '') lista = re.compile('B](.+?)/B]').findall(canaison) for nomecanal in lista: idx = int(idx + 1) if idx == 0: idxaux = ' ' else: idxaux = '%4s.' % (idx) item = xbmcgui.ListItem(idxaux + ' %s' % (nomecanal), iconImage='') item.setProperty('idx', str(idx)) item.setProperty('chname', '[B]' + nomecanal + '[/B]') listControl.addItem(item)
entryMap = {} for line in user_entries: entry = Entry(line, defaults) debug(1, entry) entryMap.setdefault(entry.pdbid, []).append(entry) pdbids = entryMap.keys() pdbids.sort() for pdbid in pdbids: debug(1, pdbid) pdbfilename = goodpdbfilename(pdbid) if not pdbfilename: warning('Could not find PDB file for', pdbid) continue debug(2, pdbfilename) entries = entryMap[pdbid] infh = openfile(pdbfilename) for line in infh: rectype = line[:6].strip() if rectype in ['ENDMDL']: break if rectype not in ['ATOM', 'HETATM']: continue atom = PDBAtom(line) for entry in entries: if entry.accept(atom): OutputAtom(pdbid, atom)
def __init__(self, filename, persist): self.file = openfile(filename) self.persist = persist
def radiosobterurlstream(name, url): #GA("None","Radio - " + name) mensagemprogresso.create('TV Portuguesa', 'A carregar...') mensagemprogresso.update(0) if re.search('www.radios.pt', url): link = abrir_url(url) try: endereco = re.compile('<param name="url" value="(.+?)"').findall( link)[0] except: xbmc.executebuiltin( "XBMC.Notification(Fightnight Music,Não é possível ouvir esta rádio.,'500000',)" ) return idradio = url.replace( 'http://www.radios.pt/portalradio/Sintonizador/?radio_id=', '').replace('&scope=0', '') thumbnail = 'http://www.radio.com.pt/APR.ROLI.WEB/Images/Logos/' + idradio + '.gif' else: urlfinal = 'http://www.radioonline.com.pt/ajax/player.php?clear_s_name=' + url link = clean(abrir_url(urlfinal)) try: player = re.compile( 'soundManager.createSound\({(.+?)autoLoad').findall(link)[0] except: player = False try: endereco = re.compile('url: "(.+?)"').findall(player)[0].replace( ';', '') if re.search('serverURL', player): rtmp = re.compile('serverURL: "(.+?)"').findall(player)[0] #rtmp=rtmp.replace('rtmp://195.23.102.206','rtmp://195.23.102.209') #tempfix rtmp = rtmp.replace(':1936', '') #tempfix endereco = rtmp + ' playPath=' + endereco except: endereco = False if not endereco: try: endereco = re.compile( '<param name="URL" value="(.+?)"').findall(link)[0] except: try: endereco = re.compile('<object data="(.+?)"').findall( link)[0] except: endereco = False if not endereco: xbmc.executebuiltin( "XBMC.Notification(TV Portuguesa,Não é possível ouvir esta rádio.,'500000',)" ) mensagemprogresso.close() return try: thumbnail = re.compile( '<img id="station-logo-player" src="(.+?)"').findall(link)[0] except: thumbnail = '' if re.search('.asx', endereco): nomeasx = 'stream.asx' path = xbmc.translatePath(os.path.join(pastaperfil)) lib = os.path.join(path, nomeasx) downloader(endereco, lib) texto = openfile(nomeasx) endereco = xbmc.PlayList(1) endereco.clear() streams = re.compile('<ref.+?"(.+?)"/>').findall(texto) for musica in streams: listitem = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=thumbnail) listitem.setInfo("music", {"Title": name}) endereco.add(musica, listitem) else: pass mensagemprogresso.close() listitem = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=thumbnail) listitem.setInfo("music", {"Title": name}) xbmc.Player().play(endereco, listitem)
def _open(self): openfile(self._path) self._close()