def write_emoji(emoji, json_out): log.out('Converting to JSON...', indent=4) j = json.dumps(emoji, sort_keys=True, indent=4) log.out('Exporting to file: ' + json_out, indent=4) f = open(json_out, 'w') f.write(j) f.close()
def main(): manifest_path = DEF_MANIFEST input_path = DEF_INPUT_PATH output_path = DEF_OUTPUT_PATH output_formats = DEF_OUTPUT_FORMATS ttx_output = DEF_TTX_OUTPUT dev_ttx_output = DEF_DEV_TTX delim_codepoint = DEF_DELIM_CODEPOINT no_lig = DEF_NO_LIG no_vs16 = DEF_NO_VS16 nfcc = DEF_NFCC try: opts, _ = getopt.getopt( sys.argv[1:], 'hm:i:o:F:d:', ['help', 'ttx', 'dev-ttx', 'no-lig', 'no-vs16', 'nfcc']) for opt, arg in opts: if opt in ['-h', '--help']: print(HELP) sys.exit() elif opt == '-m': manifest_path = arg elif opt == '-i': input_path = arg elif opt == '-o': output_path = arg elif opt == '-F': output_formats = arg.split(',') elif opt == '-d': delim_codepoint = arg elif opt == '--ttx': ttx_output = True elif opt == '--dev-ttx': dev_ttx_output = True elif opt == '--no-lig': no_lig = True elif opt == '--no-vs16': no_vs16 = True elif opt == '--nfcc': nfcc = True except Exception: print(HELP) sys.exit(2) try: export(manifest_path, input_path, output_path, output_formats, delim_codepoint, ttx_output, dev_ttx_output, no_lig, no_vs16, nfcc) except Exception as e: log.out(f'!!! {e}', 31) raise e ######################## TEMP sys.exit(1) log.out('All done', 35)
def mkdir(self): log.out('初始化存储路径...') nowDataStr = time.strftime("%Y-%m-%d", time.localtime()) #self.work_path = nowDataStr.strip() self.work_path = self.download_path is_exist = os.path.exists(os.path.join(self.work_path)) if not is_exist: os.makedirs(os.path.join(self.work_path)) os.chdir(os.path.join(self.work_path)) return True else: os.chdir(os.path.join(self.work_path)) return False
def write_web(emoji, web_out): cats = {} roots = {} out = {'cats': cats, 'roots': roots} log.out('Exporting metadata for MutStd website...', 36) log.out('Processing emoji...', indent=4) for e in emoji: if 'root' not in e: raise ValueError('no root defined for emoji: ' + str(e)) if 'cat' not in e: raise ValueError('no category defined for emoji: ' + str(e)) if e['cat'] not in cats: cats[e['cat']] = [] if e['root'] not in cats[e['cat']]: cats[e['cat']].append(e['root']) roots[e['root']] = None if 'morph' in e or 'color' in e: morph = e.get('morph', '') color = e.get('color', '') suffix = morph + '_' + color if morph and color else morph + color if roots[e['root']] is None: roots[e['root']] = [] roots[e['root']].append(suffix) log.out('Converting to JSON...', indent=4) j = json.dumps(out, sort_keys=True, indent=4) log.out('Exporting to file: ' + web_out, indent=4) f = open(web_out, 'w') f.write(j) f.close()
def get_img(self, html): li_soup = BeautifulSoup(html, 'lxml') li_list = li_soup.find_all('li', attrs={'class', 'image-item'}) for li in li_list: href = li.find('a')['href'] jump_to_url = self.main_url + href log.out('jump_to_url...'+jump_to_url) jump_to_html = self.get_html(jump_to_url).text time.sleep(1) img_soup = BeautifulSoup(jump_to_html, 'lxml') img_info = img_soup.find('div', attrs={'class', 'works_display'}).find('div', attrs={'class', '_layout-thumbnail ui-modal-trigger'}) if img_info is None: continue #log.out(img_info) self.download_img(img_info, jump_to_url)
def getDataFromClient(self): print __author__ + ' license: ' + __license__ + ' email: ' + __email__ conn, addr = self.SOCKET.accept() print 'Connection address:', addr while 1: data = conn.recv(self.BUFFER_SIZE) try: if data: data = json.loads(data) self.sendDataToListeners(data['target'], data['code']) except Exception as e: log.out('err', [str(e)], 'getDataFromClient', 'Server') #if not data: break print "received data:", data conn.send(str(self.Status['OK'])) # echo conn.close()
def list_combination_test(): aa = ["0", "1", "2"] bb = copy.copy(aa) cc = copy.copy(aa) fin = [] for a in aa: for b in bb: for c in cc: log.out(a + b + c) cc.remove(b) fin.append(a) bb = copy.copy(aa) cc = copy.copy(aa) for f in fin: bb.remove(f) cc.remove(f) return
def create_text_file(): items1 = ["empty", "bow", "rod", "tear", \ "blue", "shojin", "ludens", \ "shiv", "chalice", "guinsoos", \ "rabadons", "rapidfire"] items2 = copy.copy(items1) items3 = copy.copy(items1) finished_items = [] for item1 in items1: for item2 in items2: for item3 in items3: for level in [1, 2, 3]: for astro in [False, True]: for chrono in [0, 2, 4, 6, 8]: for sorcs in [0, 2, 4, 6]: for end in [10, 20, 30]: score = combat(level, item1, item2, item3, astro, chrono, sorcs, end) params = [ str(score), str(level), item1, item2, item3, str(astro), str(chrono), str(sorcs), str(end) ] separator = "," log.out(separator.join(params)) log.file(separator.join(params), "bard_scores.txt") items3.remove(item2) finished_items.append(item1) items2 = copy.copy(items1) items3 = copy.copy(items1) for f in finished_items: items2.remove(f) items3.remove(f) return
def detailed_sim(): level = 1 item1 = "empty" item2 = "chalice" item3 = "chalice" astro = False chrono = 0 sorcs = 2 end = 30 verbose = True score = combat(level, item1, item2, item3, astro, chrono, sorcs, end, verbose) params = [ str(score), str(level), item1, item2, item3, str(astro), str(chrono), str(sorcs), str(end) ] separator = "," log.out(separator.join(params)) return
def __init__(self): self.se = requests.session() #主站首页 self.main_url = 'https://www.pixiv.net/' #收藏夹 self.bookmarkUrl = 'https://www.pixiv.net/bookmark.php' #登录请求url self.loginUrl = 'https://accounts.pixiv.net/api/login?lang=zh' #浏览器参数 user_agent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36' #登录页面地址,拿去post_key用 self.referer_url = 'https://accounts.pixiv.net/login?lang=zh&source=pc&view_type=page&ref=wwwtop_accounts_index' #收藏推荐页 self.bookmark_addUrl = 'https://www.pixiv.net/bookmark_add.php?id=' #伪造头部 self.headers = {'User-Agent' : user_agent, 'Referer' : 'https://accounts.pixiv.net/login', 'Connection':'keep-alive', 'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8', 'Accept-Encoding':'gzip, deflate', 'Accept-Language':'zh-CN,zh;q=0.8'} #从登录页面拿取post_key post_key_html = self.se.get(self.referer_url, headers=self.headers).text post_key_soup = BeautifulSoup(post_key_html, 'lxml') post_key = post_key_soup.find('input')['value'] log.out("post_key="+post_key) self.postdata = urllib.urlencode({'pixiv_id' : '*****@*****.**', 'password' : 'xxxx', 'post_key' : post_key, 'return_to' : 'https://www.pixiv.net/' }) self.timeout = 3 self.download_path = 'download' self.imgIDList = ['62578571']
def download_img(self, img_info, href): title = img_info.find('img')['alt'] src = img_info.find('img')['src'] file_name = src.split('/')[-1] file_name = file_name.split('_')[0] src_headers = self.headers src_headers['Referer'] = href log.out(src) try: html = requests.get(src, headers=src_headers) img = html.content except: log.out('获取该图片失败:'+src) return False if os.path.exists(os.path.join(file_name+'.jpg')): log.out('跳过重复图片') else: log.out('正在保存...'+file_name) f = open(file_name+'.jpg', 'ab') f.write(img) #存到当前已抓取ID列表 self.imgIDList.append(file_name)
def compileGlyphData(dir, delim_codepoint, no_vs16, glyphImageSet): # start glyphs # -------------------------------------------------------------------- firstSubfolderName = list(glyphImageSet.keys())[0] firstSubfolder = glyphImageSet[firstSubfolderName] glyphs = [] vs16Allowed = not no_vs16 # only add space. do not add characters below 0x20. glyphs.append(glyph([0x20], 'space', None)) # process and check all of the input glyph codepoints # -------------------------------------------------------------------- vs16Presence = False zwjPresence = False for i in firstSubfolder: codepoints = [] # try to check if every part of the # filename stem is a valid hexadecimal number. try: codepoints = [int(hex, 16) for hex in i.stem.split(delim_codepoint)] except ValueError as e: log.out(f'!!! One of your glyphs is not named as hexadecimal numbers. It is \'{i.name}\'.', 31) for c in codepoints: if c < int('20', 16): raise Exception(f"A codepoint in one of your glyphs ('{i}') is below U+20. You cannot encode glyphs below this number because various typing environments get confused when you do.") if c == int('20', 16): raise Exception(f"A codepoint in one of your glyphs ('{i}') is U+20. This is space - you shouldn't be using a glyph here.") # compile a glyph file structure. structPaths = dict() for subfolderName, subfolders in glyphImageSet.items(): filename = i.stem + "." + subfolderName.split('-')[0] structPaths[subfolderName] = pathlib.Path(dir / subfolderName / filename ).absolute() # tidy instances of fe0f before adding them to the glyph list if int('fe0f', 16) in codepoints: vs16Presence = vs16Allowed codepoints.remove(int('fe0f', 16)) if len(codepoints) == 1: glyphs.append(glyph(codepoints, None, structPaths, vs16Allowed)) else: glyphs.append(glyph(codepoints, None, structPaths, False)) else: glyphs.append(glyph(codepoints, None, structPaths, False)) if int('200d', 16) in codepoints: zwjPresence = True # Add vs16 to the glyphs if one of the # processed codepoint chains contains U+fe0f. if vs16Presence: glyphs.append(glyph([0xfe0f], 'VS16', None)) # Add ZWJ to the glyphs if one of the # processed codepoint chains contains U+200d. if zwjPresence: # The glyph.name is 'u200d' because that's how other # parts of the app will interpret 200d as a GlyphID. # DO NOT CHANGE IT. glyphs.append(glyph([0x200d], 'u200d', None)) return glyphs
def emoji(m, filtered_emoji, input_path, formats, path, src_size, num_threads, renderer, max_batch, cache, license_enabled, verbose): """ Checks all emoji in a very light validation as well as checking if emoji aren't filtered out by user choices. It only checks: - If the emoji has been filtered out by user exporting options. - If the source SVG file exists. (Will throw an Exception if not the case.) - If the shortcode ('short') attribute exists. (Will throw an Exception if not the case.) - If the svg size is consistent (if a -q flag is used). (Will throw an Exception if not the case.) It this doesn't result in an Exception, it returns dict containing a list of emoji that aren't filtered out, as well as a count of emoji that were skipped. """ exporting_emoji = [] cached_emoji = {'exports': [], 'licensed_exports': []} cached_emoji_count = 0 # Required to give a correct count without overlap skipped_emoji_count = 0 for i, e in enumerate(filtered_emoji): short = e.get( "short", "<UNNAMED>") # to provide info on possible error printouts try: format_path(path, e, 'svg') except FilterException as ex: if verbose: log.out(f"- - Skipped emoji: {short} - {ex}", 34) skipped_emoji_count += 1 continue # skip if filtered out if 'src' not in e: raise ValueError( f"The emoji '{short}' is missing an 'src' attribute. It needs to have one." ) # try to see if the source SVG file exists srcpath = os.path.join(m.homedir, input_path, e['src']) try: emoji_svg = open(srcpath, 'r').read() except Exception: raise ValueError( f"This source image for emoji '{short}' could not be loaded: {srcpath}" ) # the SVG size check (-q) if src_size is not None: img_size = svg.get_viewbox_size(emoji_svg) if img_size != src_size: raise ValueError( """The source image size for emoji '{}' is not what was expected. It's supposed to be {}, but it's actually {}.""".format( short, str(src_size[0]) + 'x' + str(src_size[1]), str(img_size[0]) + 'x' + str(img_size[1]))) if cache: # prime the cache keys in the emoji for later emoji_cache_keys = cache.get_cache_keys(e, m, emoji_svg, license_enabled) e['cache_keys'] = emoji_cache_keys # check if the emoji is in cache formats_status = { 'licensed_export': [], 'export': [], 'no_cache': [] } for f in formats: status = None # Attempt to find a licensed export in cache if license_enabled: status = cache.get_cache(e, f, license_enabled) if status: formats_status['licensed_export'].append(f) # Attempt to find a non-licensed export in cache if status is None: status = cache.get_cache(e, f, license_enabled=False) if status: formats_status['export'].append(f) else: formats_status['no_cache'].append(f) # Assign the formats to their cache status and export bins if formats_status['licensed_export']: cached_emoji['licensed_exports'].append( (e, formats_status['licensed_export'])) if formats_status['export']: cached_emoji['exports'].append((e, formats_status['export'])) if formats_status['export'] or formats_status['licensed_export']: cached_emoji_count += 1 if formats_status['no_cache']: exporting_emoji.append((e, formats_status['no_cache'])) else: # add the emoji to exporting_emoji if it's passed all the tests. # Cache is not enabled; pass all formats to exporting. exporting_emoji.append((e, formats)) return { "exporting_emoji": exporting_emoji, "skipped_emoji_count": skipped_emoji_count, "cached_emoji": cached_emoji, "cached_emoji_count": cached_emoji_count }
def setMove(self, move): self.move = move log.out('info', ['Move code: ' + move], 'setMove', 'Engine')
def __init__(self): #gpio.init() log.out('info', ['Engine module enabled!', 'Init pinout..'], '__init__', 'Engine')
def msg(self, s, color=37, indent=0): log.out(s, color, indent, self.name)
def export(m, filtered_emoji, input_path, formats, path, src_size, num_threads, renderer, max_batch, verbose): """ Runs the entire orxporter process, includes preliminary checking and validation of emoji metadata and running the tasks associated with exporting. """ # verify emoji # -------------------------------------------------------------------------- log.out('Checking emoji...', 36) exporting_emoji = [] skipped_emoji_count = 0 for i, e in enumerate(filtered_emoji): short = e.get( "code", "<UNNAMED>") # to provide info on possible error printouts try: format_path(path, e, 'svg') except FilterException as ex: if verbose: log.out(f"- - Skipped emoji: {short} - {ex}", 34) skipped_emoji_count += 1 continue #skip if filtered out if 'src' not in e: raise ValueError( f"The emoji '{short}' is missing an 'src' attribute. It needs to have one." ) srcpath = os.path.join(m.homedir, input_path, e['src']) try: emoji_svg = open(srcpath, 'r').read() except Exception: raise ValueError( f"This source image for emoji '{short}' could not be loaded: {srcpath}" ) # the SVG size check (-q) if src_size is not None: imgsize = svg.get_viewbox_size(emoji_svg) if imgsize != src_size: raise ValueError( f"The source image size for emoji '{}' is not what was expected. It's supposed to be {}, but it's actually {}." .format(short, str(src_size[0]) + 'x' + str(src_size[1]), str(imgsize[0]) + 'x' + str(imgsize[1]))) # add the emoji to exporting_emoji if it's passed all the tests. exporting_emoji.append(e) if skipped_emoji_count > 0: log.out( f"- {skipped_emoji_count} emoji have been skipped, leaving {len(exporting_emoji)} emoji to export.", 34) if not verbose: log.out( f"- use the --verbose flag to see what those emoji are and why they were skipped.", 34) log.out('- done!', 32) # export emoji # -------------------------------------------------------------------------- # declare some specs of this export. log.out("Exporting emoji...", 36) log.out(f"- {', '.join(formats)}") log.out(f"- to '{path}'") if num_threads > 1: log.out(f"- {num_threads} threads") else: log.out(f"- {num_threads} thread") try: # start a Queue object for emoji export emoji_queue = queue.Queue() # put the [filtered] emoji (plus the index, cuz enumerate()) into the queue. for entry in enumerate(exporting_emoji): emoji_queue.put(entry) # initialise the amount of requested threads threads = [] for i in range(num_threads): threads.append( ExportThread(emoji_queue, str(i), len(exporting_emoji), m, input_path, formats, path, renderer)) # keeps checking if the export queue is done. log.bar.max = len(exporting_emoji) while True: done = emoji_queue.empty() log.bar.goto(log.export_task_count) # if the thread has an error, properly terminate it # and then raise an error. for t in threads: if t.err is not None: for u in threads: u.kill() u.join() raise ValueError(f'Thread {t.name} failed: {t.err}') if done: break time.sleep( 0.01) # wait a little before seeing if stuff is done again. # finish the stuff # - join the threads # - then finish the terminal stuff for t in threads: t.join() log.bar.goto(log.export_task_count) log.bar.finish() except (KeyboardInterrupt, SystemExit): # make sure all those threads are tidied before exiting the program. # also make sure the bar is finished so it doesnt eat the cursor. log.bar.finish() log.out(f'Stopping threads and tidying up...', 93) if threads: for t in threads: t.kill() t.join() raise log.out('- done!', 32) if log.filtered_export_task_count > 0: log.out( f"- {log.filtered_export_task_count} emoji have been implicitly or explicitly filtered out of this export task.", 34) log.export_task_count = 0 log.filtered_export_task_count = 0 # exif license pass # (currently only just applies to PNGs) # -------------------------------------------------------------------------- if 'exif' in m.license: png_files = [] for e in exporting_emoji: for f in formats: if f.startswith('png-'): try: png_files.append(format_path(path, e, f)) except FilterException: if verbose: log.out(f"- Filtered emoji: {e['short']}", 34) continue if png_files: log.out(f'Adding license metadata to png files...', 36) exif.add_license(png_files, m.license.get('exif'), max_batch)
def main(): input_path = DEF_INPUT manifest_path = DEF_MANIFEST output_path = DEF_OUTPUT output_naming = DEF_OUTPUT_NAMING output_formats = DEF_OUTPUT_FORMATS renderer = DEF_RENDERER license = DEF_LICENSE params_path = None emoji_filter = [] emoji_filter_text = "" # for error messaging only json_out = None json_web_out = None src_size = None num_threads = DEF_NUM_THREADS force_desc = False max_batch = DEF_MAX_BATCH verbose = False try: opts, _ = getopt.getopt(sys.argv[1:], 'hm:i:o:f:F:ce:j:J:q:t:r:b:p:l:', ['help', 'force-desc', 'verbose']) for opt, arg in opts: if opt in ['-h', '--help']: print(HELP) sys.exit() # basics elif opt == '-m': manifest_path = arg elif opt == '-i': input_path = arg elif opt == '-o': output_path = arg # images elif opt == '-F': output_formats = arg.split(',') elif opt == '-f': output_naming = arg elif opt == '-r': renderer = arg elif opt == 'l': license = False elif opt == '-p': params_path = arg elif opt == '-t': num_threads = int(arg) if num_threads <= 0: raise ValueError # JSON elif opt == '-j': json_out = arg elif opt == '-J': json_web_out = arg # other emoji stuff elif opt == '-e': k, v = arg.split('=') v = v.split(',') emoji_filter.append((k, v)) emoji_filter_text = arg elif opt == '-q': t1, t2 = arg.split('x') src_size = int(t1), int(t2) elif opt == '-b': max_batch = int(arg) if max_batch <= 0: raise ValueError elif opt == '--force-desc': force_desc = True # terminal stuff elif opt == '-c': log.use_color = False elif opt == '--verbose': verbose = True except Exception as e: log.out(f'x∆∆x {e}\n', 31) sys.exit(2) # try to get all of the basic stuff and do the main execution # ----------------------------------------------------------- try: log.out(f'o∆∆o', 32) #hello # validate basic input that can't be checked while in progress if renderer not in RENDERERS: raise Exception( f"{renderer} is not a renderer you can use in orxporter.") # create a Manifest # ie. parse the manifest file and get the information we need from it log.out(f'Loading manifest file...', 36) m = orx.manifest.Manifest(os.path.dirname(manifest_path), os.path.basename(manifest_path)) log.out(f'- {len(m.emoji)} emoji defined.', 32) # filter emoji (if any filter is present) filtered_emoji = [e for e in m.emoji if emoji.match(e, emoji_filter)] if emoji_filter: if filtered_emoji: # if more than 0 log.out( f'- {len(filtered_emoji)} / {len(m.emoji)} emoji match the filter you gave.', 34) else: raise ValueError( f"Your filter ('{emoji_filter_text}') returned no results." ) # ensure that descriptions are present if --force-desc flag is there if force_desc: nondesc = [ e.get('code', str(e)) for e in filtered_emoji if 'desc' not in e ] if nondesc: raise ValueError('You have emoji without a description: ' + ', '.join(nondesc)) # JSON out or image out if json_out: jsonutils.write_emoji(filtered_emoji, json_out) elif json_web_out: jsonutils.write_web(filtered_emoji, json_web_out) else: if params_path: log.out(f'Loading image export parameters...', 36) p = orx.params.Parameters(os.path.dirname(params_path), os.path.basename(params_path)) else: # convert the non-parameter flags into an orx expression to be turned into a parameters object. log.out(f'Compiling image export parameters...', 36) license_text = "" if license == True: license_text = "yes" else: license_text = "no" makeshift_params = f"dest structure = {output_naming} format = {' '.join(output_formats)} license = {license_text}" p = orx.params.Parameters(string=makeshift_params) log.out(f'- {len(p.dests)} destination(s) defined.', 32) export.export(m, filtered_emoji, input_path, output_formats, os.path.join(output_path, output_naming), src_size, num_threads, renderer, max_batch, verbose) except (KeyboardInterrupt, SystemExit) as e: log.out(f'>∆∆< Cancelled!\n{e}', 93) sys.exit(1) # Where all the exceptions eventually go~ except Exception as e: log.out(f'x∆∆x {e}\n', 31) raise e ######################## TEMP, for developer stuff sys.exit(1) # yay! finished! log.out('All done! ^∆∆^\n', 32) # goodbye
def export( manifestPath , inputPath , outputPath , outputFormats , delim_codepoint , ttx_output , dev_ttx_output , no_lig , no_vs16 , nsc ): """ Performs a variety of processing and validation tasks related to font format, then initiates font creation once those have passed. """ log.out(f'Export started!', 35) # check if the input and output folders are valid. inputPathPath = pathlib.Path(inputPath).absolute() outputPathPath = pathlib.Path(outputPath).absolute() manifestPathPath = pathlib.Path(manifestPath).absolute() # deal with input/output/manifest directories # ------------------------------------------------ # check if the input directory exists. log.out(f'Checking input/output directories...') if not inputPathPath.exists(): raise ValueError(f"Your input folder - {inputPathPath} - is not a real directory.") elif inputPathPath.is_file(): raise ValueError(f"Your input folder - {inputPathPath} - is a file, not a directory.") # try to make the output directory. if not outputPathPath.exists(): try: outputPathPath.mkdir(parents=True, exist_ok=True) except Exception as e: raise Exception("Couldn't make the output folder '{outputPathPath}':" + str(e)) if not manifestPathPath.exists(): raise ValueError(f"Your manifest - {manifestPathPath} - is not a real directory.") elif manifestPathPath.is_dir(): raise ValueError(f"Your manifest - {manifestPathPath} - is a directory, not a file.") log.out(f'Input/output directories verified.', 32) # determine what image formats need to be used # (also check if the output formats are valid) # ------------------------------------------------ glyphImageFormats = set() log.out(f'Checking output format(s)...') for f in outputFormats: # check if it's in the list of accepted formats if f not in formats: raise ValueError(f"'{f}' isn't an output format!") # check what formats are needed if formats[f]["imageFormat"] == 'svg': glyphImageFormats.add('svg') elif formats[f]["imageFormat"] == 'png': glyphImageFormats.add('png') log.out(f'Output format(s) verified.', 32) # check the image sets for each format. # ------------------------------------------------ log.out(f'Getting + checking glyph images...') glyphs = getGlyphs(inputPathPath, delim_codepoint, glyphImageFormats, no_lig, no_vs16, nsc) log.out(f'Glyphs acquired.', 32) # try to load and check the manifest. # ------------------------------------------------ log.out(f'Getting + Checking manifest JSON...') try: with open(manifestPath, "r") as read_file: manifest = json.load(read_file) except Exception as e: raise Exception('Loading the manifest file failed!' + str(e)) validateManifest(outputFormats, manifest) log.out(f'Manifest verified.', 32) # assemble each font format. # ------------------------------------------------ log.out(f'Begin font compilation!', 35) for f in outputFormats: createFont(f, outputPath, manifest, glyphs, ttx_output, dev_ttx_output)
def export(m, filtered_emoji, input_path, formats, path, src_size, num_threads, renderer, max_batch): # 1st pass log.out('Performing sanity check...', 36) for i, e in enumerate(filtered_emoji): log.out( f'[{i+1} / {len(filtered_emoji)}] Checking ' f'{e.get("code", "<UNNAMED>")}...', 32) try: format_path(path, e, 'svg') except SkipException as ex: if str(ex): log.out(f'Skipping: {ex})', 34, 4) else: log.out('Skipping', 34) continue if 'src' not in e: raise ValueError('Missing src attribute') srcpath = os.path.join(m.homedir, input_path, e['src']) try: emoji_svg = open(srcpath, 'r').read() except Exception: raise ValueError('Could not load file: ' + srcpath) if src_size is not None: imgsize = svg.size(emoji_svg) if imgsize != src_size: raise ValueError('Source image size is {}, expected {}'.format( str(imgsize[0]) + 'x' + str(imgsize[1]), str(src_size[0]) + 'x' + str(src_size[1]))) # 2nd pass log.out('Exporting emoji...', 36) emoji_queue = queue.Queue() for entry in enumerate(filtered_emoji): emoji_queue.put(entry) log.show_threads = num_threads > 1 threads = [] for i in range(num_threads): log.out(f'Init thread {i}...', 35) threads.append( ExportThread(emoji_queue, str(i), len(filtered_emoji), m, input_path, formats, path, renderer)) while True: done = emoji_queue.empty() for t in threads: if t.err is not None: for u in threads: u.kill() u.join() raise ValueError(f'Thread {t.name} failed: {t.err}') if done: break time.sleep(0.01) log.out(f'Waiting for all threads to finish...', 35) for t in threads: t.join() # png license pass if 'png' in m.license: png_files = [] for e in filtered_emoji: for f in formats: if f.startswith('png-'): try: png_files.append(format_path(path, e, f)) except SkipException: continue log.out(f'Adding license metadata to {len(png_files)} png files...', 36) png.license(png_files, m.license.get('png'), max_batch)
def __init__(self): self.insertImgSQL = "INSERT INTO `pixiv`.`imageinfo` (`id`, `path`, `author`, `authorid`) VALUES ('%s','%s','%s','%s')" log.out('连接数据库...') self.db = MySQLdb.connect("localhost", "root", "1234", "pixiv", 3308) self.cur = self.db.cursor(cursorclass=MySQLdb.cursors.DictCursor)
def getAllRowData(self): try: testCasePath = loadTest.cRun().getTestCasePath() allData = excel.Excel(testCasePath).getExcelDataByName(5) except Exception, ex: log.out().debug(ex.message)
def getServerInfo(self): try: with open('config.json', 'r') as config: return json.loads(config.read()) except Exception as e: log.out('err', [str(e)], 'getServerInfo', 'Server')
def get_html(self, url, proxy=None, num_retries = 6): if proxy == None: try: return self.se.get(url, headers=self.headers, timeout=self.timeout) except: if num_retries > 0: log.out('打开网页出错,5秒后重试...') time.sleep(5) return self.get_html(url,num_retries = num_retries - 1) else: log.out('开始使用代理...') ip = requestPool.get_randomIP() now_proxy = {'http': ip} return self.get_html(url, proxy=now_proxy, timeout=self.timeout) else: try: return self.se.get(url, headers=self.headers, proxies=proxy, timeout=self.timeout) except: if num_retries > 0: log.out('5秒后更换代理重试...') time.sleep(5) ip = requestPool.get_randomIP() log.out('当前代理ip:'+ip) now_proxy = {'http': ip} return self.get_html(url, proxy=now_proxy, timeout=self.timeout, num_retries = num_retries - 1) else: log.out('代理也拯救不了...') log.out('10秒后取消代理重新连接...') return self.get_html(url)
def getGlyphs(inputPath, delim_codepoint, formats, no_lig, no_vs16, nfcc): """ - Validates glyph image paths from the input path. - Returns a list of glyph objects, including important special control glyphs. """ log.out(f'Checking + getting file paths...', 90) glyphImageSet = getImagesFromDir(inputPath, formats) if not nfcc: log.out(f'Checking file consistency...', 90) areGlyphImagesConsistent(glyphImageSet) log.out(f'Compiling glyph data...', 90) glyphs = compileGlyphData(inputPath, delim_codepoint, no_vs16, glyphImageSet) log.out(f'Validating glyph data...', 90) postVS16DupeTest(glyphs) if no_lig: log.out(f'Stripping any ligatures...', 90) singleGlyphs = [] for g in glyphs: if len(g.codepoints) == 1: singleGlyphs.append(g) return singleGlyphs else: log.out(f'Validating ligatures...', 90) areGlyphLigaturesSafe(glyphs) return glyphs
def combat(level: int, item1: str, item2: str, item3: str, astro: bool, chrono: int, sorcs: int, end: float, verbose=False): #determine initial stats base_as = .7 as_mod = 1.0 base_ap = 0 mana = 0 max_mana = 90 cast_time = 1.5 #special effects blue = False shojins = 0 rabadons = 0 guinsoos = 0 rods = 0 bows = 0 tears = 0 chalices = 0 chrono_int = 0 chrono_ticks = 0 #apply items equipped = [item1, item2, item3] for i in equipped: if i == "tear": tears += 1 elif i == "rod": rods += 1 elif i == "bow": bows += 1 elif i == "blue": tears += 2 blue = True elif i == "shojin": tears += 1 shojins += 1 elif i == "ludens": tears += 1 rods += 1 elif i == "shiv": tears += 1 bows += 1 elif i == "chalice": tears += 1 chalices += 1 elif i == "guinsoos": bows += 1 rods += 1 guinsoos += 1 elif i == "rabadons": rods += 2 rabadons += 1 elif i == "rapidfire": bows += 2 mana += tears * 15 as_mod += bows * .15 base_ap += rods * .2 #apply traits if astro: max_mana -= 30 if sorcs >= 6: base_ap += .75 elif sorcs >= 4: base_ap += .4 elif sorcs >= .2: base_ap += .2 if chrono >= 8: chrono_int = .75 elif chrono >= 6: chrono_int = 1.5 elif chrono >= 4: chrono_int = 3.5 elif chrono >= 2: chrono_int = 8 #apply level, rabadons, calculate mana generated if level == 1: base_mana_gen = 8 elif level == 2: base_mana_gen = 20 elif level == 3: base_mana_gen = 90 #starting the loop time = 0 meeps = 0 if verbose: log.out("Starting Mana: " + str(int(mana)) + "/" + str(max_mana)) while time < end: if mana >= max_mana: time += cast_time meeps += 1 if blue: mana = 20 else: mana = 0 if verbose: log.out("Made a Meep at: " + str(round(time, 2))) continue while chrono >= 2 and time / chrono_int >= chrono_ticks: as_mod += .15 chrono_ticks += 1 aa_time = 1 / (base_as * as_mod) if aa_time < .2: aa_time = .2 ap = base_ap if time < 10: ap = base_ap + .3 * chalices mana_gen = 10 + base_mana_gen * (1 + (ap + ap * .5 * rabadons)) if meeps >= 1: mana_gen += shojins * .18 * max_mana time += aa_time mana = mana + mana_gen as_mod += .05 * guinsoos if verbose: log.out("Finished an aa at: " + str(round(time, 2)) + " and generated " + str(mana_gen) + " mana") if verbose: log.out("Current Mana: " + str(int(mana)) + "/" + str(max_mana) + " Meeps: " + str(meeps)) return round(time / meeps, 3)
def getColName(self): try: testCasePath = loadTest.cRun().getTestCasePath() colNameList = excel.Excel(testCasePath).getRowData(5) #列名所在行 except Exception, ex: log.out().debug(ex.message)
def sendDataToListeners(self, target, data): try: {'engine': self.sendDataToEngine}[target](str(data)) except Exception as e: log.out('warn', [str(e)], 'sendDataToListeners', 'Server')
def createFont(fontFormat, outputPath, manifest, glyphs, ttx_output, dev_ttx_output): """ Calls the functions that assemble and create a font. """ log.out(f'[{fontFormat}]', 36) # VARIABLES extension = formats[fontFormat]["extension"] imageFormat = formats[fontFormat]["imageFormat"] outputAbsolute = pathlib.Path(outputPath).absolute() # assemble TTX log.out(f'Assembling initial TTX...') originalTTX = assembler(fontFormat, manifest, glyphs) log.out(f'Initial TTX successfully assembled.', 32) # save TTX log.out(f'Saving initial TTX to file...') originalTTXPath = outputAbsolute / (f"{fontFormat}_initial.ttx") writeFile(originalTTXPath, originalTTX, 'Could not write initial TTX to file') log.out(f'Initial TTX saved.', 32) # compile TTX to font log.out(f'Compiling font...') outputFontPath = outputAbsolute / (fontFormat + extension) compileTTX(originalTTXPath, outputFontPath) log.out(f'Font compiled.', 32) # --dev-ttx flag if not dev_ttx_output: log.out(f'Deleting initial TTX...') originalTTXPath.unlink() #delete # -ttx flag if ttx_output: log.out(f'Compiling finished TTX..') afterExportTTX = outputAbsolute / (f"{fontFormat}_finished.ttx") compileTTX(outputFontPath, afterExportTTX) # iOS Configuration Profile compilation # (must come after everything else) if formats[fontFormat]["iOSCompile"]: log.out(f'Compiling iOS Configuration Profile...') configString = compileiOSConfig(manifest, outputFontPath, outputPath) configPath = outputAbsolute / (f"{fontFormat}.mobileconfig") writeFile(configPath, configString, 'Could not write iOS Configuration Profile to file') log.out(f'Deleting the original Font...') outputFontPath.unlink() #delete log.out(f'Done!!!', 32)
def login(self): log.out('正在登录...') #登录 self.response = self.se.post(self.loginUrl, data=self.postdata, headers=self.headers) log.out('登录成功')