def main(): os.chdir(os.path.dirname(__file__)) with open('page.html', 'rb') as f: template = f.read() swf = sysArgvOrInput().encode() page = template.replace(b'__swf__', swf) with open(TEMP, 'wb+') as f: f.write(page) webbrowser.open(TEMP) print('A browser window is opened. ')
def main(): op = sysArgvOrInput('Component name: ') names = [] while op: create(op) names.append(op) op = input('Component name: ') folder = os.getcwd().replace('\\', '/').split('/')[-1].strip('/') print(*["import %s from '../%s/%s';" % (x, folder, x) for x in names], sep='\n')
def main(): filename = sysArgvOrInput() with open(filename, 'rb') as f: with Image.open(f) as image: scale = float(input('scale=')) width = round(scale * image.width) height = round(scale * image.height) print('Wait for it...') new = image.resize([width, height]) print('saving...') new.save(filename + '.resized') print('done')
def main(): filename = sysArgvOrInput() outputs = mido.get_output_names() for i, name in enumerate(outputs): print(i, name, sep='\t') port_name = outputs[int(inputChin('> ', 0))] with mido.open_output(port_name) as port: with mido.MidiFile(filename) as mid: print('playing...') try: for msg in mid.play(): print(msg) port.send(msg) except KeyboardInterrupt: print('Stop. ') print('ok')
def main(): filename = sysArgvOrInput() with TemporaryFile() as tmp: with open(filename, 'r', encoding='gb18030') as f: during_mso_9 = False remains = '' try: while True: if remains: line = remains remains = '' else: line = next(f) if during_mso_9: parts = line.split(MSO_9_END, 1) if len(parts) == 2: line, remains = parts during_mso_9 = False continue else: parts = line.split(MSO_9_START, 1) if len(parts) == 2: line, remains = parts during_mso_9 = True if MSO_9_START in line or MSO_9_END in line: print(line) raise Exception('Error q3490626') line = line.replace('gb2312', 'utf-8') line = line.replace('“', '"') line = line.replace('”', '"') tmp.write(line.encode('utf-8')) except StopIteration: pass tmp.seek(0) with open(filename, 'wb') as f: shutil.copyfileobj(tmp, f) print('Done. ')
def main(): filename = sysArgvOrInput() convert(filename) print('ok')
from interactive import listen, multiLineInput from myfile import sysArgvOrInput from os.path import splitext from io import StringIO from console import console def doIt(inFile, outFile): print('(i)nteractive, or (a)utomatic?') if listen('ia') == b'i': fixIO(inFile, outFile, interactive = True) else: fixIO(inFile, outFile) print('open (f)ile, or paste (r)aw text? ') if listen('fr') == b'f': filename = sysArgvOrInput() with open(filename, 'r') as inFile: base, ext = splitext(filename) base += '_fix' with open(base + ext, 'w') as outFile: doIt(inFile, outFile) print('done') else: print('Please paste here and Ctrl + Z: ') inFile = StringIO() outFile = StringIO() raw = multiLineInput(inFile) inFile.seek(0) doIt(inFile, outFile) outFile.seek(0) print(outFile.read())
''' LiTouZhiBei(Chinese: '\xe5\x8a\x9b\xe9\x80\x8f\xe7\xba\xb8\xe8\x83\x8c'). Converts pdf from [p1, p2...] to [p1, p1, p2, p2...] ''' from myfile import sysArgvOrInput import sys import os from pdfrw import PdfReader, PdfWriter from jdt import Jdt if __name__ == '__main__': inpfn = sysArgvOrInput() outfn = os.path.join(os.path.dirname(inpfn), 'LiTouZhiBei.' + os.path.basename(inpfn)) writer = PdfWriter(outfn) pages = PdfReader(inpfn).pages jdt = Jdt(len(pages)) for i, page in enumerate(pages): writer.addpages([page] * 2) jdt.acc() writer.write() jdt.complete() print('written to', outfn)