def main(): if not appex.is_running_extension(): print 'This script is intended to be run from the sharing extension.' return images = appex.get_attachments('public.jpeg') if images: a = get_exif(images[0]) if a.get('GPSInfo'): lat = [float(x)/float(y) for x, y in a['GPSInfo'][2]] latref = a['GPSInfo'][1] lon = [float(x)/float(y) for x, y in a['GPSInfo'][4]] lonref = a['GPSInfo'][3] lat = lat[0] + lat[1]/60 + lat[2]/3600 lon = lon[0] + lon[1]/60 + lon[2]/3600 if latref == 'S': lat = -lat if lonref == 'W': lon = -lon loc_str = '%f, %f' % (lat, lon) print 'Latitude/Longitude:' print loc_str clipboard.set(loc_str) print '(copied to the clipboard -- you can paste this in the search field of Maps to go to the location where the photo was taken)' else: print 'No location data found' else: print 'No input image found'
def get_appex_attachments(self, type): """AppEx: Get attachments""" if type == 'imagePIL': items = appex.get_images() elif type == 'image': items = appex.get_attachments('public.jpeg') return items
def main(): if not appex.is_running_extension(): print('This script is intended to be run from the sharing extension.') return images = appex.get_attachments('public.jpeg') if images: a = get_exif(images[0]) if a.get('GPSInfo'): lat = [float(x) / float(y) for x, y in a['GPSInfo'][2]] latref = a['GPSInfo'][1] lon = [float(x) / float(y) for x, y in a['GPSInfo'][4]] lonref = a['GPSInfo'][3] lat = lat[0] + lat[1] / 60 + lat[2] / 3600 lon = lon[0] + lon[1] / 60 + lon[2] / 3600 if latref == 'S': lat = -lat if lonref == 'W': lon = -lon loc_str = '%f, %f' % (lat, lon) print('Latitude/Longitude:') print(loc_str) clipboard.set(loc_str) print( '(copied to the clipboard -- you can paste this in the search field of Maps to go to the location where the photo was taken)' ) else: print('No location data found') else: print('No input image found')
def main(): # 三种入口方式 if appex.is_running_extension() and re.search( 'http*:\/\/[^\s]+', appex.get_attachments()[0]) is not None: url = appex.get_attachments()[0] else: clip = re.search('http*:\/\/[^\s]+', clipboard.get()) if clip is None: url = console.input_alert('请输入直链或者资源地址:') else: url = clipboard.get() req_header = console.input_alert('请输入请求头,如果没有请不要输入(直接确定):') download(url, req_header)
def main(): if not appex.is_running_extension(): print 'ERROR: This script is meant to be run from the sharing extension.' else: input_files = appex.get_attachments() for input_file in input_files: head, tail = os.path.split(input_file) shutil.copy(input_file, tail)
def main(): if appex.is_running_extension(): attachments = appex.get_attachments() assert attachments and attachments[0].rstrip(), "Ain't gots no text!!" file_name = 'from Goodreader_{:%Y_%m_%d_%H_%M_%S}.txt'.format(datetime.datetime.now()) with open(file_name, 'w') as out_file: out_file.write(attachments[0]) print('{} bytes written to {}.'.format(len(attachments[0]), file_name))
def main(): if appex.is_running_extension(): attachments = appex.get_attachments() assert attachments and attachments[0].rstrip(), "Ain't gots no text!!" fmt = "from Goodreader_{:%Y_%m_%d_%H_%M_%S}.txt" file_name = fmt.format(datetime.datetime.now()) with open(file_name, "w") as out_file: out_file.write(attachments[0]) print("{} bytes written to {}.".format(len(attachments[0]), file_name))
def main(): if not appex.is_running_extension(): print 'This script is intended to be run from the sharing extension.' return text = appex.get_attachments() if not text: print 'No text input found.' return console.alert('Statistics', '%s' % (text), 'OK', hide_cancel_button=True)
def main(): if not appex.is_running_extension(): print('This script is intended to be run from the sharing extension.') return myfile = appex.get_attachments('public.data')[0] if myfile: sha1 = sha1_hash(myfile) print('sha1: {}\n'.format(sha1)) clipboard.set(sha1) print('The sha1 hash has been copied to the clipboard.')
def main(): if not appex.is_running_extension(): print('This script is intended to be run from the sharing extension.') return name = appex.get_attachments()[0] if not name: console.hud_alert('Nothing to save?') return shutil.copy(name, os.path.expanduser('~/Documents/Downloads/')) console.hud_alert('done')
def main(): # 三种入口方式 if appex.is_running_extension() and re.search( 'http*:\/\/[^\s]+', appex.get_attachments()[0]) is not None: url = appex.get_attachments()[0] else: clip = re.search('http*:\/\/[^\s]+', clipboard.get()) if clip is None: url = console.input_alert('请输入m3u8资源地址:') else: url = clipboard.get() new_file_name = download_m3u8(url) if new_file_name != '': print('================================') print('下载完毕,存储为 this phone/ppcxy_download/m3u8目录\n文件名:') print(new_file_name + '.ts') print('请使用支持ts格式播放器播放') print('================================')
def main(): input_dict = None if len(sys.argv) >= 2 and sys.argv[1] == 'quick': if appex.is_running_extension() and re.search('http*:\/\/[^\s]+', appex.get_attachments()[0]) is None: input_dict = appex.get_attachments()[0] else: clip = re.search('^(?!http)+', clipboard.get()) if clip != None: input_dict = clipboard.get() input = input_dict or dialogs.text_dialog() if input: referenceViewController = UIReferenceLibraryViewController.alloc().initWithTerm_(input) rootVC = UIApplication.sharedApplication().keyWindow().rootViewController() tabVC = rootVC.detailViewController() referenceViewController.setTitle_("Definition: '{}'".format(input)) referenceViewController.setPreferredContentSize_(CGSize(540, 540)) referenceViewController.setModalPresentationStyle_(2) #tabVC.addTabWithViewController_(referenceViewController) tabVC.presentViewController_animated_completion_(referenceViewController, True, None)
def main(): if not appex.is_running_extension(): assets = choose_assets() if assets is None: return assets = process_assets(assets) if len(assets.deletable) > 0: photos.batch_delete(assets.deletable) dialogs.hud_alert("{0} photos updated".format(len(assets.new))) else: images = appex.get_attachments() print(images)
def main(): if not appex.is_running_extension(): print('This script is intended to be run from the sharing extension.') return images = appex.get_attachments('public.jpeg') if images: a = get_exif(images[0]) if a: print('EXIF data:') for k, v in a.items(): print('{0}: {1}'.format(k, v)) else: print('No exif data found') else: print('No input image found')
def main(): global testing testing = False if not appex.is_running_extension() and not testing: print('This script is intended to be run from the sharing extension.') return global attachments attachments = appex.get_attachments() global assets assets = assets_for_attachments(attachments) v = ui.load_view('exif') v.present('sheet')
def main(): if not appex.is_running_extension(): print('This script is intended to be run from the sharing extension.') return pdfs = appex.get_attachments(uti='public.data') if pdfs: pdf_file = PdfFileReader(open(pdfs[0], "rb")) if pdf_file: metadata = pdf_file.getDocumentInfo() for k, v in metadata.items(): if type(v) == PyPDF2.generic.IndirectObject: print('{0} - {1}'.format(k, metadata[k])) else: print('{0} - {1}'.format(k, v)) else: print('No metadata found') else: print('No input PDF found')
def main(): if not appex.is_running_extension(): print('This script is intended to be run from the sharing extension.') return # list contains two duplicate entries, get first one inputfile = appex.get_attachments()[0] comps = __file__.split(os.sep) # check if file exists if os.path.exists(inputfile): try: # Attempt to move source into destination shutil.copy2( inputfile, os.path.join(os.sep.join(comps[:comps.index('Documents') + 1]), os.path.basename(inputfile))) console.hud_alert( os.path.basename(inputfile) + ' copied successful.') except Exception: console.hud_alert('Unable to copy ' + inputfile + '.')
def main(): if appex.is_running_extension(): content = None attachments = appex.get_attachments() filepaths = appex.get_file_path() if attachments and attachments[0].rstrip() and appex.get_file_path(): with open(attachments[0], 'r') as f: content = f.read() attachment_name = filepaths.split(os.sep)[-1] else: print('No attachment found.') sys.exit(1) sel = console.alert('Save: %s' % attachment_name, button1='File', button2='Clipboard') if sel == 1: file_name = '{:%Y%m%d-%H%M%S}_{}'.format(datetime.datetime.now(), attachment_name) save_dir_name = get_save_dir() save_dir_path = os.path.join(BASE_DIR, save_dir_name) save_file_rel_path = os.path.join(save_dir_name, file_name) save_file_path = os.path.join(BASE_DIR, save_file_rel_path) try: # check dirs and save if not os.path.exists(save_dir_path): os.makedirs(save_dir_path) with open(save_file_path, 'w') as f: f.write(content) # wrapup msg = 'Saved: %s' % save_file_rel_path except Exception as e: msg = str(e) console.alert(msg, button1='OK', hide_cancel_button=True) elif sel == 2: clipboard.set(content) if appex.is_running_extension(): appex.finish()
def main(): if appex.is_running_extension(): images = appex.get_attachments('public.jpeg') else: print('Pick a photo to mask.') images = [pick_photo()] print(images) if not images: print('No input image found') return ci_img = load_ci_image(images[0]) faces = find_faces(ci_img) if not faces: print('Error: No faces found in the photo.') return out_img = mask_faces(ci_img, faces) out_file = write_output(out_img) console.clear() console.show_image(out_file) console.alert('Tweet this image?')
def main(): saveDir = './Download' url = appex.get_attachments()[-1] ydl_opts = { 'outtmpl': '{}/%(title)s.%(ext)s'.format(saveDir), # 'format': 'mp4', 'subtitlesformat': 'best', 'writesubtitles': False, 'writeautomaticsub': False, 'continuedl': True, 'quiet': False } os.makedirs(saveDir, exist_ok=True) print("Downloading video...") with youtube_dl.YoutubeDL(ydl_opts) as ydl: ydl.download([url]) print("Finished downloading video")
print('\t下载失败!') return False save_dir = './video' if not os.path.exists(save_dir): os.makedirs(save_dir) url = '' headers = {} if not appex.is_running_extension(): import clipboard url = dialogs.input_alert('请输入链接地址:') else: filepath = appex.get_attachments()[0] if '.har' == filepath[-4:]: import json with open(filepath, 'r') as f: #f=open(filepath,'r') #print('test') r = json.loads(f.readline())['log']['entries'][0]['request'] #print(r) f.close() url = r['url'] for h in r['headers']: if not h['name'] in [ 'Content-Length', 'Connection', 'Host', 'Content-Type', 'If-Modified-Since', 'Range', 'Connection'
import appex, console data = [] data.append(appex.get_attachments()) data.append(appex.get_file_paths()) data.append(appex.get_images()) data.append(appex.get_text()) data.append(appex.get_urls()) data.append(appex.get_web_page_info()) keys = ['attachments', 'file paths', 'images', 'text', 'urls', 'web page'] data_dict = dict(zip(keys, data)) for key in data_dict.keys(): #print(key, type(data_dict[key])) if type(data_dict[key]) == type(dict()): for item in data_dict[key].keys(): print(item, type(data_dict[key][item])) elif type(data_dict[key]) == type(list()): for part in data_dict[key]: print(type(part)) else: print('fart') #for datum in data: #print(type(datum)) #console.alert("fart", str(type(datum)), "okay") #console.alert("fart", str(len(datum), "okay"))
# https://forum.omz-software.com/topic/4101/using-apex-to-modify-a-photo-creation-date-directly/5 import appex import photos from objc_util import ObjCInstance def assets_for_attachments(attachments): all_assets = photos.get_assets() matching_assets = [] for a in all_assets: path = str(ObjCInstance(a).pathForOriginalFile()) if path in attachments: matching_assets.append(a) return matching_assets attachments = appex.get_attachments() assets = assets_for_attachments(attachments) # Now you can use the photos module to manipulate the assets... (as in previous example)
def get_image(): if not appex.is_running_extension(): print('This script is intended to be run from the sharing extension.') return images = appex.get_attachments('public.jpeg') return images[0]
import os,sys import appex import zipfile import console console.clear() if not appex.is_running_extension(): print('请在"Run Pythonista Script"中使用!') else: try: mmsg=0 _要导入的文件=appex.get_attachments()[0] _文件名=_要导入的文件.replace(os.path.dirname(_要导入的文件)+'/',' _目录名=hml()+'导入的文件/' expath=_目录名+_文件名[0:_文件名.rfind('.')] if not os.path.exists(_目录名): os.mkdir(_目录名) filetype=str.lower(_文件名[_文件名.rfind('.'):]) def cfile(): _文件=open(_要导入的文件,'rb') zwxm=open(_目录名+_文件名,'wb') zwxm.write(_文件.read()) zwxm.close() _文件.close() if os.path.exists(_目录名+_文件名): console.clear() console.set_font('',5) img = console.alert('提示', '文件已存在', '覆盖','取消',hide_cancel_button=True) if img==1:
# coding: utf-8 # https://forum.omz-software.com/topic/2637/is-it-possible-to-read-a-file-say-txt-file-from-other-app/6 import appex print appex.get_attachments() #============================== text=open(appex.get_attachments()[0]).read() open('a.txt','w').write(text) #============================== >>> import appex >>> appex.get_attachments() [u"/var/mobile/Containers/Data/Application/E2D89A6E-FD16-4428-BAC4-2E01276796E6/Documents/What's new in GoodReader 4.11.pdf", u"/var/mobile/Containers/Data/Application/E2D89A6E-FD16-4428-BAC4-2E01276796E6/Documents/What's new in GoodReader 4.11.pdf"] #============================== >>> import appex >>> import json >>> print(json.dumps(appex.get_input(), indent=4)) [ { "attachments": [ { "com.adobe.pdf": "/var/mobile/Containers/Data/Application/E2D89A6E-FD16-4428-BAC4-2E01276796E6/Documents/What's new in GoodReader 4.11.pdf", "public.file-url": "/var/mobile/Containers/Data/Application/E2D89A6E-FD16-4428-BAC4-2E01276796E6/Documents/What's new in GoodReader 4.11.pdf" } ]
def generate(): if not appex.is_running_extension(): img = photos.pick_image(show_albums=True) size_field.text = 'Open in Extension to view file size' else: img_path = appex.get_attachments()[0] size_field.text = size_fmt(os.path.getsize(img_path)) img = appex.get_image() if img: exif = get_exif(img) width, height = img.size if width > 3000 or height > 3000: img.thumbnail((1000, 1000)) orientations = { 1: 0, 2: 0, 3: 180, 4: 0, 5: 0, 6: 270, 7: 0, 8: 90 } if exif.get('Orientation'): img = img.rotate(orientations.get(exif['Orientation'], 0)) img_view.image = pil2ui(img) hist = get_histogram(img) hist_view.image = hist if exif.get('FocalLength'): focal_field.text = '%d' % (exif['FocalLength'][0] / exif['FocalLength'][1]) else: focal_field.text = '--' if exif.get('FNumber'): f = exif['FNumber'] aperture_field.text = '%.1f' % (float(f[0]) / f[1]) else: aperture_field.text = '--' if exif.get('ExposureTime'): shutter_field.text = '%d/%d' % exif['ExposureTime'] else: shutter_field.text = '----' iso_field.text = str(exif.get('ISOSpeedRatings', '--')) if exif.get('DateTimeOriginal'): date = datetime.strptime(exif['DateTimeOriginal'], '%Y:%m:%d %H:%M:%S') date_field.text = date.strftime('%B %d, %Y at %H:%M') else: date_field.text = 'No date and time information' wh_field.text = '%d x %d (%.1fMP)' % (width, height, width * height / 1000000.0) camera_field.text = exif.get('Model', 'Unknown') lens = exif.get('LensModel', 'Unknown') lens_field.text = lens artist_field.text = exif.get('Artist', 'Unknown') programs = { 0: 'Unknown', 1: 'Manual', 2: 'Program AE', 3: 'Aperture-priority AE', 4: 'Shutter-priority AE', 5: 'Sleep speed', 6: 'High speed', 7: 'Portrait', 8: 'Landscape', 9: 'Bulb'} program_field.text = programs.get(exif.get('ExposureProgram', 0), 'Unknown') flashes = { 0x0: 'No Flash', 0x1: 'Fired', 0x5: 'Fired, Return not detected', 0x7: 'Fired, Return detected', 0x8: 'On, Did not fire', 0x9: 'On, Fired', 0xd: 'On, Return not detected', 0xf: 'On, Return detected', 0x10: 'Off, Did not fire', 0x14: 'Off, Did not fire, Return not detected', 0x18: 'Auto, Did not fire', 0x19: 'Auto, Fired', 0x1d: 'Auto, Fired, Return not detected', 0x1f: 'Auto, Fired, Return detected', 0x20: 'No flash function', 0x30: 'Off, No flash function', 0x41: 'Fired, Red-eye reduction', 0x45: 'Fired, Red-eye reduction, Return not detected', 0x47: 'Fired, Red-eye reduction, Return detected', 0x49: 'On, Red-eye reduction', 0x4d: 'On, Red-eye reduction, Return not detected', 0x4f: 'On, Red-eye reduction, Return detected', 0x50: 'Off, Red-eye reduction', 0x58: 'Auto, Did not fire, Red-eye reduction', 0x59: 'Auto, Fired, Red-eye reduction', 0x5d: 'Auto, Fired, Red-eye reduction, Return not detected', 0x5f: 'Auto, Fired, Red-eye reduction, Return detected', 0x60: 'Unknown'} flash_field.text = flashes.get(exif.get('Flash', 0x60)) zoom_text = 'Unknown' if (lens == 'iPhone 7 Plus back iSight Duo camera 6.6mm f/2.8'): zoom_text = '2x Optical on Duo Camera' if exif.get('DigitalZoomRatio'): z = exif['DigitalZoomRatio'] zoom_text = '%.2gx Digital' % (float(z[0]) / z[1]) zoom_field.text = zoom_text software_field.text = exif.get('Software', 'Unknown') meterings = { 0: 'average.png', 1: 'average.png', 2: 'center-weighted.png', 3: 'spot.png', 4: 'spot.png', 5: 'average.png', 6: 'partial.png', 255: 'average.png' } metering_view.image = ui.Image(meterings.get(exif.get('MeteringMode', 0), 'average.png')) if exif.get('WhiteBalance') == 1: balance_field.text = 'MWB' if exif.get('GPSInfo'): try: lat = [float(x)/float(y) for x, y in exif['GPSInfo'][2]] latref = exif['GPSInfo'][1] lon = [float(x)/float(y) for x, y in exif['GPSInfo'][4]] lonref = exif['GPSInfo'][3] lat = lat[0] + lat[1]/60 + lat[2]/3600 lon = lon[0] + lon[1]/60 + lon[2]/3600 if latref == 'S': lat = -lat if lonref == 'W': lon = -lon geolocator = Nominatim() loc_str = '%f, %f' % (lat, lon) location_field.text = loc_str + '\nDecoding location...' location = geolocator.reverse(loc_str) location_field.text = location.address except KeyError: location_field.text = 'No location data found' else: location_field.text = 'No location data found' return True else: hud_alert('No valid photo selected', icon='error') return False
elif 'receive' in user_args: transfer.receive(wait_interval) elif 'send_selected_or_clipboard_text' in user_args: share_text = get_selected_text() if not share_text: share_text = clipboard.get() transfer.send_text(share_text) elif user_args: files = user_args print(files) transfer.send(files) else: if appex.is_running_extension(): path = appex.get_file_paths() if len(path) == 0: path = appex.get_attachments() # print(appex.get_file_path() print(path) if not len(path) == 0: if len(path) == 1 and not os.path.isfile(path[0]): share_text = path[0] msg = "Do you want to share this text?\n{}".format( share_text) if console.alert("Transfer", msg, "No", "Yes", hide_cancel_button=True) == 2: transfer.send_text(share_text) else: transfer.send(path)
if d['status'] == 'finished': console.hide_output() chosen = console.alert( 'Download Finished', "Video is already in Pythonista.\nWaht else do you want to do with it?", 'Quick Look', 'Open in', 'Save to Album') if chosen == 1: console.quicklook(d['filename']) elif chosen == 2: console.open_in(d['filename']) elif chosen == 3: save_video(d['filename'].encode('utf-8')) if appex.is_running_extension() and re.search( 'https*:\/\/[^\s]+', appex.get_attachments()[0]) is not None: url = appex.get_attachments()[0] else: clip = re.search('https*:\/\/[^\s]+', clipboard.get()) if clip is None: url = console.input_alert('URL Input') else: url = clipboard.get() console.clear() config = input('input config: ') sys.argv = ['you-get', '%s' % config, '%s' % url] you_get.main()