-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
output_aws.py
executable file
·33 lines (29 loc) · 1.05 KB
/
output_aws.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
Author: Jeremy Parks
Purpose: Function for writing output files to AWS.
Note: Requires Python 3.7.x
'''
import os
import time
from random import randint
import boto3
def write_file(directory, filename, contents, backupdir=''):
while True:
try:
keyname = os.path.join('{}'.format(directory), filename)
s3 = boto3.resource('s3')
s3.Object('gw2crafts.net', keyname).put(Body=contents.encode('utf8'), ContentType='text/html', CacheControl='public, max-age=1260')
if backupdir:
copy_source = {
'Bucket': 'gw2crafts.net',
'Key': keyname
}
b_keyname = os.path.join('{}'.format(backupdir + '/' + directory), filename)
#s3.meta.client.copy(copy_source, 'gw2crafts.net', b_keyname)
s3.Object('gw2crafts.net', b_keyname).copy_from(CopySource='gw2crafts.net/' + keyname, ContentType='text/html', CacheControl='public', Metadata={'X-Robots-Tag': 'noindex'}, MetadataDirective="REPLACE")
return
except Exception as err:
print('ERROR: %s.' % str(err))
time.sleep(randint(1, 10))