Skip to content

Commit

Permalink
allow passing of an event as json file
Browse files Browse the repository at this point in the history
  • Loading branch information
bedroge committed Dec 14, 2021
1 parent 775421b commit bf67d06
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions eessi_bot_software_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
import datetime
import flask
import github
import json
import os
import pprint
import sys
from collections import namedtuple
from requests.structures import CaseInsensitiveDict

LOG = os.path.join(os.getenv('HOME'), 'eessi-bot-software-layer.log')

Expand Down Expand Up @@ -41,6 +45,18 @@ def log_event(request):
log(msg_txt)


def read_event_from_json(jsonfile):
"""
Read in event data from a json file.
"""
req = namedtuple('Request', ['headers', 'json'])
with open(jsonfile, 'r') as jf:
event_data = json.load(jf)
req.headers = CaseInsensitiveDict(event_data['headers'])
req.json = event_data['json']
return req


def create_app(gh):
"""
Create Flask app.
Expand All @@ -66,5 +82,9 @@ def main():


if __name__ == '__main__':
app = main()
app.run()
if len(sys.argv) > 1:
event = read_event_from_json(sys.argv[1])
log_event(event)
else:
app = main()
app.run()

0 comments on commit bf67d06

Please sign in to comment.