3
0

3 Commits b230b91023 ... d94cf86991

Autor SHA1 Nachricht Datum
  sxoinas12 d94cf86991 add Model, View, Serializers for xml generator vor 2 Jahren
  sxoinas12 8c410f2d73 update settings and urls files vor 2 Jahren
  sxoinas12 c89c7210c0 add xml_to_json parser vor 2 Jahren

+ 1 - 0
.gitignore

@@ -4,6 +4,7 @@ venv/
 node_modules/
 __pycache__
 **/__pycache__
+telecaster/__pycache__/
 *.pyc
 .pipcache
 .benchmarks/

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/telecaster.iml" filepath="$PROJECT_DIR$/.idea/telecaster.iml" />
+    </modules>
+  </component>
+</project>

+ 17 - 0
.idea/telecaster.iml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="PYTHON_MODULE" version="4">
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$">
+      <excludeFolder url="file://$MODULE_DIR$/virtualenv" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+  <component name="PyDocumentationSettings">
+    <option name="format" value="PLAIN" />
+    <option name="myDocStringFormat" value="Plain" />
+  </component>
+  <component name="TestRunnerService">
+    <option name="PROJECT_TEST_RUNNER" value="py.test" />
+  </component>
+</module>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

BIN
telecaster/db.sqlite3


BIN
telecaster/telecaster/__pycache__/settings.cpython-38.pyc


BIN
telecaster/telecaster/__pycache__/urls.cpython-38.pyc


+ 5 - 0
telecaster/telecaster/models/XmlGeneratorModel.py

@@ -0,0 +1,5 @@
+from django.db import models
+
+
+class XmlGeneratorModel:
+    pass

+ 10 - 0
telecaster/telecaster/parsers/parse_xml_to_json.py

@@ -0,0 +1,10 @@
+def parse_xml_to_json(xml):
+    response = {}
+
+    for child in list(xml):
+        if len(list(child)) > 0:
+            response[child.tag] = parse_xml_to_json(child)
+        else:
+            response[child.tag] = child.text or ''
+
+    return response

+ 2 - 0
telecaster/telecaster/parsers/skroutz_parser.py

@@ -0,0 +1,2 @@
+class SkroutzParser(url):
+    pass

+ 11 - 0
telecaster/telecaster/serializers/XmlGeneratorSerializer.py

@@ -0,0 +1,11 @@
+from rest_framework import serializers
+from ..models import XmlGeneratorModel
+
+
+class XmlGeneratorSerializer(serializers.Serializer):
+    class Meta:
+        model = XmlGeneratorModel
+
+    @classmethod
+    def for_api(validated_data):
+        return validated_data

+ 3 - 0
telecaster/telecaster/serializers/__init__.py

@@ -0,0 +1,3 @@
+from .XmlGeneratorSerializer import XmlGeneratorSerializer
+
+__all__ = ['XmlGeneratorSerializer']

+ 2 - 1
telecaster/telecaster/settings.py

@@ -37,6 +37,7 @@ INSTALLED_APPS = [
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'telecaster',
 ]
 
 MIDDLEWARE = [
@@ -67,7 +68,7 @@ TEMPLATES = [
     },
 ]
 
-WSGI_APPLICATION = 'telecaster.wsgi.application'
+WSGI_APPLICATION = 'wsgi.application'
 
 
 # Database

+ 7 - 1
telecaster/telecaster/urls.py

@@ -14,8 +14,14 @@ Including another URLconf
     2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
 """
 from django.contrib import admin
-from django.urls import path
+from django.urls import path, re_path
+from rest_framework import routers
+from .views import XmlGeneratorView
+
+
+router = routers.SimpleRouter(trailing_slash=False)
 
 urlpatterns = [
+    re_path(r'^generate/xml', view=XmlGeneratorView.as_view()),
     path('admin/', admin.site.urls),
 ]

+ 28 - 0
telecaster/telecaster/views/XmlGeneratorView.py

@@ -0,0 +1,28 @@
+import requests
+
+from rest_framework import views
+from ..serializers import XmlGeneratorSerializer
+from rest_framework.request import Request
+import xml.etree.ElementTree as ElementTree
+from ..models import XmlGeneratorModel
+from django.http import JsonResponse
+from ..parsers.parse_xml_to_json import parse_xml_to_json
+
+class XmlGeneratorView(views.APIView):
+    @classmethod
+    def get(cls, request: Request, *args, **kwargs) -> JsonResponse:
+        return JsonResponse({}, safe=False)
+
+    @classmethod
+    def post(cls, request: Request, *args, **kwargs) -> JsonResponse:
+        url = request.data.get('url')
+
+        if url:
+            response = requests.get(url)
+            if response and response.status_code == 200:
+                response_xml_as_string = response.content
+                response_xml = ElementTree.fromstring(response_xml_as_string)
+                response_json = parse_xml_to_json(response_xml)
+
+        #serialized_response = XmlGeneratorSerializer.for_api()
+        return JsonResponse(response_json, safe=False)

+ 3 - 0
telecaster/telecaster/views/__init__.py

@@ -0,0 +1,3 @@
+from .XmlGeneratorView import XmlGeneratorView
+
+__all__ = ['XmlGeneratorView']