This repository was archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambda_function.py
More file actions
executable file
·75 lines (61 loc) · 2.15 KB
/
lambda_function.py
File metadata and controls
executable file
·75 lines (61 loc) · 2.15 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python2
import logging
try:
from StringIO import StringIO
except ImportError:
from io import StringIO
import boto3
from dmr_marc_users_cs750 import (
get_users,
get_groups_dci, get_groups_bm,
write_contacts_csv,
write_contacts_xlsx,
SIMPLEX,
)
from dmrx_most_heard_n0gsg import (
get_users as get_most_heard,
write_n0gsg_csv,
)
logger = logging.getLogger(__name__)
def s3_contacts(contacts, bucket, key):
s3 = boto3.client('s3')
o = StringIO()
if key.endswith('.csv'):
t = 'text/csv'
if key.startswith('N0GSG/'):
write_n0gsg_csv(contacts, o)
else:
write_contacts_csv(contacts, o)
elif key.endswith('.xlsx'):
t = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
write_contacts_xlsx(contacts, o)
s3.put_object(
Bucket=bucket, Key=key, StorageClass='REDUCED_REDUNDANCY',
Body=o.getvalue(), ContentType=t, ACL='public-read')
o.close()
def lambda_handler(event=None, context=None):
logger.info('Getting MARC Users')
marc = get_users('s3://dmr-contacts/marc/users.csv')
logger.info('Getting BrandMeister Groups')
bm = get_groups_bm('s3://dmr-contacts/brandmeister/groups.json')
logger.info('Getting DMRX Most Heard')
dmrx = get_most_heard()
logger.info('Getting DCI Groups')
dci = get_groups_dci()
logger.info('Writing CS750 Contacts .csv')
s3_contacts(contacts=marc, bucket='dmr-contacts',
key='CS750/DMR_contacts.csv')
logger.info('Writing CS750 .xlsx')
s3_contacts(contacts=SIMPLEX + dci + bm + marc, bucket='dmr-contacts',
key='CS750/dci-bm-marc.xlsx')
logger.info('Writing DMRX Most Heard (N0GSG) .csv')
s3_contacts(contacts=dmrx, bucket='dmr-contacts',
key='N0GSG/dmrx-most-heard.csv')
logger.info('Writing BrandMeister Groups (N0GSG) .csv')
s3_contacts(contacts=bm, bucket='dmr-contacts',
key='N0GSG/brandmeister-groups.csv')
if __name__ == '__main__':
logging.basicConfig(
format='%(asctime)s %(message)s')
logger.setLevel(logging.INFO)
lambda_handler()