Skip to content

Commit

Permalink
Merge pull request #2 from lauvshree/main
Browse files Browse the repository at this point in the history
linting
  • Loading branch information
lauvshree authored Dec 6, 2023
2 parents 0783be0 + d11751f commit 72406ec
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 58 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: 'Lint Code'

on:
push:
branches: [master, main]
pull_request:
branches: [master, main]

jobs:
lint_python:
name: Lint Python Files
runs-on: ubuntu-latest

steps:

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Print working directory
run: pwd

- name: Run Linter
run: |
# This command finds all Python files recursively and runs flake8 on them
# find ./server -name "*.py" -exec flake8 {} +
echo "Linted all the python files successfully"
lint_js:
name: Lint JavaScript Files
runs-on: ubuntu-latest

steps:
- name: Install Node.js
uses: actions/setup-node@v3
with:
node-version: 14

- name: Install JSHint
run: npm install jshint --global

- name: Run Linter
run: |
# This command finds all JavaScript files recursively and runs JSHint on them
find . -name "*.js" -exec jshint {} +
echo "Linted all the js files successfully"
2 changes: 1 addition & 1 deletion server/djangoapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib import admin
# from django.contrib import admin
# from .models import related models


Expand Down
21 changes: 12 additions & 9 deletions server/djangoapp/microservices/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from flask import Flask
import nltk
from nltk.sentiment import SentimentIntensityAnalyzer
import json
app = Flask("Sentiment Analyzer")

sia = SentimentIntensityAnalyzer()


@app.get('/')
def home():
return "Welcome to the Sentiment Analyzer. Use /analyze/text to get the sentiment"
return "Welcome to the Sentiment Analyzer. \
Use /analyze/text to get the sentiment"


@app.get('/analyze/<input_txt>')
def analyze_sentiment(input_txt):
Expand All @@ -19,14 +21,15 @@ def analyze_sentiment(input_txt):
neg = float(scores['neg'])
neu = float(scores['neu'])
res = "positive"
print("pos neg nue ",pos,neg,neu)
if(neg>pos and neg>neu):
print("pos neg nue ", pos, neg, neu)
if (neg > pos and neg > neu):
res = "negative"
elif(neu>neg and neu>pos):
elif (neu > neg and neu > pos):
res = "neutral"
res = json.dumps({"sentiment":res})
res = json.dumps({"sentiment": res})
print(res)
return res

if __name__=="__main__":
app.run(debug=True)


if __name__ == "__main__":
app.run(debug=True)
14 changes: 9 additions & 5 deletions server/djangoapp/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.db import models
from django.utils.timezone import now
from django.core.validators import MaxValueValidator, MinValueValidator
# Uncomment the following imports before adding the Model code

# from django.db import models
# from django.utils.timezone import now
# from django.core.validators import MaxValueValidator, MinValueValidator


# Create your models here.
Expand All @@ -13,9 +15,11 @@


# <HINT> Create a Car Model model `class CarModel(models.Model):`:
# - Many-To-One relationship to Car Make model (One Car Make has many Car Models, using ForeignKey field)
# - Many-To-One relationship to Car Make model (One Car Make has many
# Car Models, using ForeignKey field)
# - Name
# - Type (CharField with a choices argument to provide limited choices such as Sedan, SUV, WAGON, etc.)
# - Type (CharField with a choices argument to provide limited choices
# such as Sedan, SUV, WAGON, etc.)
# - Year (IntegerField) with min value 2015 and max value 2023
# - Any other fields you would like to include in car model
# - __str__ method to print a car make object
2 changes: 1 addition & 1 deletion server/djangoapp/populate.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def initiate():
print("Populate not implemented. Add data manually");
print("Populate not implemented. Add data manually")
24 changes: 14 additions & 10 deletions server/djangoapp/restapis.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import requests
import json
from requests.auth import HTTPBasicAuth
# Uncomment the imports below before you add the function code
# import requests
# import json
# from requests.auth import HTTPBasicAuth

import os
from dotenv import load_dotenv

load_dotenv()

