I've written a Python script which takes screenshot of my pc at a certain interval and send that screenshot to my S3 bucket. When I run my script with python command, it works, but when I run this script as a background task with pythonw.exe command, the screenshot capturing operation works- but nothing uploads to S3.
Here is my code:
import os
import sys
import time
import Image
import ImageGrab
import getpass
import boto3
import threading
from random import randint
s3 = boto3.resource('s3')
username = getpass.getuser()
#---------------------------------------------------------
#User Settings:
SaveDirectory=r'C:\Users\Md.Rezaur\Dropbox\Screepy_App\screenshot'
ImageEditorPath=r'C:\WINDOWS\system32\mspaint.exe'
def capture_and_send():
interval = randint(10,30)
threading.Timer(interval, capture_and_send).start ()
img=ImageGrab.grab()
saveas=os.path.join(SaveDirectory,'ScreenShot_'+time.strftime('%Y_%m_%d_%H_%M_%S')+'.jpg')
fname = 'ScreenShot_'+time.strftime('%Y_%m_%d_%H_%M_%S')+'.jpg'
img.save(saveas, quality=50, optimize=True)
editorstring='""%s" "%s"'% (ImageEditorPath,saveas)
data = open(fname, 'rb')
s3.Bucket('screepy').put_object(Key=username+'/'+fname, Body=data)
capture_and_send()
If you didn't configure your aws credentials, install the aws-cli and run the command:
aws configure