From 75564e57a305d5ce52bf96f8301c2a009c2c676f Mon Sep 17 00:00:00 2001 From: "Jacob.Fritsche" Date: Sat, 1 Mar 2025 10:32:08 +0100 Subject: [PATCH] GetArticle API to local Neo4J database --- .idea/misc.xml | 3 +++ APICall/GetArticle.py | 21 +++++++++++++++++++++ main.py | 13 +++++++++++++ requirements.txt | 3 +++ 4 files changed, 40 insertions(+) create mode 100644 APICall/GetArticle.py create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.idea/misc.xml b/.idea/misc.xml index e0a4998..353c7c9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ + + \ No newline at end of file diff --git a/APICall/GetArticle.py b/APICall/GetArticle.py new file mode 100644 index 0000000..48efd72 --- /dev/null +++ b/APICall/GetArticle.py @@ -0,0 +1,21 @@ +from flask import Flask, jsonify +from neo4j import GraphDatabase + +class Neo4JAPis: + + def __init__(self, uri, username, password): + self.app = Flask(__name__) + self.setup_routes() + self.driver = GraphDatabase.driver(uri, auth=(username, password)) + + + def setup_routes(self): + @self.app.route('/article', methods=['GET']) + def get_article(): + with self.driver.session() as session: + result = session.run("MATCH (a:Artikel) RETURN a.name AS name, a.EANGTIN as EANGTIN") + article = [{"name": record["name"], "EANGTIN": record["EANGTIN"]} for record in result] + return jsonify(article) + + def run(self, debug=True): + self.app.run(debug=debug) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..bf9ea89 --- /dev/null +++ b/main.py @@ -0,0 +1,13 @@ +import APICall.GetArticle as neo4japi + +from flask import Flask + +def main(): + uri = "bolt://localhost:7687" + username = "neo4j" + password = "daywalker14" + api = neo4japi.Neo4JAPis(uri, username, password) + api.run() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a775a62 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Flask +neo4j +pandas \ No newline at end of file