Skip to content

Instantly share code, notes, and snippets.

@ArthurAttout
Last active December 27, 2025 13:01
Show Gist options
  • Select an option

  • Save ArthurAttout/693a6a937564fe1b755a1b26bcfb9e90 to your computer and use it in GitHub Desktop.

Select an option

Save ArthurAttout/693a6a937564fe1b755a1b26bcfb9e90 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# MIT License
#
# Copyright (c) [year] [fullname]
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import requests
import sys
from PIL import Image
from io import BytesIO
import re
from datetime import datetime
def usage():
print('Usage : memories.py dd/MM')
sys.exit(1)
API_TOKEN='<YOUR_TOKEN>'
HOST = '<YOUR_HOST>'
SEARCH_UP_TO_YEARS = 15
headers = {'x-api-key':API_TOKEN}
if len(sys.argv) != 2:
usage()
pattern = re.search('(\d+?)/(\d*)',sys.argv[1])
if not(pattern):
usage()
month = -1
day = -1
try:
month = int(pattern[1])
day = int(pattern[2])
except Error:
usage()
current_year = datetime.now().year
asset_ids = []
for i in range(SEARCH_UP_TO_YEARS):
year = current_year - i
body = {
'takenAfter':f'{year}-{month}-{day}T00:00:00.000Z',
'takenBefore':f'{year}-{month}-{day}T23:59:59.999Z'
}
result = requests.post(f'{HOST}/api/search/metadata', data=body, headers=headers).json()
assets = result['assets']
if assets['total'] == 0:
continue
print(f"Retrieved {result['assets']['total']} assets for year {year}")
asset_ids = asset_ids + [a['id'] for a in assets['items']]
idx = 0
for id in asset_ids:
filename = requests.get(f'{HOST}/api/assets/{id}/', headers=headers).json()['originalFileName']
img = requests.get(f'{HOST}/api/assets/{id}/original', headers=headers, stream=True)
if img.status_code == 200:
with open(filename, 'wb') as file:
file.write(img.content)
print(f'Downloaded asset {idx}/{len(asset_ids)}')
idx += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment