def main(args): from progress.bar import ChargingBar as Bar ap = argparse.ArgumentParser() ap.add_argument("-o", "--output-file", nargs="?", help="save content as file") ap.add_argument("url", nargs="?", help="the url to read from (default to clipboard)") ns = ap.parse_args(args) url = ns.url or clipboard.string() output_file = ns.output_file or url.split("/")[-1] try: # print('Opening: %s\n' % url) u = urlopen(url) meta = u.info() try: file_size = int(meta["Content-Length"]) except (IndexError, ValueError, TypeError): file_size = 0 # print("Save as: {} ".format(output_file), end="") # print("({} bytes)".format(file_size if file_size else "???")) with open(output_file, "wb") as f: file_size_dl = 0 block_sz = 8192 if file_size != 0 and file_size is not None: bar = Bar("Downloading", max=100) else: bar = None _n = 0 while True: buf = u.read(block_sz) if not buf: break file_size_dl += len(buf) f.write(buf) if bar is not None: n = int(file_size_dl * 100.0 / file_size) if n == _n: continue _n = n now = monotonic() dt = now - bar._ts bar.update_avg(n, dt) bar._ts = now bar.index = n bar.update() if bar is not None: bar.finish() except Exception as e: print(e) print("Unable to download file: %s" % url) return 1 return 0
""" Prints the user pasteboard text. """ import pasteboard # Code here print("Your pasteboard is: ") print(pasteboard.string())
""" A Text View that edits the clipboard. """ import pyto_ui as ui import pasteboard as pb def did_end(text_view): pb.set_string(text_view.text) text_view = ui.TextView(text=pb.string()) text_view.become_first_responder() text_view.did_end_editing = did_end text_view.font = ui.Font.system_font_of_size(17) text_view.text_alignment = ui.TEXT_ALIGNMENT_CENTER ui.show_view(text_view, ui.PRESENTATION_MODE_SHEET)
def paste_ios(): import pasteboard return pasteboard.string()