Created
August 14, 2017 02:27
-
-
Save ternus/c83cff50b0bfb75cc695d2365fa893ed to your computer and use it in GitHub Desktop.
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 python | |
import os | |
import sys | |
import shutil | |
import datetime | |
import pyperclip | |
clipboard_copy = pyperclip.clipboards.init_osx_clipboard()[0] | |
STATIC_DIR = os.path.join(os.path.dirname(__file__), "static") | |
if len(sys.argv) == 1: | |
print "Usage: %s file.jpg [file.jpg ...]" % sys.argv[0] | |
sys.exit(1) | |
copy_str = "" | |
for fname in sys.argv[1:]: | |
bname = os.path.basename(fname) | |
if not os.path.exists(fname): | |
sys.stderr.write("File not found: %s\n" % fname) | |
sys.exit(1) | |
if not os.path.exists(STATIC_DIR): | |
sys.stderr.write("Couldn't find static dir %s\n" % STATIC_DIR) | |
sys.exit(1) | |
today = datetime.date.today() | |
upload_path = os.path.join("uploads", | |
str(today.year), | |
str(today.month), | |
str(today.day)) | |
full_upload_path = os.path.join(STATIC_DIR, upload_path) | |
if not os.path.exists(full_upload_path): | |
os.makedirs(full_upload_path) | |
bname = bname.replace(' ', '_') | |
target = os.path.join(full_upload_path, bname) | |
shutil.copy(fname, target) | |
copy_str += "![%s]({{ .Site.BaseURL }}/%s/%s)\n" % (bname, upload_path, bname) | |
print "Copied %s to %s" % (fname, target) | |
clipboard_copy(copy_str) | |
print "Done and copied to clipboard." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment