forked from kitaka/prioritizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prioritizer.py
63 lines (48 loc) · 2.09 KB
/
prioritizer.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
from flask import Flask, request
from models.receiver_count_filter import ReceiverCountFilter
import redis
from models.blacklist_cache import BlacklistCache
from models.caching_steps import StepsCache
from models.priority import Priority
from models.registration_message_filter import RegistrationMessageFilter
app = Flask(__name__)
app.config.from_object('settings')
app.config["DEBUG"] = True
def get_redis_client():
return redis.StrictRedis(host='localhost', port=6379, db=0)
def get_steps_cache_instance():
steps_cache = StepsCache(get_redis_client(),
app.config["REGISTRATION_STEPS_API_USERNAME"],
app.config["REGISTRATION_STEPS_API_PASSWORD"],
app.config["REGISTRATION_STEPS_API_URL"],
app.config["STEPS_CACHE_KEY_NAME"])
return steps_cache
@app.route("/router", methods=['GET'])
def outgoing_message_router():
message_filter = RegistrationMessageFilter(get_steps_cache_instance(),
request.args.get('text', None))
receivers = request.args.get('receivers','')
receiver_count_filter = ReceiverCountFilter(receivers.split(","), 2)
filters = [message_filter, receiver_count_filter]
for filter in filters:
if filter.prioritize() == Priority.HIGH:
return "High Priority"
return "Low Priority"
@app.route("/update_script_steps")
def update_script_steps():
steps_cache = get_steps_cache_instance()
steps_cache.delete_script_steps_data()
steps_cache.add_script_steps_data()
return "Steps script in cache successfully updated"
@app.route("/add_to_blacklist", methods=['POST'])
def add_to_blacklist():
"curl -i -X POST -d 'text=example_text' http://127.0.0.1:5000/add_to_blacklist"
if request.form['text']:
client = get_redis_client()
blacklist_cache = BlacklistCache(client)
blacklist_cache.add_to_blacklist(request.form['text'])
return "Successfully added to blacklist"
else:
return "None text found"
if __name__ == "__main__":
app.run()