def choose_assets(): search = dialogs.input_alert('What is your album called?') albums = photos.get_albums() albums = list([a for a in albums if search in a.title]) albums = list([a for a in albums if get_album_ends(a)[0] is not None]) if len(albums) == 0: dialogs.hud_alert('No album found!', icon='error') return None album_names = [ { 'id': a.local_id, 'index': i, 'title': "{0} ({1})".format(a.title, get_album_dates(a)[0].strftime('%b %d, %Y')), #'image': get_asset_thumb(get_album_ends(a)[0]), 'accessory_type': 'checkmark' } for (i, a) in enumerate(albums) ] album = dialogs.list_dialog('Choose Album', album_names) if album is None: return None album_index = album['index'] assets = photos.pick_asset(albums[album_index], 'Choose Photos', True) return assets
def addImagefileToAlbum(imagefilePath, albumName): try: album = [a for a in photos.get_albums() if a.title == albumName][0] except IndexError: album = photos.create_album(albumName) asset = photos.create_image_asset(imagefilePath) album.add_assets([asset])
def get_album(title): for coll in photos.get_albums(): if coll.title == title: break else: coll = photos.create_album(title) return coll
def get_album(): albums = photos.get_albums() albums = [a for a in albums if a.title == ALBUM_NAME] if not albums: return photos.create_album(ALBUM_NAME) else: return albums[0]
def albums_load(self, load_smart_albums=False): # Get Album Titles albums = photos.get_albums() for album in albums: self.albums.append(album) self.album_titles.append(album.title) return # Although not required, I am a fan of returning all methods
def add_to_album(image_path, album_name): try: album = [a for a in photos.get_albums() if a.title == album_name][0] except IndexError: album = photos.create_album(album_name) asset = photos.create_image_asset(image_path) album.add_assets([asset]) os.remove(image_path)
def check_for_album_or_make(album_name): all_albums = photos.get_albums() found = False for some_album in all_albums: if found: continue elif some_album.title == album_name: found = True found_album = some_album if not found: found_album = photos.create_album(album_name) return found_album
def main(): std_albums = photos.get_albums() print('Albums') print('------') for a in std_albums: print (f'{a.title}') print('\nSmart Albums') print('------------') smart_albums = photos.get_smart_albums() for a in smart_albums: print(f'{a.title}')
def add_to_album(image_path, album_name): # KUDOS to Ole Zorn here! # Source: https://forum.omz-software.com/topic/3889/adding-an-image-to-my-own-album-in-photos-how/2 # Find the album or create it: try: album = [a for a in photos.get_albums() if a.title == album_name][0] except IndexError: album = photos.create_album(album_name) # Add the file as an asset to the library: asset = photos.create_image_asset(image_path) # Workaround a possible timestamp bug: asset.creation_date = datetime.datetime.now() # Add the asset to the album: album.add_assets([asset])
class Selection_Handler: data = {album.title: album for album in photos.get_albums()} @property def names(self): return list(self.data.keys()) @property def albums(self): return [self.data[selection] for selection in self.selections] #here we sort theough and remove every photo album that has no pictures in them, as selecting one would crash the program when it tries to make a PDF from it's nonexistant images def filter_albums(self): albums_to_remove = list() for name, album in self.data.items(): if len(album.assets) == 0: albums_to_remove.append(name) [self.data.pop(album) for album in albums_to_remove] def make_selection(self): self.filter_albums() self.selections = dialogs.list_dialog('Galleries', self.names, True)
def touch_began(self, touch): sound.play_effect('Footstep') #creates a query of the locations recorded and opens it on google maps #because the query accepts at most around 20 points, if you have more #than 20 points it will create a new list and get points evenly spaced #throughout the path to a total of less than 20. Looks representative #and accurate. def mapView(self): googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] webbrowser.open(self.query) #when you run across a landmark (photo) you placed down, it will #notify you its present and you can tap to reveal the photo def openLandmark(self): sound.play_effect('Click_1') self.imageModeOpen = True self.imageMode = False self.heightPhoto = (self.photoHeight/self.photoWidth) * \ (self.size.x-20) self.widthPhoto = (self.photoWidth/self.photoWidth) * \ (self.size.x-20) self.heightFrame = self.heightPhoto + 10 self.widthFrame = self.widthPhoto + 10 self.halfScreenFrame = self.size.y / 2 - self.heightFrame / 2 self.halfScreen = self.size.y / 2 - self.heightPhoto / 2 #asked a question on the omz (Pythonista) forum and they answered! #'https://forum.omz-software.com/topic/5263/displaying-an-image- #from-album-in-photos-onto-screen-in-scene-module' #opens the image and has it hidden. self.img = ui.Button(name='image') self.img.frame = (10, self.halfScreen, self.widthPhoto, self.heightPhoto) self.img.background_image = self.ui_image self.img.enable = False self.img.hidden = False self.view.add_subview(self.img) #when you tap, get the current location to perform functions current = location.get_location() #solved the close points problem using rounding latLong = (round(current['latitude'], 4), round(current['longitude'], 4)) picTaken = latLong in self.photoLocations #get the location on the screen of the touch x, y = touch.location #if the image is open, close it when you tap (has to be off the image) if self.imageModeOpen == True: self.imageModeOpen = False self.img.hidden = True #if you have the loop Prompt, you must tap an answer in order to use #the other functions if self.loopPrompt == True: if x > 50 and x < self.size.x/2 and y < self.size.y/2 \ and y > self.size.y/2 - 50: self.loopPrompt = False self.loopPromptState = 1 elif x > self.size.x/2 and x < self.size.x-50 \ and y < self.size.y/2 and y > self.size.y/2 - 50: self.loopPrompt = False self.loopPromptState = 2 #when it has the more menu open, you must are not able to tap any of #the other buttons, other than the ones in the more menu elif self.MoreState == True: #SOS State tap, call the cops if you tap if x < self.size.w/2 + 30 and x > self.size.w/2 - 30 \ and y > 50 and y < 100 and self.MoreState == True: webbrowser.open('tel:911') #MapView tap elif x < 100 and x > 50 and y < 220 and y > 160 and \ len(self.locations) >= 2: mapView(self) #create the query, but make it a link for phone users, and copy #it to the clipboard elif x < self.size.x/2+40 and x > self.size.x/2-40 and \ y < 220 and y > 160 and len(self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] clipboard.set(self.query[7:]) self.clipState = True #tap on Trace button to reveal the path elif x < self.size.x-50 and x > self.size.x-100 and y < 220 \ and y > 160 and len(self.locations) > 2: self.pathState = True #tap on theme button to switch the theme elif x < self.size.w/2 + 30 and x > self.size.w/2 - 30 \ and y > self.size.y-95-40 and y < self.size.y-95+40: self.themeSwitch += 1 if self.themeSwitch % 2 == 0: self.theme = self.lightMode elif self.themeSwitch % 2 == 1: self.theme = self.darkMode #tap off a button while in the more menu, and it exits the menu else: self.MoreState = False self.clipState = False self.pathState = False #open landmark by tapping on the banner elif y > 150 and y < 200 and self.imageMode == True: openLandmark(self) #if in image mode, tap off the image to get rid of it off the screen elif y < 150 and y > 200 and self.imageMode == True: self.imageMode = False #reset button resets everything elif x < 100 and x > 50 and y < 100 and y > 50: self.measuringOn = False self.functionState = 0 self.background_color = self.theme["backgroundColor"] self.locations = [] self.needMore = False self.photoCount = 0 self.photoLocations = [] self.locationsLeft = [] self.needMore = False self.timerCount = 0 #more button is a small and out of the way, opens up more menu elif x < self.size.w/2 + 25 and x > self.size.w/2 - 25 and y < 30 \ and y > 0: self.MoreState = True #take photos and add to album elif x < self.size.w/2 + 30 and x > self.size.w/2 - 30 \ and y > 50 and y < 100 and self.MoreState == False and \ self.measuringOn == True and picTaken == False: imageree = photos.capture_image() if imageree != None: #open up the camera and you can take photo photos.save_image(imageree) time.sleep(1) self.photoCount += 1 allAssets = photos.get_assets() theImage = allAssets[-1] #if there is no album, create album 'Thread' try: self.photoLibrary = [a for a in photos.get_albums() \ if a.title == 'Thread'][0] except IndexError: self.photoLibrary = photos.create_album('Thread') #add the image to the album for the user to have and for #future use in the app's use (landmarks!) theImage = allAssets[len(allAssets) - 1] self.photoLibrary.add_assets([theImage]) self.photoLocations += [latLong] #compass State: Letters (NWSE) or degrees elif x < 325 and x > 275 and y < 100 and y > 50: self.compassStat = not (self.compassStat) #go to measuring mode when tapped for the first time elif self.measuringOn == False and self.functionState == 0: self.measuringOn = True self.background_color = self.theme["backgroundColor"] self.functionState += 1 #if you need more values do not let the user stop recording elif self.measuringOn == True and self.functionState == 1 \ and len(self.locations) < 4: self.needMore = True #if you have enough locations, when you tap you can move to next state elif self.measuringOn == True and self.functionState == 1 \ and len(self.locations) > 3: #sound.play_effect('arcade:Laser_1') self.needMore = False self.measuringOn = False self.background_color = self.theme["backgroundColor"] self.functionState += 1 #move function state up to state 4 so you can begin tracing back elif self.measuringOn == False and self.functionState == 3: #sound.play_effect('arcade:Laser_1') self.background_color = self.theme["backgroundColor"] self.functionState += 1
import photos, PIL, os pic_to_resize = photos.pick_asset() img = pic_to_resize.get_image() all_folders = photos.get_albums() for album in all_folders: if album.title == 'medium-sized': meds = album new_size = (int(pic_to_resize.pixel_width / 3), int(pic_to_resize.pixel_height / 3)) img_med = img.resize(new_size, PIL.Image.ANTIALIAS) img_med.save('img_med.jpg') new_med = photos.create_image_asset('img_med.jpg') meds.add_assets([new_med]) try: os.remove('img_med.jpg') except OSError: pass
# TODO have option to deal more even if sets remain (maybe penalty) import random import ui from scene import * from sound import * import console import itertools import json import time import photos console.clear() # Get images drawn by Iris in photo album 'SetImages' for album in photos.get_albums(): if album.title == 'SetImages': try: scaleFaces = .05 imgBadChoice = album.assets[0].get_ui_image() imgAlreadyChosen = album.assets[1].get_ui_image() imgBadDealRequest = album.assets[2].get_ui_image() imgCorrectSet = album.assets[3].get_ui_image() imgOops = album.assets[1].get_ui_image() # imgBadChoice = album.assets[0].get_ui_image(size=(120, 120), crop=False) # imgAlreadyChosen = album.assets[1].get_ui_image(size=(120, 120), crop=False) # imgBadDealRequest = album.assets[2].get_ui_image(size=(120, 120), crop=False) # imgCorrectSet = album.assets[3].get_ui_image(size=(120, 120), crop=True) break except: pass
from scene import * import photos, Image, ImageDraw, evolver, math w = 254 h = 254 opacity = 125 controls = [[0, w], [0, h], [0, w / 4], [0, h / 4], [0, 255], [0, 255], [0, 255]] population = 40 parents = 20 mrate = 0.05 figures = 300 moments = photos.get_albums() asset = photos.pick_asset(moments[4], title='Pick your image', multi=False) img = asset.get_image() img = img.convert('RGB') #scale photo to fit half the screen width = img.size[0] height = img.size[1] widthratio = width / (w) heightratio = height / h if widthratio > heightratio: scale = widthratio else: scale = heightratio if scale != 1: width = int(width / scale) height = int(height / scale)
def getAlbum(album_name): albums = photos.get_albums() for ab in albums: if ab.title == album_name: return ab return photos.create_album(album_name)
def touch_began(self, touch): current = location.get_location() latLong = (round(current['latitude'], 4), round(current['longitude'], 4) ) #solved the close points problem using rounding picTaken = latLong in self.photoLocations x, y = touch.location if self.imageModeOpen == True: self.imageModeOpen = False self.img.hidden = True if self.loopPrompt == True: if x > 50 and x < self.size.x / 2 and y < self.size.y / 2 and y > self.size.y / 2 - 50: self.loopPrompt = False self.loopPromptState = 1 elif x > self.size.x / 2 and x < self.size.x - 50 and y < self.size.y / 2 and y > self.size.y / 2 - 50: self.loopPrompt = False self.loopPromptState = 2 elif self.MoreState == True: #SOS State if x < self.size.w / 2 + 30 and x > self.size.w / 2 - 30 and y > 50 and y < 100 and self.MoreState == True: webbrowser.open('tel:911') #MapView elif x < 100 and x > 50 and y < 220 and y > 160 and len( self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] webbrowser.open(self.query) elif x < self.size.x / 2 + 40 and x > self.size.x / 2 - 40 and y < 220 and y > 160 and len( self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] clipboard.set(self.query[7:]) self.clipState = True elif x < self.size.x - 50 and x > self.size.x - 100 and y < 220 and y > 160 and len( self.locations) > 2: self.pathState = True else: self.MoreState = False self.clipState = False self.pathState = False #open landmark elif y > 150 and y < 200 and self.imageMode == True: sound.play_effect('arcade:Laser_2') self.imageModeOpen = True self.imageMode = False self.heightFrame = (self.photoHeight / self.photoWidth) * (self.size.x) self.widthFrame = (self.photoWidth / self.photoWidth) * (self.size.x) self.heightPhoto = (self.photoHeight / self.photoWidth) * (self.size.x - 20) self.widthPhoto = (self.photoWidth / self.photoWidth) * (self.size.x - 20) self.halfScreenFrame = self.size.y / 2 - self.heightFrame / 2 self.halfScreen = self.size.y / 2 - self.heightPhoto / 2 self.img = ui.Button(name='image') self.img.frame = (10, self.halfScreen, self.widthPhoto, self.heightPhoto) self.img.background_image = self.ui_image self.img.enable = False self.img.hidden = False self.view.add_subview(self.img) elif y < 150 and y > 200 and self.imageMode == True: self.imageMode = False #reset button elif x < 100 and x > 50 and y < 100 and y > 50: self.measuringOn = False self.checkedOnce = 0 self.background_color = self.theme["backgroundColor"] self.locations = [] self.needMore = False self.photoCount = 0 self.photoLocations = [] self.locationsLeft = [] self.needMore = False self.timerCount = 0 #more button elif x < self.size.w / 2 + 25 and x > self.size.w / 2 - 25 and y < 30 and y > 0: self.MoreState = True #take photos and add to album elif x < self.size.w / 2 + 30 and x > self.size.w / 2 - 30 and y > 50 and y < 100 and self.MoreState == False and self.measuringOn == True and picTaken == False: imageree = photos.capture_image() if imageree != None: photos.save_image(imageree) time.sleep(1) self.photoCount += 1 allAssets = photos.get_assets() theImage = allAssets[-1] #print("Divider") # Find the album or create it: try: self.photoLibrary = [ a for a in photos.get_albums() if a.title == 'Thread' ][0] except IndexError: self.photoLibrary = photos.create_album('Thread') # Add the file as an asset to the library: # asset = photos.create_image_asset(theImage) # Add the asset to the album: theImage = allAssets[len(allAssets) - 1] self.photoLibrary.add_assets([theImage]) self.photoLocations += [latLong] #compass State: Letters (NWSE) or degrees elif x < 325 and x > 275 and y < 100 and y > 50: self.compassStat = not (self.compassStat) elif self.measuringOn == False and self.checkedOnce == 0: #sound.play_effect('arcade:Laser_2') self.measuringOn = True self.background_color = self.theme["backgroundColor"] self.checkedOnce += 1 elif self.measuringOn == True and self.checkedOnce == 1 and len( self.locations) < 4: #sound.play_effect('arcade:Laser_1') self.needMore = True elif self.measuringOn == True and self.checkedOnce == 1 and len( self.locations) > 3: #sound.play_effect('arcade:Laser_1') self.needMore = False self.measuringOn = False self.background_color = self.theme["backgroundColor"] self.checkedOnce += 1 elif self.measuringOn == False and self.checkedOnce == 3: #sound.play_effect('arcade:Laser_1') self.background_color = self.theme["backgroundColor"] self.checkedOnce += 1
def touch_began(self, touch): x, y = touch.location if self.loopPrompt == True: if x > 50 and x < self.size.x / 2 and y < self.size.y / 2 and y > self.size.y / 2 - 50: self.loopPrompt = False self.loopPromptState = 1 elif x > self.size.x / 2 and x < self.size.x - 50 and y < self.size.y / 2 and y > self.size.y / 2 - 50: self.loopPrompt = False self.loopPromptState = 2 elif self.MoreState == True: #SOS State if x < self.size.w / 2 + 30 and x > self.size.w / 2 - 30 and y > 50 and y < 100 and self.MoreState == True: webbrowser.open('tel:911') #MapView elif x < 100 and x > 50 and y < 220 and y > 160 and len( self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] webbrowser.open(self.query) elif x < self.size.x / 2 + 40 and x > self.size.x / 2 - 40 and y < 220 and y > 160 and len( self.locations) >= 2: googleMapsMaxPoints = 20 mapLocations = copy.deepcopy(self.locations) if len(self.locations) > googleMapsMaxPoints: mapLocations = [] jump = math.ceil(len(self.locations) / googleMapsMaxPoints) for i in range(0, len(self.locations), jump): mapLocations += [self.locations[i]] self.query = 'safari-https://www.google.com/maps/dir/' for loc in mapLocations: self.query += str(loc[0]) self.query += "," self.query += str(loc[1]) self.query += "/" self.query = self.query[:-1] clipboard.set(self.query[7:]) self.clipState = True elif x < self.size.x - 50 and x > self.size.x - 100 and y < 220 and y > 160: self.pathState = True else: self.MoreState = False self.clipState = False self.pathState = False #reset button elif x < 100 and x > 50 and y < 100 and y > 50: self.measuringOn = False self.checkedOnce = 0 self.background_color = 'white' self.locations = [] self.needMore = False #more button elif x < self.size.w / 2 + 25 and x > self.size.w / 2 - 25 and y < 30 and y > 0: self.MoreState = True elif x < self.size.w / 2 + 30 and x > self.size.w / 2 - 30 and y > 50 and y < 100 and self.MoreState == False: imageree = photos.capture_image() photos.save_image(imageree) time.sleep(3) self.photoCount += 1 all_assets = photos.get_assets() theImage = all_assets[-1] #print("Divider") # Find the album or create it: try: album = [ a for a in photos.get_albums() if a.title == 'Thread' ][0] except IndexError: album = photos.create_album('Thread') # Add the file as an asset to the library: # asset = photos.create_image_asset(theImage) # Add the asset to the album: theImage = all_assets[len(all_assets) - 1] album.add_assets([theImage]) #compass State: Letters (NWSE) or degrees elif x < 325 and x > 275 and y < 100 and y > 50: self.compassStat = not (self.compassStat) elif self.measuringOn == False and self.checkedOnce == 0: #sound.play_effect('arcade:Laser_2') self.measuringOn = True self.background_color = 'white' self.checkedOnce += 1 elif self.measuringOn == True and self.checkedOnce == 1 and len( self.locations) < 4: #sound.play_effect('arcade:Laser_1') self.needMore = True elif self.measuringOn == True and self.checkedOnce == 1 and len( self.locations) > 3: #sound.play_effect('arcade:Laser_1') self.needMore = False self.measuringOn = False self.background_color = 'white' self.checkedOnce += 1 elif self.measuringOn == False and self.checkedOnce == 3: #sound.play_effect('arcade:Laser_1') self.background_color = 'white' self.checkedOnce += 1
def get_albums(self): albums = photos.get_albums() return albums
import photos if __name__ == '__main__': photos.create_album('Test1') photos.create_album('Test2') albums = photos.get_albums() for k, a in enumerate(albums): if a.title in ('Test1', 'Test2'): print(f'Deleting album "{a.title}"...') a.delete() print(f'"{a.title}" is gone, dude!')
files=files) if response.status_code != 200: json = response.json() if json['throwable'].startswith("com.liferay.document.library.kernel.exception.DuplicateFileEntryException"): print("Sorry, unable to upload file: %s. A file with the name '%s' already exists." % (title, title)) else: print("Sorry, unable to upload file: %s. %i - %s" % (title, response.status_code, response.text)) return response.status_code hackday_album = None keeper_album = None asset_collections = photos.get_albums() for asset_collection in asset_collections: if asset_collection.title == album_name: hackday_album = asset_collection if asset_collection.title == keeper_album_name: keeper_album = asset_collection if hackday_album and keeper_album: break keeper_filenames = [] if keeper_album: for asset in keeper_album.assets: