diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000000..25696fb89a --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,28 @@ + FROM python:3.8.2 + + ENV PYTHONBUFFERED 1 + ENV PYTHONWRITEBYTECODE 1 + + RUN apt-get update \ + && apt-get install -y netcat + + ENV APP=/app + + # Change the workdir. + WORKDIR $APP + + # Install the requirements + COPY requirements.txt $APP + + RUN pip3 install -r requirements.txt + + # Copy the rest of the files + COPY . $APP + + EXPOSE 8000 + + RUN chmod +x /app/entrypoint.sh + + ENTRYPOINT ["/bin/bash","/app/entrypoint.sh"] + + CMD ["gunicorn", "--bind", ":8000", "--workers", "3", "djangobackend.wsgi"] \ No newline at end of file diff --git a/server/deployment.yaml b/server/deployment.yaml new file mode 100644 index 0000000000..1eebbf60ce --- /dev/null +++ b/server/deployment.yaml @@ -0,0 +1,29 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + run: dealership + name: dealership +spec: + replicas: 1 + selector: + matchLabels: + run: dealership + strategy: + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + type: RollingUpdate + template: + metadata: + labels: + run: dealership + spec: + containers: + - image: us.icr.io/sn-labs-gduzel/dealership:latest + imagePullPolicy: Always + name: dealership + ports: + - containerPort: 8000 + protocol: TCP + restartPolicy: Always \ No newline at end of file diff --git a/server/djangoapp/restapis.py b/server/djangoapp/restapis.py index ca95954155..dd4ad113a6 100644 --- a/server/djangoapp/restapis.py +++ b/server/djangoapp/restapis.py @@ -120,9 +120,9 @@ def get_dealer_by_id_from_cf(url, dealer_id): # Create a get_dealer_reviews_from_cf method to get reviews by dealer id from a cloud function # - Call get_request() with specified arguments # - Parse JSON results into a DealerView object list -def get_dealer_reviews_from_cf(url, id): +def get_dealer_reviews_from_cf(url, dealer_id): results = [] - json_result = get_request(url, id=id) + json_result = get_request(url, id=dealer_id) print(json_result) if isinstance(json_result, list): @@ -172,9 +172,14 @@ def analyze_review_sentiments(dealerreview): authenticator = IAMAuthenticator(api_key) natural_language_understanding = NaturalLanguageUnderstandingV1(version='2021-08-01',authenticator=authenticator) natural_language_understanding.set_service_url(url) - response = natural_language_understanding.analyze( text=dealerreview,features=Features(sentiment=SentimentOptions(targets=[dealerreview]))).get_result() - label=json.dumps(response, indent=2) - label = response['sentiment']['document']['label'] + try: + response = natural_language_understanding.analyze( text=dealerreview,features=Features(sentiment=SentimentOptions(targets=[dealerreview]))).get_result() + label=json.dumps(response, indent=2) + label = response['sentiment']['document']['label'] + + return(label) - return(label) + except: + print("Can't analyze the sentiment") + return 'none' diff --git a/server/djangoapp/templates/djangoapp/about.html b/server/djangoapp/templates/djangoapp/about.html index 00851adad1..fed108173f 100644 --- a/server/djangoapp/templates/djangoapp/about.html +++ b/server/djangoapp/templates/djangoapp/about.html @@ -3,22 +3,57 @@
Welcome to Best Cars dealership,
-home to the best cars in North America
-and soon in Canada. We sell domestic and
-imported cars at reasonable pricessssss.
+Welcome to Best Cars dealership, home to the best cars in North America and soon in Canada.
+We sell domestic and imported cars at reasonable prices.
+