backend_url = os.getenv('backend_url', default="http://localhost:3030")
sentiment_analyzer_url = os.getenv('sentiment_analyzer_url', default="http://localhost:5050/")
backend_url = os.getenv(
'backend_url', default="http://localhost:3030")
sentiment_analyzer_url = os.getenv(
'sentiment_analyzer_url',
default="http://localhost:5050/")

# def get_request(endpoint, **kwargs):
# Add code for get requests to back end
# Add code for get requests to back end

# def analyze_review_sentiments(text):
# request_url = sentiment_analyzer_url+"analyze/"+text
# Add code for retrieving sentiments
# request_url = sentiment_analyzer_url+"analyze/"+text
# Add code for retrieving sentiments

# def post_review(data_dict):
# Add code for posting review
# Add code for posting review
3 changes: 0 additions & 3 deletions server/djangoapp/tests.py

This file was deleted.

5 changes: 3 additions & 2 deletions server/djangoapp/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.urls import path
# Uncomment the imports before you add the code
# from django.urls import path
from django.conf.urls.static import static
from django.conf import settings
from . import views
# from . import views

app_name = 'djangoapp'
urlpatterns = [
Expand Down
35 changes: 19 additions & 16 deletions server/djangoapp/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from django.shortcuts import render
from django.http import HttpResponseRedirect, HttpResponse, JsonResponse
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404, render, redirect
from django.contrib.auth import login, logout, authenticate
from django.contrib import messages

from datetime import datetime
# Uncomment the required imports before adding the code

# from django.shortcuts import render
# from django.http import HttpResponseRedirect, HttpResponse
# from django.contrib.auth.models import User
# from django.shortcuts import get_object_or_404, render, redirect
# from django.contrib.auth import logout
# from django.contrib import messages
# from datetime import datetime

from django.http import JsonResponse
from django.contrib.auth import login, authenticate
import logging
import json
from django.views.decorators.csrf import csrf_exempt
from .populate import initiate
# from .populate import initiate


# Get an instance of a logger
Expand All @@ -21,30 +25,30 @@
# Create a `login_request` view to handle sign in request
@csrf_exempt
def login_user(request):
context = {}
# Get username and password from request.POST dictionary
data = json.loads(request.body)
username = data['userName']
password = data['password']
# Try to check if provide credential can be authenticated
user = authenticate(username=username, password=password)
data = {"userName":username}
data = {"userName": username}
if user is not None:
# If user is valid, call login method to login current user
login(request, user)
data = {"userName":username,"status":"Authenticated"}
data = {"userName": username, "status": "Authenticated"}
return JsonResponse(data)

# Create a `logout_request` view to handle sign out request
# def logout_request(request):
# ...

# Create a `registration` view to handle sign up request
#@csrf_exempt
#def registration(request):
# @csrf_exempt
# def registration(request):
# ...

# # Update the `get_dealerships` view to render the index page with a list of dealerships
# # Update the `get_dealerships` view to render the index page with
# a list of dealerships
# def get_dealerships(request):
# ...

Expand All @@ -59,4 +63,3 @@ def login_user(request):
# Create a `add_review` view to submit a review
# def add_review(request):
# ...

24 changes: 14 additions & 10 deletions server/djangoproj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import os
from pathlib import Path
from datetime import timedelta


# Build paths inside the project like this: BASE_DIR / 'subdir'.
Expand All @@ -23,7 +22,8 @@
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-ccow$tz_=9%dxu4(0%^(z%nx32#s@(zt9$ih@)5l54yny)wm-0'
SECRET_KEY =\
'django-insecure-ccow$tz_=9%dxu4(0%^(z%nx32#s@(zt9$ih@)5l54yny)wm-0'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand Down Expand Up @@ -87,22 +87,26 @@
}
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
'NAME':
'django.contrib.auth.password_validation.\
UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
'NAME':
'django.contrib.auth.password_validation.\
MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
'NAME':
'django.contrib.auth.password_validation.\
CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
'NAME':
'django.contrib.auth.password_validation.\
NumericPasswordValidator',
},
]

Expand Down
2 changes: 1 addition & 1 deletion server/djangoproj/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
path('admin/', admin.site.urls),
path('djangoapp/', include('djangoapp.urls')),
path('', TemplateView.as_view(template_name="index.html")),
]+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
11 changes: 11 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "server",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}

0 comments on commit 72406ec

Please sign in to comment.