Skip to content

Instantly share code, notes, and snippets.

@zacjones93
Created May 3, 2021 18:42
Show Gist options
  • Save zacjones93/d9b153917062eb7da1a520deef4b54e4 to your computer and use it in GitHub Desktop.
Save zacjones93/d9b153917062eb7da1a520deef4b54e4 to your computer and use it in GitHub Desktop.
// Menu: Plant Photo uploader
// Description: Update your photos and sync to google
// Author: Zac Jones
// Twitter: @zacjones93
// Shortcut: opt p
// requires fs
const fs = await npm("fs");
//? Trying out switching on if files are already selected
//? Running into an error of '[warn] UNCAUGHT EXCEPTION: SyntaxError: Unexpected reserved word'
// let { getSelectedFile } = await kit("file");
// let selectedFiles = await getSelectedFile();
// const getFilePaths = async () => {
// if (selectedFiles) {
// console.log("hey");
// return selectedFiles.split("\n");
// } else {
// console.log("hey2");
// let myPhotos;
// return myPhotos;
// }
// };
const plantName = await arg("Enter a plant name:");
const potSize = await arg("Enter pot size: ");
const shotType = await arg("Is this product or detail?", ["product", "detail"]);
const photos = await drop("Drop your images");
console.log(photos);
let renamePhotoFile = (path, plantName) => {
let tempPath = path.split("/");
tempPath.pop();
tempPath.push(plantName);
let newPath = tempPath.join("/");
fs.rename(path, newPath, (err) => {
if (err) return console.log("there was an error: ", err);
console.log("selectedFiles renamed");
});
};
let renamePhotoToDirectory = (path, plantName) => {
let targetDirectory = "/Users/zac/Desktop/photops/photos";
let photoPath = `${targetDirectory}/${plantName}`;
fs.rename(path, photoPath, (err) => {
if (err) return console.log("there was an error: ", err);
console.log("selectedFiles renamed");
});
};
photos.map((plant, index) => {
if (shotType === "detail") {
renamePhotoToDirectory(
plant.path,
`${plantName}Detail${potSize}_${index + 1}.png`
);
} else {
renamePhotoFile(plant.path, `${plantName}${potSize}_${index + 1}.png`);
}
});
//! TODO: Upload
// Moving pngs to a synced folder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment