Last active
September 2, 2020 20:07
-
-
Save jdposthuma/0f5213c76bcdecb5a48ae48c526b0264 to your computer and use it in GitHub Desktop.
Copy files to Intterra Airborne API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# README | |
# pip install awscli | |
# aws configure | |
import boto3 | |
from datetime import datetime | |
import sys | |
import glob | |
import os | |
import time | |
import re | |
# init s3 client | |
s3 = boto3.client('s3') | |
bucket = 'tenaximagery' | |
# define timestamp for this run | |
now = datetime.utcnow() | |
print( | |
f'Running at {now.strftime("%Y-%m-%d %H:%M:%S")} UTC for bucket {bucket}...') | |
# Get current working directory (CWD) and mission name from args | |
path = sys.argv[1].rstrip('/').rstrip('\\') | |
mission_name = os.path.basename(path) | |
# create mission | |
# mission_path = f'{mission_name}.txt' | |
# with open(mission_path, 'w+') as f: | |
# f.write('') | |
# s3.upload_file(mission_path, bucket, f'MISSION/{mission_name}.txt') | |
# time.sleep(1) | |
# find KMLs (eg: 20200831_193612Z_Crawl1_IntenseHeat.kml) | |
for file_path in glob.iglob(f'{path}/*.kml', recursive=False): | |
now = datetime.utcnow() | |
new_obj = f'TACTICAL/{now.strftime("%Y%m%d")}_{now.strftime("%H%M%S")}Z_{mission_name}_IntenseHeat.kml' | |
print(f'Uploading {file_path} to {new_obj}...') | |
# Strip points with regex | |
with open(file_path, 'r+') as f: | |
contents = f.read() | |
with open(file_path, 'w') as f: | |
modified_contents = re.sub( | |
r'<Point>[-.\n\t<>a-z0-9,\/]+<\/Point>', '', contents, flags=re.MULTILINE) | |
f.write(modified_contents) | |
s3.upload_file(file_path, bucket, new_obj) | |
os.remove(file_path) | |
print('done!') | |
time.sleep(1) | |
# find IRs (eg: 20200818_031612Z_Crawl1_IRimage.tif) | |
for file_path in glob.iglob(f'{path}/*.tif', recursive=False): | |
now = datetime.utcnow() | |
new_obj = f'IMAGERY/{now.strftime("%Y%m%d")}_{now.strftime("%H%M%S")}Z_{mission_name}_IRimage.tif' | |
print(f'Uploading {file_path} to {new_obj}...') | |
s3.upload_file(file_path, bucket, new_obj) | |
os.remove(file_path) | |
print('done!') | |
time.sleep(1) | |
print('Goodbye!') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment