From acb9fc558a2b6ca376c3a1e4c452c13bf8ce30a0 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 1 May 2025 18:22:21 -0400 Subject: [PATCH] django web server --- README.md | 12 ++ dedup.py | 5 + delibs.py | 7 + webapp/authapp/__init__.py | 0 webapp/authapp/admin.py | 3 + webapp/authapp/apps.py | 6 + webapp/authapp/migrations/__init__.py | 0 webapp/authapp/models.py | 3 + webapp/authapp/templates/authapp/home.html | 11 ++ webapp/authapp/templates/authapp/login.html | 23 ++++ webapp/authapp/templates/authapp/success.html | 7 + webapp/authapp/tests.py | 3 + webapp/authapp/urls.py | 9 ++ webapp/authapp/views.py | 54 ++++++++ webapp/db.sqlite3 | Bin 0 -> 131072 bytes webapp/manage.py | 22 ++++ webapp/webapp/__init__.py | 0 webapp/webapp/asgi.py | 16 +++ webapp/webapp/settings.py | 124 ++++++++++++++++++ webapp/webapp/urls.py | 25 ++++ webapp/webapp/wsgi.py | 16 +++ 21 files changed, 346 insertions(+) create mode 100644 webapp/authapp/__init__.py create mode 100644 webapp/authapp/admin.py create mode 100644 webapp/authapp/apps.py create mode 100644 webapp/authapp/migrations/__init__.py create mode 100644 webapp/authapp/models.py create mode 100644 webapp/authapp/templates/authapp/home.html create mode 100644 webapp/authapp/templates/authapp/login.html create mode 100644 webapp/authapp/templates/authapp/success.html create mode 100644 webapp/authapp/tests.py create mode 100644 webapp/authapp/urls.py create mode 100644 webapp/authapp/views.py create mode 100644 webapp/db.sqlite3 create mode 100755 webapp/manage.py create mode 100644 webapp/webapp/__init__.py create mode 100644 webapp/webapp/asgi.py create mode 100644 webapp/webapp/settings.py create mode 100644 webapp/webapp/urls.py create mode 100644 webapp/webapp/wsgi.py diff --git a/README.md b/README.md index a6a7049..bcb558f 100644 --- a/README.md +++ b/README.md @@ -69,4 +69,16 @@ python dedup.py 0.jpg 1.jpg -scores ### Files made by get_dups Scripts: error level: 0 = NOT a Dup, 1 = Duplicate, 2 = Close Match, 5 = Same GPS GEO-location, 8 = Invalid Image, 9 = File Too small/big. Possible files: dups.txt, alike.txt, sameGPS.txt, invalid.txt, size.txt. +# Run website: +First activate the python environment, then: +``` +pip install django +cd webapp +python manage.py runserver +``` +Visit http://127.0.0.1:8000 +Login as bob, password: guest +Wait a minute...for program to run it will compair a.jpg and b.jpg. +See: authapp/views.py + [![Image of ScreenShot](Screenshot2025-04-26.png)] diff --git a/dedup.py b/dedup.py index 84ad83c..dda89e4 100644 --- a/dedup.py +++ b/dedup.py @@ -89,6 +89,11 @@ def main(): print("Usage: python3 dedup.py file1.jpg file2.jpg") sys.exit(3) + if "-noansi" in sys.argv: + delibs.disable_ansi() + elif "-ansi" in sys.argv: + delibs.enable_ansi() + file1 = sys.argv[1] file2 = sys.argv[2] diff --git a/delibs.py b/delibs.py index 0c214fd..49218ea 100644 --- a/delibs.py +++ b/delibs.py @@ -23,6 +23,13 @@ RESET = "\033[0m" start = time.perf_counter() +def enable_ansi(): + global use_ANSI_Colors + use_ANSI_Colors = True +def disable_ansi(): + global use_ANSI_Colors + use_ANSI_Colors = False + def kill_all(): print("KILLING PROCESS") os.kill(os.getpid(), signal.SIGKILL) # Force kernel-level termination diff --git a/webapp/authapp/__init__.py b/webapp/authapp/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/webapp/authapp/admin.py b/webapp/authapp/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/webapp/authapp/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/webapp/authapp/apps.py b/webapp/authapp/apps.py new file mode 100644 index 0000000..ef802c9 --- /dev/null +++ b/webapp/authapp/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class AuthappConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'authapp' diff --git a/webapp/authapp/migrations/__init__.py b/webapp/authapp/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/webapp/authapp/models.py b/webapp/authapp/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/webapp/authapp/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/webapp/authapp/templates/authapp/home.html b/webapp/authapp/templates/authapp/home.html new file mode 100644 index 0000000..fd45829 --- /dev/null +++ b/webapp/authapp/templates/authapp/home.html @@ -0,0 +1,11 @@ + + + + Dedup WebApp + + +

