In [141]:
import requests
import shutil
import os
import getpass
from urllib.parse import urlparse
import json
import arrow
import glob
import os
import arrow
import time
import subprocess
In [115]:
def mkyr(blogpath):
raw = arrow.now()
if raw.strftime("%Y") not in os.listdir(blogpath + '/galleries'):
os.mkdir(blogpath + '/galleries/' + raw.strftime("%Y"))
#return(raw.strftime("%Y"))
else:
return('ERROR: Year already exists')
In [116]:
def mkmth(blogpath):
raw = arrow.now()
if raw.strftime("%m") not in os.listdir(blogpath + '/galleries/' + raw.strftime("%Y")):
os.mkdir(blogpath + '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m"))
return(raw.strftime("%m"))
else:
return('ERROR: Month already exists')
In [117]:
def mkday(blogpath):
raw = arrow.now()
if raw.strftime("%d") not in os.listdir(blogpath + '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m")):
os.mkdir(blogpath + '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m") + '/' + raw.strftime('%d'))
return(raw.strftime('%d'))
else:
return('ERROR: Day already exists')
In [139]:
def cpdayimg(orginpath, blogpath):
#copies images from origin folder to blog folder
raw = arrow.now()
files = os.listdir(orginpath)
for f in files:
shutil.copy(orginpath + '/' + f, blogpath + '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m") + '/' + raw.strftime('%d'))
return(os.listdir(blogpath + '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m") + '/' + raw.strftime('%d')))
In [140]:
cpdayimg('/home/wcmckee/imgtest', '/home/wcmckee/artctrl-test/')
Out[140]:
In [129]:
def mkblogpost(blogpath, postname, tagblog):
raw = arrow.now()
fultim = raw.datetime
if postname + '.md' not in os.listdir(blogpath + '/posts'):
with open(blogpath + '/posts/' + postname + '.meta', 'w') as daympo:
daympo.write('.. title: {}\n.. slug: {}\n.. date: {}\n.. tags: {}\n.. link:\n.. description:\n.. type: text'.format(postname, postname, fultim, tagblog))
with open(blogpath + '/posts/' + postname + '.md', 'w') as daymark:
for toar in os.listdir(blogpath + '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m") + '/' + raw.strftime('%d')):
daymark.write('![{}]({}{})\n\n'.format(toar.replace('.png', ''), '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m") + '/' + raw.strftime('%d') + '/', toar))
else:
return('ERROR: post already exists')
In [178]:
import awscli
In [179]:
awscli.en
Out[179]:
In [181]:
awscli.EnvironmentVariables
Out[181]:
In [ ]:
In [136]:
def syncblogpost():
#rsync the galleries and post files to various services - aws and digitalocean bucket.
folder of images. create request that creates json of image name, id, and text descrion. this is the text that goes after the image.
In [163]:
def imgjstru(blogpath, postname):
sampdict = dict()
raw = arrow.now()
for osli in os.listdir(blogpath + '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m") + '/' + raw.strftime('%d')):
#print(osli)
sampdict.update({osli : dict({'id' : 'one', 'text' : 'sampletext'})})
#os.listdir(blogpath + '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m") + '/' + raw.strftime('%d'))
return(sampdict)
In [173]:
def singimg(blogpath, postname, imgname, imgtxt):
sampdict = dict()
raw = arrow.now()
with open(blogpath + '/posts/' + postname + '.md', 'a') as daymark:
daymark.write('![{}]({}{})\n\n{}\n\n'.format(imgname.replace('.png', ''), '/galleries/' + raw.strftime("%Y") + '/' + raw.strftime("%m") + '/' + raw.strftime('%d') + '/', imgname, imgtxt))
In [174]:
singimg('/home/wcmckee/artctrl-test', 'omgz', 'hello.png', 'this is lame')
In [175]:
singimg('/home/wcmckee/artctrl-test', 'omgz', 'never.png', 'well this didnt look good')
In [ ]:
In [ ]:
In [164]:
sam
In [165]:
imgjstru('/home/wcmckee/artctrl-test', 'testing')
Out[165]:
In [ ]:
In [ ]:
In [ ]: