-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
executable file
·111 lines (79 loc) · 2.87 KB
/
app.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
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
from flask import Flask, request, render_template, redirect, url_for
from Newsletter import Newsletter
import glob
import os
import traceback
import sys
import json
app = Flask(__name__)
config = None
scriptPath = os.path.dirname(os.path.abspath(__file__))
pluginList = {}
# read the configuration
def read_config(filename):
# read the configuration from the JSON file
stream = open(filename, "r")
config = json.load(stream)
stream.close()
return config
# read the configuration xml
config = read_config(os.path.join(scriptPath, "config.json"))
def load_plugins():
global scriptPath
pluginPath = os.path.join(scriptPath, "plugins")
sys.path.append(scriptPath)
sys.path.append(pluginPath)
pluginNames = glob.glob(os.path.join(pluginPath, "*.py"))
for x in pluginNames:
pathName = x.replace(".py","")
className = os.path.basename(pathName)
# import the module
mod = __import__(className)
# find the symbol for the class
cls = getattr(mod, className)
# add the plugin to the list
pluginList[ cls().pluginName ] = cls()
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
form = request.form
hostIndex = 0;
locationIndex = 0
for x in config['hosts']:
if x['name'] == form["hostSelect"]:
break
hostIndex += 1
for x in config['locations']:
if x['name'] == form["locationSelect"]:
break
locationIndex += 1
nl = Newsletter(config['clubCity'],
config['clubURL'],
form["film"],
form["filmURL"],
form["hostSelect"],
config["hosts"][hostIndex]['image'],
form["locationSelect"],
config["locations"][locationIndex]['link'],
form["wearing"],
form["showTime"],
form["plotSynopsis"])
load_plugins()
selected_plugins = form.getlist("plugins")
responses = []
for plugin_name in selected_plugins:
plugin = pluginList[plugin_name]
try:
responses.append(plugin.execute(config, nl))
except Exception as e:
# print the stack trace to a string and append it to the list
responses.append(traceback.format_exc())
return render_template('responses.html', responses=responses)
else:
load_plugins()
plugNames = []
for item in pluginList:
plugNames.append(item)
return render_template('form.html', pluginList=plugNames, hostsDict=config['hosts'], locationDict=config['locations'])
if __name__ == '__main__':
app.run(debug=True)