Welcome

+

Please login...

+ Login + + diff --git a/webapp/authapp/templates/authapp/login.html b/webapp/authapp/templates/authapp/login.html new file mode 100644 index 0000000..010bef9 --- /dev/null +++ b/webapp/authapp/templates/authapp/login.html @@ -0,0 +1,23 @@ + + + + Login + + +

Login

+ {% if messages %} + {% for message in messages %} +
+ {{ message }} +
+ {% endfor %} +{% endif %} + +
+ {% csrf_token %} + + + +
+ + diff --git a/webapp/authapp/templates/authapp/success.html b/webapp/authapp/templates/authapp/success.html new file mode 100644 index 0000000..c621896 --- /dev/null +++ b/webapp/authapp/templates/authapp/success.html @@ -0,0 +1,7 @@ +

Welcome, Bob!

+

You have successfully logged in.

+ +Logout + +

Script Output:

+
{{ script_output }}
diff --git a/webapp/authapp/tests.py b/webapp/authapp/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/webapp/authapp/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/webapp/authapp/urls.py b/webapp/authapp/urls.py new file mode 100644 index 0000000..75095ac --- /dev/null +++ b/webapp/authapp/urls.py @@ -0,0 +1,9 @@ +from django.urls import path +from . import views + +urlpatterns = [ + path('', views.login_view, name='login'), # Handles `/login/` + #path('login/', views.login_view, name='login'), + path('success/', views.success_view, name='success'), + path('logout/', views.logout_view, name='logout'), # New logout path +] diff --git a/webapp/authapp/views.py b/webapp/authapp/views.py new file mode 100644 index 0000000..4ec1ef3 --- /dev/null +++ b/webapp/authapp/views.py @@ -0,0 +1,54 @@ +from django.shortcuts import render, redirect +from django.contrib import messages +import os +import subprocess # To run external scripts + +def login_view(request): + if request.method == 'POST': + username = request.POST.get('username') + password = request.POST.get('password') + + if username == 'bob' and password == 'guest': + # Set session variables + request.session['logged_in'] = True + request.session['username'] = username # Optional: Store username + messages.success(request, 'Login successful!') + return redirect('success') # Redirect to a success page + else: + messages.error(request, 'Invalid credentials!') + + return render(request, 'authapp/login.html') + +def success_view(request): + # Check if user is logged in via session + if not request.session.get('logged_in'): + messages.error(request, 'You must log in first!') + return redirect('login') # Redirect to login page if not authenticated + + # Define paths to your images (adjust as needed) + image1 = os.path.join('..', 'a.jpg') # Full path to a.jpg + image2 = os.path.join('..', 'b.jpg') # Full path to b.jpg + + try: + result = subprocess.run( + ["python", "../dedup.py", image1, image2, "-noansi", "-scores"], + capture_output=True, + text=True + ) + script_output = result.stdout + except Exception as e: + script_output = f"Error: {e}" + + # Pass results to the template + return render(request, "authapp/success.html", { + "script_output": script_output, + }) + +def home_view(request): + return render(request, 'authapp/home.html') # Create home.html in templates + +def logout_view(request): + # Clear session data + request.session.flush() # Or use del request.session['logged_in'] + messages.success(request, 'You have been logged out.') + return redirect('login') diff --git a/webapp/db.sqlite3 b/webapp/db.sqlite3 new file mode 100644 index 0000000000000000000000000000000000000000..01bbbf5614a0e99a3081d82ecce43dbdd26e2109 GIT binary patch literal 131072 zcmeI5Ym6h=RmWZJvfb{sefv4pWTv;>p6%T+Jw5IBW0t`7&UR*+o$cA32b+-+6=l1+ z#}hw#Z1+4A3E|Fc0vq51D3KBgHeVuv-~+EHACgE>5JG?;fD$AiLBN*zV`a%YDbT5HCuJ96HR+2Jd)&jF&g!F zJm!CNC_d*Ym5pQmN3tF7cNq1YyZiG#F3kRi%P74+`-!6*1V8`;KmY_l00ck)1V8`; zKmY_l;N2%MI~^vaQ{%6B*dMV^vkF^`{B`6PA}@u%AO2GKUN{qaC-ipcr$UqCUmt&y zgzy0Y5C8!X009sH0T2KI5Evkkp7MF-m)6>PyIpNI+KEIWsa6}+PF1U=5~=J;g8rY3 zCiCZ$h4Y#Gxpc0OD5fq=`aH95tZBQQTO^-SwOU7Ssk?1TwyL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