From 20df46c3727f3582f05d8945de8253db177ccca4 Mon Sep 17 00:00:00 2001 From: Sarthak5598 Date: Wed, 29 May 2024 02:58:32 +0530 Subject: [PATCH] The bot should ultimately provide one or more links to the repositories for the projects that match the answers. #11 --- app.py | 39 ++++++++++++--------------------------- repo.json | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 27 deletions(-) create mode 100644 repo.json diff --git a/app.py b/app.py index 6f7a8a2..fdc8689 100644 --- a/app.py +++ b/app.py @@ -2,6 +2,7 @@ import os import sqlite3 +import json import git from dotenv import load_dotenv from flask import Flask, jsonify, request @@ -38,6 +39,9 @@ # logging.info(f"Body: {request.get_data(as_text=True)}") +with open('repos.json') as f: + repos_data = json.load(f) + @app.route("/update_server", methods=["POST"]) def webhook(): if request.method == "POST": @@ -171,33 +175,13 @@ def list_repo(): user_name = data.get("user_name") tech_name = text.strip().lower() - repos = None - if tech_name in {"django"}: - repos = "(https://github.com/OWASP-BLT/BLT)" - elif tech_name in {"python"}: - repos = "(https://github.com/OWASP-BLT/BLT)" - "(https://github.com/OWASP-BLT/BLT-Flutter)" - "(https://github.com/OWASP-BLT/BLT-Lettuce)" - elif tech_name in {"dart", "flutter"}: - repos = "(https://github.com/OWASP-BLT/BLT-Flutter)" - "(https://github.com/OWASP-BLT/BLT-Lettuce)" - elif tech_name in {"blockchain", "cryptography"}: - repos = "(https://github.com/OWASP-BLT/BLT-Bacon)" - elif tech_name in {"javascript"}: - repos = "(https://github.com/OWASP-BLT/BLT-Action)" - "(https://github.com/OWASP-BLT/BLT-Extension)" - "(https://github.com/OWASP-BLT/BLT)" - elif tech_name in {"css", "html"}: - repos = "(https://github.com/OWASP-BLT/BLT-Extension)" - "(https://github.com/OWASP-BLT/BLT)" - - message = ( - f"""Hello {user_name}, You can implement your '{tech_name}' knowledge here: - {repos} - """ - if repos - else f"Hello {user_name}, the technology '{tech_name}' is not recognized. Please try again." - ) + repos = repos_data.get(tech_name) + + if repos: + repos_list = "\n".join(repos) + message = f"Hello {user_name}, you can implement your '{tech_name}' knowledge here:\n{repos_list}" + else: + message = f"Hello {user_name}, the technology '{tech_name}' is not recognized. Please try again." return jsonify( { @@ -205,3 +189,4 @@ def list_repo(): "text": message, } ) + diff --git a/repo.json b/repo.json new file mode 100644 index 0000000..f38ebbf --- /dev/null +++ b/repo.json @@ -0,0 +1,38 @@ +{ + "django": [ + "https://github.com/OWASP-BLT/BLT" + ], + "python": [ + "https://github.com/OWASP-BLT/BLT", + "https://github.com/OWASP-BLT/BLT-Flutter", + "https://github.com/OWASP-BLT/BLT-Lettuce" + ], + "dart": [ + "https://github.com/OWASP-BLT/BLT-Flutter", + "https://github.com/OWASP-BLT/BLT-Lettuce" + ], + "flutter": [ + "https://github.com/OWASP-BLT/BLT-Flutter", + "https://github.com/OWASP-BLT/BLT-Lettuce" + ], + "blockchain": [ + "https://github.com/OWASP-BLT/BLT-Bacon" + ], + "cryptography": [ + "https://github.com/OWASP-BLT/BLT-Bacon" + ], + "javascript": [ + "https://github.com/OWASP-BLT/BLT-Action", + "https://github.com/OWASP-BLT/BLT-Extension", + "https://github.com/OWASP-BLT/BLT" + ], + "css": [ + "https://github.com/OWASP-BLT/BLT-Extension", + "https://github.com/OWASP-BLT/BLT" + ], + "html": [ + "https://github.com/OWASP-BLT/BLT-Extension", + "https://github.com/OWASP-BLT/BLT" + ] + } + \ No newline at end of file