-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·49 lines (42 loc) · 1.91 KB
/
main.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
# TODO someday
# don't send if the message is already in the chatbox
# don't send if the game was more than a couple days ago
# TODO also report the day
# TODO would be nice to move to a subdirectory
import re
import sys
from lib import analyze
from lib import pcweb
from google.cloud import exceptions, storage
def process_box_score(event, context):
"""Background Cloud Function to be triggered by Cloud Storage.
Args:
event (dict): The dictionary with data specific to this type of event.
The `data` field contains a description of the event in
the Cloud Storage `object` format described here:
https://cloud.google.com/storage/docs/json_api/v1/objects#resource
context (google.cloud.functions.Context): Metadata of triggering event.
Returns:
None; the output is written to Stackdriver Logging
"""
# print('Event type: {}'.format(context.event_type))
# print('Bucket: {}'.format(event['bucket']))
# print('File: {}'.format(event['name']))
# print('Metageneration: {}'.format(event['metageneration']))
# print('Created: {}'.format(event['timeCreated']))
# print('Updated: {}'.format(event['updated']))
storage_client = storage.Client()
bucket = storage_client.get_bucket(event['bucket'])
blob = bucket.get_blob(event['name'])
print('Event ID: %s bucket: %s object: %s' % (context.event_id, bucket, blob))
if event['name'].find('-replay') > 0:
print('replay, skipping')
return
data = blob.download_as_text()
messages = analyze.analyze(data)
if messages:
pc = pcweb.PcWeb('256') # '1000' for testing
# pc.send_to_thromer('stuff happened', '\n'.join(messages))
for message in messages:
pc.league_chat('%s [Day %s]' % (message, blob.metadata['day']), trailing_whitespace=int(blob.metadata['year']) % 5)