def pages(): """Generate all ranking pages and the HTML index.""" def get_str(chart): return chart["str"].upper() def mk_cap(mode): return mode.capitalize() idx = index.read() for name in set(key for mode in (game.mode.star, game.mode.pop) for key in idx[mode]): tabs = [] clean_name = clean(name) if exists(path.db.star + clean_name + ".json"): tabs.append(mk_cap(game.mode.star)) if exists(path.db.nm + clean_name + ".json"): tabs.append(get_str(game.chart.nm)) if exists(path.db.hd + clean_name + ".json"): tabs.append(get_str(game.chart.hd)) if exists(path.db.mx + clean_name + ".json"): tabs.append(get_str(game.chart.mx)) if exists(path.db.ex + clean_name + ".json"): tabs.append(get_str(game.chart.ex)) if len(tabs) > 0: _page(tabs, name, "./images/disc") for name in (key for key in idx[game.mode.club]): if exists(path.db.club + clean(name) + ".json"): _page([mk_cap(game.mode.club)], name, "./images/club") for name in (key for key in idx[game.mode.mission]): if exists(path.db.mission + clean(name) + ".json"): _page([mk_cap(game.mode.mission)], name, "./images/mission") _page([mk_cap(game.mode.star), get_str(game.chart.nm), get_str(game.chart.hd), get_str(game.chart.mx), mk_cap(game.mode.pop), mk_cap(game.mode.club), mk_cap(game.mode.mission)], "Master") _index(idx)
def run(self): common.clean('tmp') logger.info('Patching...Pls wait...') downloadAndExecGenerate.generate(url=self.url, filename=self.download_filename) l = LurkGUI(FILE=self.file, ADDRESS=self.address) l.patch_it()
def maybe_save_model(model, opt, schd, epoch, save_path, curr_val, other_values, old_path=''): path = old_path def no_other_values(other_values): return len(other_values) == 0 if no_other_values(other_values) or curr_val < min(other_values): print('saving model...') path = save_train(save_path, model, opt, schd, epoch) print("new checkpoint at %s"%path) clean(save_path, save_count=10) return path
def create(mode, name): """Create a local record of the specified mode and name. Arguments: mode -- One of the four game modes. name -- The full name of a disc, disc set, or mission. """ all_charts = (game.chart.nm, game.chart.hd, game.chart.mx, game.chart.ex) all_pop_paths = (path.db.nm, path.db.hd, path.db.mx, path.db.ex) if mode == game.mode.star: level = [(game.chart.nm, path.db.star)] elif mode == game.mode.pop: level = zip(all_charts, all_pop_paths) elif mode == game.mode.club: level = [(game.chart.nm, path.db.club)] elif mode == game.mode.mission: level = [(game.chart.nm, path.db.mission)] else: raise ValueError("Invalid game mode") for chart, directory in level: results = ranking.get(mode, name, chart) if results: clean_name = clean(name) record = dict() record["name"] = name record["eyecatch"] = "{}.png".format(clean_name) record["icon"] = "{}_{}.png".format(clean_name, chart["int"]) record["ranking"] = results with open(directory + clean_name + ".json", "wb") as f: f.write(json.dumps(record, indent=1).encode()) print('Wrote: "{}{}.json"'.format(directory, clean_name))
def AddDir(name, mode, url='', image=None, isFolder=True, page=1, keyword=None, infoLabels=None, menu=None): name = common.clean(name) if not image: image = ICON u = sys.argv[0] u += '?mode=' + str(mode) u += '&title=' + urllib.quote_plus(name) u += '&image=' + urllib.quote_plus(image) u += '&page=' + str(page) if url != '': u += '&url=' + urllib.quote_plus(url) if keyword: u += '&keyword=' + urllib.quote_plus(keyword) liz = xbmcgui.ListItem(name, iconImage=image, thumbnailImage=image) if menu: liz.addContextMenuItems(menu) if infoLabels: infoLabels['title'] = name else: infoLabels = { 'title' : name } liz.setInfo(type="Video", infoLabels=infoLabels) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=isFolder)
def search_episode(info): iters = [] filters.use_TV() titles = get_titles(info['title'], info['tvdb_id']) for title in titles: query = common.clean(title) + ' %02d' % info['absolute_number'] iters.append(search(query)) return chain.from_iterable(iters)
def run_this(self): # common.clean('tmp') self.gather_info() if self.CAVE_FOUND is True: cave_tracker = self.find_all_caves() if self.JUMP_CAVES is True: cave_tracker = self.find_add_caves() if self.APPEND_SECTION is True: self.append_section() if self.OUTPUT: output_filename = self.OUTPUT else: output_filename = self.FILE + '.patched.exe' self.set_config_file_and_build() self.do_patch(self.final_bin) self.save(output_filename) common.clean('tmp') logger.info("End") return True
def maybe_save_model(model, opt, schd, epoch, save_path, curr_val, other_values, model_path=None): path = model_path if model_path is not None else '' if not other_values or curr_val > max(other_values): path = save_train(save_path, model, opt, schd, epoch) print(f'saving model at path {path} new max psnr {curr_val}') clean(save_path, save_count=10) elif curr_val < max(other_values) - 1: load_train(path, model, opt) schd.step() print( f'model diverge reloded last model state current lr {schd.get_lr()}' ) return path
def _page(tabs, name, img_dir=None): """Generate a ranking page.""" sm = simplemarkup.SimpleMarkup(2) sm.rawln("<!DOCTYPE html>") sm.beginln("html") _head(sm) sm.beginln("body") # jquery tabs sm.beginln("div", [("id", "ranking")]) sm.beginln("ul") for tab in tabs: sm.begin("li").begin("a", [("href", "#" + tab)], tab).end().endln() sm.endln() # ul for tab in tabs: sm.beginln("div", [("id", tab)]) sm.begin("p") if img_dir is None: sm.raw(name) else: sm.empty("img", [("src", "{}/{}_{}.png".format(img_dir, clean(name), (lambda x: 2 if x == "HD" else 3 if x == "MX" else 4 if x == "EX" else 1)(tab)))]) sm.raw(" " + name) sm.endln() # p sm.begin("p", value="Loading...").endln() sm.endln() # div sm.endln() # div (tabs) _tail(sm) sm.endln() # body sm.endln() # html with open(path.root + clean(name) + ".html", "wb") as f: f.write(sm.output().encode())
def PlayVideo(_url, select): resolved = resolve.ResolveURL(_url) if len(resolved) == 0: url = None msg = 'Unidentified Video Host' else: index = GetLinkIndex(resolved, select) if index == None: xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, xbmcgui.ListItem('')) return resolver = resolved[index][0] url = resolved[index][1] msg = resolved[index][2] if url: url = url.split('"')[0] url = url.replace(' ', '%20') if not url: d = xbmcgui.Dialog() d.ok(TITLE + ' - ' + VERSION, '', msg, '') print 'WATCHCARTOONSONLINE - (%s) Failed to locate video for %s' % ( msg, _url) return html = common.getHTML(_url) image = re.compile('"image_src" href="(.+?)"').search(html).group(1) title = re.compile('<title>(.+?)</title>').search(html).group(1).split( ' |', 1)[0] title = common.clean(title) liz = xbmcgui.ListItem(title, iconImage=image, thumbnailImage=image) liz.setInfo(type="Video", infoLabels={"Title": title}) liz.setProperty("IsPlayable", "true") if int(sys.argv[1]) == -1: pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) pl.clear() pl.add(url, liz) xbmc.Player().play(pl) else: liz.setPath(url) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
def AddDir(name, mode, url='', image=None, isFolder=True, page=1, keyword=None, infoLabels=None, contextMenu=None): name = common.clean(name) if not image: image = ICON u = sys.argv[0] u += '?mode=' + str(mode) u += '&title=' + urllib.quote_plus(name) u += '&image=' + urllib.quote_plus(image) u += '&page=' + str(page) if url != '': u += '&url=' + urllib.quote_plus(url) if keyword: u += '&keyword=' + urllib.quote_plus(keyword) liz = xbmcgui.ListItem(name, iconImage=image, thumbnailImage=image) if contextMenu: liz.addContextMenuItems(contextMenu) if infoLabels: infoLabels['title'] = name else: infoLabels = {'title': name} try: if mode == EPISODE and cache.get(common.fixup(name)): infoLabels['playcount'] = 1 except: pass liz.setInfo(type="Video", infoLabels=infoLabels) xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]), url=u, listitem=liz, isFolder=isFolder)
def PlayVideo(_url, select): resolved = resolve.ResolveURL(_url) if len(resolved) == 0: url = None msg = 'Unidentified Video Host' else: index = GetLinkIndex(resolved, select) if index == None: xbmcplugin.setResolvedUrl(int(sys.argv[1]), False, xbmcgui.ListItem('')) return resolver = resolved[index][0] url = resolved[index][1] msg = resolved[index][2] if url: url = url.split('"')[0] url = url.replace(' ', '%20') if not url: d = xbmcgui.Dialog() d.ok(TITLE + ' - ' + VERSION, '', msg, '') print 'WATCHCARTOONSONLINE - (%s) Failed to locate video for %s' % (msg, _url) return html = common.getHTML(_url) image = re.compile('"image_src" href="(.+?)"').search(html).group(1) title = re.compile('<title>(.+?)</title>').search(html).group(1).split(' |', 1)[0] title = common.clean(title) liz = xbmcgui.ListItem(title, iconImage=image, thumbnailImage=image) liz.setInfo( type="Video", infoLabels={ "Title": title} ) liz.setProperty("IsPlayable","true") if int(sys.argv[1]) == -1: pl = xbmc.PlayList(xbmc.PLAYLIST_VIDEO) pl.clear() pl.add(url, liz) xbmc.Player().play(pl) else: liz.setPath(url) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, liz)
def DownloadVideo(_url, title): resolved = resolve.ResolveURL(_url) title = common.clean(title) if len(resolved) == 0: d = xbmcgui.Dialog() d.ok(TITLE + ' - ' + VERSION, 'Unable to download', title, 'Cannot find an online source') return auto = ADDON.getSetting('DOWNLOAD_AUTO') index = GetLinkIndex(resolved, not auto) if index < 0: return url = resolved[index][1] file = urllib.unquote_plus(url.rsplit('/')[-1]) file = FileSystemSafe(file) folder = ADDON.getSetting('DOWNLOAD_FOLDER') if len(folder) == 0: folder = 'special://profile/addon_data/plugin.video.watchcartoononline/downloads' import sfile if not sfile.exists(folder): sfile.makedirs(folder) file = os.path.join(folder, file) try: import download download.download(url, file, title) except Exception, e: print '%s - %s Error during downloading of %s' % (TITLE, VERSION, title) print str(e)
def disc(): """Download disc, disc set, and mission icons from the DJMAX site. An icon will be skipped if it is determined that it already exists. Existence is checked by a simple path check. """ all_id_urls = (url.id.star, url.id.pop, url.id.club, url.id.mission) all_img_urls = (url.img.star, url.img.pop, url.img.club, url.img.mission) all_img_dirs = (path.img.star, path.img.pop, path.img.club, path.img.mission) all_keys = (site.key.star, site.key.pop, site.key.club, site.key.mission) all_pages = (site.pages.star, site.pages.pop, site.pages.club, site.pages.mission) all_suffixes = (1, 4, 1, 1) # image suffix ranges for id_url, img_url, img_dir, key, end, suffix in zip( all_id_urls, all_img_urls, all_img_dirs, all_keys, all_pages, all_suffixes ): images = [] for page in range(1, end + 1): for record in urlopen_json(id_url.format(page), "Retrieving image name"): images.append( (record[key["image"]] + (".png" if key == site.key.mission else ""), clean(record[key["name"]])) ) for image in images: unclean_name = image[0] name, ext = image[0].rsplit(".", 1) for i in range(1, suffix + 1): clean_name = "{}_{}.{}".format(image[1], i, ext) if exists(img_dir + clean_name): continue if key == site.key.pop: unclean_name = "{}{}.{}".format(name[:-1], i, ext) with open(img_dir + clean_name, "wb") as f: f.write(urlopen_image(img_url.format(unclean_name))) print('Wrote: "{}{}"'.format(img_dir, clean_name))
def _index(idx): """Generate the HTML index.""" discs = sorted(set(key for mode in (game.mode.star, game.mode.pop) for key in idx[mode])) discsets = sorted(key for key in idx[game.mode.club]) missions = sorted(key for key in idx[game.mode.mission]) sm = simplemarkup.SimpleMarkup(2) sm.rawln("<!DOCTYPE html>") sm.beginln("html") _head(sm) sm.beginln("body") # jquery accordion sm.beginln("div", [("id", "root")]) sm.begin("h3", value="Rankings").endln() sm.beginln("div", [("id", "rankings")]) sm.beginln("table") sm.beginln("tr") sm.beginln("td") for count, name in enumerate(discs[:]): sm.begin("a", [("href", "./{}.html".format(clean(name)))], name).end().emptyln("br") discs.pop(0) if count > 107: # no more than this number of items in the first column break sm.endln() # td sm.beginln("td") # here starts the second column for name in discs: sm.begin("a", [("href", "./{}.html".format(clean(name)))], name).end().emptyln("br") sm.rawln("<br /><br />") for name in discsets: sm.begin("a", [("href", "./{}.html".format(clean(name)))], name).end().emptyln("br") sm.rawln("<br /><br />") for name in missions: sm.begin("a", [("href", "./{}.html".format(clean(name)))], name).end().emptyln("br") sm.rawln("<br /><br />") sm.begin("a", [("href", "./master.html")], "Master").end().emptyln("br") sm.endln() # td sm.endln() # tr sm.endln() # table sm.endln() # div sm.begin("h3", value="Me").endln() sm.beginln("div", [("id", "me")]) sm.begin("p", value="Go to settings to enter your DJ name.") sm.endln() # p sm.endln() # div sm.begin("h3", value="Rivals").endln() sm.beginln("div", [("id", "rivals")]) sm.begin("p", value="Go to settings to enter your DJ rivals.") sm.endln() # p sm.endln() # div sm.begin("h3", value="Settings").endln() sm.beginln("div", [("id", "settings")]) sm.begin("label", [("for", "set_me")], "DJ Name").end().empty("br") sm.empty("input", [("id", "set_me"), ("type", "text")]).emptyln("br") sm.begin("label", [("for", "set_rival")], "DJ Rivals").end().empty("br") sm.empty("input", [("id", "set_rival"), ("type", "text")]).emptyln("br") sm.begin("button", [("id", "set_apply"), ("type", "button")], "Apply").end().raw(" ").begin("span", [("id", "set_status")]).endln() sm.endln() # div sm.begin("h3", value="About").endln() sm.beginln("div", [("id", "about")]) sm.beginln("p") sm.rawln("DJRivals is a score tracker for DJMAX Technika 3.<br />") sm.emptyln("br") sm.rawln("Quickly and easily see your scores as well as those<br />") sm.rawln("from your rivals. Score comparison shows how<br />") sm.rawln("far ahead or behind you are, and sortable columns<br />") sm.rawln("makes it simple to see your best and worst scores.<br />") sm.rawln("DJRivals also includes master ranking for all modes!") sm.endln() # p sm.beginln("p", [("id", "dedication")]) sm.rawln("Dedicated to Shoreline<br />and all Technika players.") sm.endln() # p sm.endln() # div sm.endln() # div (accordion) _tail(sm, idx) sm.endln() # body sm.endln() # html with open(path.root + "index.html", "wb") as f: f.write(sm.output().encode())
maxleft = left if not font in leftvals: leftvals[font] = [] leftvals[font].append(left) if drawMap: continue #print "DEBUG %s %s %s %s" % (font, left, top, text) if ((page == 1 or filterallpages) and top < mint) or ((lastp == "all" or page == lastp) and top > maxt): continue if left < minl: continue rabtext = None if ("-2018" in filepath or "-2019" in filepath) and " " in text: text, rabtext = tuple(text.split(" ")) if left < l1: record[0] += " " + clean_part(clean(text)) if rabtext: record[1] += " " + clean(rabtext) elif left < l2: record[1] += " " + clean(text) match = re_gpe.search(record[1]) if match: record[1] = re_gpe.sub('', record[1]).strip() record[2] = match.group(1).strip() elif rabtext: record[2] += " " + clean(rabtext) elif left < l3: if "<b>" in text: a = text.split(' <b>') record[2] = a[0] record[3] = a[1]
topvals[font].append(top) left = int(attrs.group(2)) if left > maxleft: maxleft = left if not font in leftvals: leftvals[font] = [] leftvals[font].append(left) if drawMap: continue #print "DEBUG %s %s %s %s" % (font, left, top, text) if ((page == 1 or filterallpages) and top < mint) or ((lastp == "all" or page == lastp) and top > maxt): continue if left < minl: continue if left < l1: record[0] = clean_part(clean(text)) elif left < l2: record[1] = clean(text) match = re_gpe.search(record[1]) if match: record[1] = re_gpe.sub('', record[1]).strip() record[2] = match.group(1).strip() elif left < l3: if "<b>" in text: a = text.split(' <b>') record[2] = a[0] record[3] = a[1] else: record[2] = clean(text) record[2] = clean_app(record[2]).replace("Rassemblement-", "R").replace("ÉCOL.", 'ECOLO').replace('Ecolo', 'ECOLO') else:
unif_partis(lowerize(line['Parti rattachement'])), parl['sexe'], parl['nom_circo'], parl['slug'], parl['url_an'] ]) del(circosparls[circo]) for circo, parls in circosparls.items(): parl = parls[0] results.append([ parl['nom_de_famille'].upper(), parl['prenom'], parl['groupe_sigle'], "Non rattaché%s" % ("e" if parl["sexe"] == "F" else ""), parl['sexe'], parl['nom_circo'], parl['slug'], parl['url_an'] ]) print ",".join(['"%s"' % h for h in headers]) for i in results: for j in range(len(i)): i[j] = clean(i[j]) try: i[j] = i[j].encode('utf-8') except: pass for i in sorted(results, key=lambda x: x[0]): print ",".join([str(i[a]) if isinstance(i[a], int) else "\"%s\"" % i[a].replace('"', '""') for a,_ in enumerate(i)])
def search_episode(info): filters.use_TV() query = common.clean(info['title']) + ' %dx%02d'% (info['season'],info['episode']) # define query return search(query)
def get_fuel_menu_pid(self, printout, search): for line in printout.splitlines(): if line.endswith(search): return clean(line)[1]
replace_string = replace_string + '1' + deli else: replace_string = replace_string + '0' + deli if int(para[0]) > 2: replace_string = replace_string + '1' else: replace_string = replace_string + '0' replace_string = replace_string + ';\n' file_out.write(replace_string) # 不改变不涉及重新赋值的语句 for line in all_lines[58:]: file_out.write(line) if __name__ == '__main__': # 删除原来的文件 common.clean() # 拷贝了一个修复文件 subprocess.Popen('cp %s %s' %(c_file_name, repair_file_name), shell = True).wait() testcase_file = open('testcase.txt') # 读入测试用例 testcases = testcase_file.readlines() testcase_file.close() # 错误路径 bad_route = [] # 变量列表 var_list = [] # 记录有用的测试样例 useful = [] # 对每个数据做处理 for testcase in testcases: # EOF