Skip to content

Commit

Permalink
- added documentation for the Main.py module
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxThomasHPI committed Jan 10, 2024
1 parent 480e5f3 commit 375c8d7
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions Main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
"""
The Main.py module with the Flask application to organize the communication from the server side.
Methods:
index(): Show the initial web page.
get_all_frameworks(): Gather all frameworks data and return them to the client.
write_json(): Take all received competencies and fields of study (FoS) and generate a zip file containing the
respective metadata fragments according to the MOOChub API v3.0.
conduct_search(): Ask the query to the search engine and return the results to the client.
"""

import json

from flask import Flask, request, send_file, render_template, jsonify, Markup
Expand All @@ -9,9 +23,13 @@

@app.route('/')
def index():
files = fp.find_framework_files()
"""Show the initial web page.
:return: the rendered starting page
"""
files = fp.find_framework_files() # the names of the frameworks to be included in the initial dropdown menu
docs = []
with open("documentation/documentation.txt", "r") as file:
with open("documentation/documentation.txt", "r") as file: # prepare the documentation file for the html
data = file.read().split("\n")
for i in range(3, len(data)):
docs.append(Markup(data[i]))
Expand All @@ -21,6 +39,10 @@ def index():

@app.route('/get_all_frameworks')
def get_all_frameworks():
"""Gather all frameworks data and return them to the client.
:return: a JSON file containing the data of all frameworks
"""
all_frameworks = fp.get_all_frameworks()
all_frameworks = json.dumps(all_frameworks)

Expand All @@ -29,6 +51,11 @@ def get_all_frameworks():

@app.route('/write_json', methods=['POST'])
def write_json():
"""Take all received competencies and fields of study (FoS) and generate a zip file containing the respective
metadata fragments according to the MOOChub API v3.0.
:return: a zip file with the respective metadata fragments
"""
received_fields = request.get_json()
buffer = fp.write_json(received_fields)
response = send_file(buffer, mimetype='application/zip')
Expand All @@ -39,9 +66,13 @@ def write_json():

@app.route('/conduct_search')
def conduct_search():
"""Ask the query to the search engine and return the results to the client.
:return: a JSON file with the search results
"""
query = request.args.get('query')
results = search_engine.search(query)
results = json.dumps(results)
results = json.dumps(results) # Important! search method returns a list of dictionaries!

return jsonify(results)

Expand Down

0 comments on commit 375c8d7

Please sign in to comment.