#!/usr/bin/python
""" !/home/yo/.virtualenvs/sacrebleu/bin/python """
from sacrecommon import post_video, post_to_wall
from moviecommon import push_video, render_video
from cloudsmovement import last_hour_plot
from sunsetplotter import brightness_plot
import time
import os

# Find newest dir (hopefuly with photos)
dirs = [f for f in os.listdir(os.getcwd()) if os.path.isdir(f)]
newest = max(dirs, key = os.path.getmtime)

# Upload to Youtube
render_video(newest)
video_id = push_video(newest)

# Publish with current date as a message
message = '_' + time.strftime('%d %B %Y, %H:%M') 
post_video(video_id, message)

# Movement detection whole day plot
plotname = last_hour_plot(newest, hour_only = False)
post_to_wall(plotname, ' ')
os.remove(plotname)

# Brightness plot
suntrace = brightness_plot(newest)
post_to_wall(suntrace, ' ')
os.remove(suntrace)
f = np.fft.fft2(gray)
fshift = np.fft.fftshift(f)

rows, cols = gray.shape
crow,ccol = rows/2 , cols/2

# remove the low frequencies by masking with a rectangular 
# window of size 2h x 2h
h = 10
fshift[crow-h : crow+h, ccol-h : ccol+h] = 0

# shift back (we shifted the center before)
f_ishift = np.fft.ifftshift(fshift)

# inverse fft to get the image back 
filtered = np.fft.ifft2(f_ishift)

filtered = np.abs(filtered)

# Convert gray to rgb so you can ..
#filtered_c = cv2.cvtColor(filtered, cv2.COLOR_GRAY2BGR)
# Joint two images
vis = np.concatenate((gray, filtered), axis=0)

# Save on hdd
savepath = 'dupa.png'
cv2.imwrite(savepath, vis)

post_to_wall(savepath, 'high pass filter and original image')
os.remove(savepath)