mirror of
https://github.com/UofCBaja/Interview-Backend.git
synced 2025-06-15 13:24:19 -06:00
feat(putTogether): packagers and writeDB
This commit is contained in:
parent
85ee822e5c
commit
20620922d0
Binary file not shown.
BIN
__pycache__/WriteDB.cpython-313.pyc
Normal file
BIN
__pycache__/WriteDB.cpython-313.pyc
Normal file
Binary file not shown.
BIN
__pycache__/main.cpython-313.pyc
Normal file
BIN
__pycache__/main.cpython-313.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
__pycache__/send_email.cpython-313.pyc
Normal file
BIN
__pycache__/send_email.cpython-313.pyc
Normal file
Binary file not shown.
@ -1,22 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
"""Django's command-line utility for administrative tasks."""
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
"""Run administrative tasks."""
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
|
|
||||||
try:
|
|
||||||
from django.core.management import execute_from_command_line
|
|
||||||
except ImportError as exc:
|
|
||||||
raise ImportError(
|
|
||||||
"Couldn't import Django. Are you sure it's installed and "
|
|
||||||
"available on your PYTHONPATH environment variable? Did you "
|
|
||||||
"forget to activate a virtual environment?"
|
|
||||||
) from exc
|
|
||||||
execute_from_command_line(sys.argv)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,16 +0,0 @@
|
|||||||
"""
|
|
||||||
ASGI config for mysite project.
|
|
||||||
|
|
||||||
It exposes the ASGI callable as a module-level variable named ``application``.
|
|
||||||
|
|
||||||
For more information on this file, see
|
|
||||||
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from django.core.asgi import get_asgi_application
|
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
|
|
||||||
|
|
||||||
application = get_asgi_application()
|
|
@ -1,8 +0,0 @@
|
|||||||
import json
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from .methods.GetSchedulePackager import getSchedulePackager
|
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
|
||||||
res = getSchedulePackager()
|
|
||||||
return HttpResponse(json.dumps(res))
|
|
@ -1,26 +0,0 @@
|
|||||||
import yaml
|
|
||||||
import json
|
|
||||||
|
|
||||||
with open("./mysite/methods/MockDB/schedule.yaml", "r") as scheduleyml:
|
|
||||||
ymlschedule = yaml.safe_load(scheduleyml)
|
|
||||||
|
|
||||||
def getSchedulePackager():
|
|
||||||
"""
|
|
||||||
Formats and allows for the
|
|
||||||
|
|
||||||
``REQUIRES``: None
|
|
||||||
|
|
||||||
``PROMISES``: ``JSON`` http response ready
|
|
||||||
|
|
||||||
``Develop in part by``: Brock T
|
|
||||||
|
|
||||||
``Contact``: darkicewolf50@gmail.ocm
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
return {
|
|
||||||
"statusCode": 200,
|
|
||||||
"isBase64ENcoded": "false",
|
|
||||||
"body": json.dumps(ymlschedule)
|
|
||||||
}
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
|||||||
Date:
|
|
||||||
Sept 16:
|
|
||||||
Meeting Duration: 30 min
|
|
||||||
Meeting Start Times:
|
|
||||||
- 10:00 am
|
|
||||||
- 10:30 am
|
|
||||||
- 11:00 am
|
|
||||||
- 11:30 am
|
|
||||||
- 1:00 pm
|
|
||||||
- 1:30 pm
|
|
||||||
- 2:00 pm
|
|
Binary file not shown.
Binary file not shown.
@ -1,36 +0,0 @@
|
|||||||
import json
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
def SelectAppointment (appointmentJson):
|
|
||||||
"""
|
|
||||||
packages up a response for a http request
|
|
||||||
|
|
||||||
``appointmentJSON``: ``JSON``
|
|
||||||
The appointment date and time details
|
|
||||||
|
|
||||||
``returns``: ``json``
|
|
||||||
Returns the status of the booking confirmation
|
|
||||||
|
|
||||||
``Develop in part by``: Brock T
|
|
||||||
|
|
||||||
``Contact``: darkicewolf50@gmail.com
|
|
||||||
"""
|
|
||||||
|
|
||||||
status = mockWriteFunction(appointmentJson)
|
|
||||||
|
|
||||||
if status:
|
|
||||||
resBody = {"Success": True}
|
|
||||||
else:
|
|
||||||
resBody = {"Success": False}
|
|
||||||
|
|
||||||
return {
|
|
||||||
"statusCode": 200,
|
|
||||||
"isBase64ENcoded": "false",
|
|
||||||
"body": json.dumps(resBody)
|
|
||||||
}
|
|
||||||
|
|
||||||
def mockWriteFunction(appTime):
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
print(SelectAppointment("10:00 AM"))
|
|
@ -1,11 +0,0 @@
|
|||||||
Date:
|
|
||||||
Sept 16:
|
|
||||||
Meeting Duration: 30 min
|
|
||||||
Meeting Start Times:
|
|
||||||
- 10:00 am
|
|
||||||
- 10:30 am
|
|
||||||
- 11:00 am
|
|
||||||
- 11:30 am
|
|
||||||
- 1:00 pm
|
|
||||||
- 1:30 pm
|
|
||||||
- 2:00 pm
|
|
@ -1,47 +0,0 @@
|
|||||||
import json
|
|
||||||
from django.http import HttpResponse
|
|
||||||
|
|
||||||
def index(request):
|
|
||||||
ymlschedule = {"message": False}
|
|
||||||
res = {
|
|
||||||
#"statusCode": 200, commented out because not needed django/wrapper will handle it
|
|
||||||
"isBase64ENcoded": "false",
|
|
||||||
"body": json.dumps(ymlschedule)
|
|
||||||
}
|
|
||||||
return HttpResponse(json.dumps(res), content_type='application/json')
|
|
||||||
'''
|
|
||||||
response = HttpResponse(json.dumps(res), content_type='application/json')
|
|
||||||
response['X-IsBase64Encoded'] = 'false' # Custom header to indicate base64 encoding
|
|
||||||
response.status_code = 200
|
|
||||||
return response
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from fastapi.responses import JSONResponse
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
@app.get("/")
|
|
||||||
async def index():
|
|
||||||
ymlschedule = {"message": False}
|
|
||||||
|
|
||||||
# Create the response body with multiple items
|
|
||||||
res = {
|
|
||||||
"body": {
|
|
||||||
"Schedule": ymlschedule, # FastAPI will automatically serialize the dictionary
|
|
||||||
"message": "good",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set custom headers
|
|
||||||
headers = {
|
|
||||||
"isBase64Encoded": "false", # Custom header
|
|
||||||
}
|
|
||||||
|
|
||||||
# Return the response with the custom header
|
|
||||||
return JSONResponse(
|
|
||||||
content=res,
|
|
||||||
headers=headers,
|
|
||||||
# status_code=200 commented out just to show how to change it if you wanted
|
|
||||||
)
|
|
||||||
|
|
||||||
'''
|
|
@ -1,8 +0,0 @@
|
|||||||
import json
|
|
||||||
from django.http import HttpResponse
|
|
||||||
from .methods.postSelectAppointment import SelectAppointment
|
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
|
||||||
res = SelectAppointment(request)
|
|
||||||
return HttpResponse(json.dumps(res))
|
|
@ -1,123 +0,0 @@
|
|||||||
"""
|
|
||||||
Django settings for mysite project.
|
|
||||||
|
|
||||||
Generated by 'django-admin startproject' using Django 5.1.3.
|
|
||||||
|
|
||||||
For more information on this file, see
|
|
||||||
https://docs.djangoproject.com/en/5.1/topics/settings/
|
|
||||||
|
|
||||||
For the full list of settings and their values, see
|
|
||||||
https://docs.djangoproject.com/en/5.1/ref/settings/
|
|
||||||
"""
|
|
||||||
|
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
|
||||||
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
|
|
||||||
|
|
||||||
# SECURITY WARNING: keep the secret key used in production secret!
|
|
||||||
SECRET_KEY = "django-insecure-6&71dc8$=p0pg+5=7^_vk6_an^8o2mrr)gh1gs5#i56h)f2um6"
|
|
||||||
|
|
||||||
# SECURITY WARNING: don't run with debug turned on in production!
|
|
||||||
DEBUG = True
|
|
||||||
|
|
||||||
ALLOWED_HOSTS = []
|
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
|
||||||
"django.contrib.admin",
|
|
||||||
"django.contrib.auth",
|
|
||||||
"django.contrib.contenttypes",
|
|
||||||
"django.contrib.sessions",
|
|
||||||
"django.contrib.messages",
|
|
||||||
"django.contrib.staticfiles",
|
|
||||||
]
|
|
||||||
|
|
||||||
MIDDLEWARE = [
|
|
||||||
"django.middleware.security.SecurityMiddleware",
|
|
||||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
|
||||||
"django.middleware.common.CommonMiddleware",
|
|
||||||
"django.middleware.csrf.CsrfViewMiddleware",
|
|
||||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
|
||||||
"django.contrib.messages.middleware.MessageMiddleware",
|
|
||||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
|
||||||
]
|
|
||||||
|
|
||||||
ROOT_URLCONF = "mysite.urls"
|
|
||||||
|
|
||||||
TEMPLATES = [
|
|
||||||
{
|
|
||||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
|
||||||
"DIRS": [],
|
|
||||||
"APP_DIRS": True,
|
|
||||||
"OPTIONS": {
|
|
||||||
"context_processors": [
|
|
||||||
"django.template.context_processors.debug",
|
|
||||||
"django.template.context_processors.request",
|
|
||||||
"django.contrib.auth.context_processors.auth",
|
|
||||||
"django.contrib.messages.context_processors.messages",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
WSGI_APPLICATION = "mysite.wsgi.application"
|
|
||||||
|
|
||||||
|
|
||||||
# Database
|
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
|
|
||||||
|
|
||||||
DATABASES = {
|
|
||||||
"default": {
|
|
||||||
"ENGINE": "django.db.backends.sqlite3",
|
|
||||||
"NAME": BASE_DIR / "db.sqlite3",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Password validation
|
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
|
|
||||||
|
|
||||||
AUTH_PASSWORD_VALIDATORS = [
|
|
||||||
{
|
|
||||||
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
# Internationalization
|
|
||||||
# https://docs.djangoproject.com/en/5.1/topics/i18n/
|
|
||||||
|
|
||||||
LANGUAGE_CODE = "en-us"
|
|
||||||
|
|
||||||
TIME_ZONE = "UTC"
|
|
||||||
|
|
||||||
USE_I18N = True
|
|
||||||
|
|
||||||
USE_TZ = True
|
|
||||||
|
|
||||||
|
|
||||||
# Static files (CSS, JavaScript, Images)
|
|
||||||
# https://docs.djangoproject.com/en/5.1/howto/static-files/
|
|
||||||
|
|
||||||
STATIC_URL = "static/"
|
|
||||||
|
|
||||||
# Default primary key field type
|
|
||||||
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
|
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
|
@ -1,28 +0,0 @@
|
|||||||
"""
|
|
||||||
URL configuration for mysite project.
|
|
||||||
|
|
||||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
|
||||||
https://docs.djangoproject.com/en/5.1/topics/http/urls/
|
|
||||||
Examples:
|
|
||||||
Function views
|
|
||||||
1. Add an import: from my_app import views
|
|
||||||
2. Add a URL to urlpatterns: path('', views.home, name='home')
|
|
||||||
Class-based views
|
|
||||||
1. Add an import: from other_app.views import Home
|
|
||||||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
|
|
||||||
Including another URLconf
|
|
||||||
1. Import the include() function: from django.urls import include, path
|
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
|
||||||
"""
|
|
||||||
|
|
||||||
from django.contrib import admin
|
|
||||||
from django.urls import include, path
|
|
||||||
from . import newtest, getAppointments, selectAppointment
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path("polls/", include("polls.urls")),
|
|
||||||
path("admin/", admin.site.urls),
|
|
||||||
path("test", newtest.index, name="index"),
|
|
||||||
path("getSchedule", getAppointments.index, name="index"),
|
|
||||||
path("postSelectAppointment", selectAppointment.index, name="index"),
|
|
||||||
]
|
|
@ -1,16 +0,0 @@
|
|||||||
"""
|
|
||||||
WSGI config for mysite project.
|
|
||||||
|
|
||||||
It exposes the WSGI callable as a module-level variable named ``application``.
|
|
||||||
|
|
||||||
For more information on this file, see
|
|
||||||
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
|
|
||||||
"""
|
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from django.core.wsgi import get_wsgi_application
|
|
||||||
|
|
||||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
|
|
||||||
|
|
||||||
application = get_wsgi_application()
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,3 +0,0 @@
|
|||||||
from django.contrib import admin
|
|
||||||
|
|
||||||
# Register your models here.
|
|
@ -1,6 +0,0 @@
|
|||||||
from django.apps import AppConfig
|
|
||||||
|
|
||||||
|
|
||||||
class PollsConfig(AppConfig):
|
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
|
||||||
name = "polls"
|
|
@ -1,3 +0,0 @@
|
|||||||
from django.db import models
|
|
||||||
|
|
||||||
# Create your models here.
|
|
@ -1,3 +0,0 @@
|
|||||||
from django.test import TestCase
|
|
||||||
|
|
||||||
# Create your tests here.
|
|
@ -1,12 +0,0 @@
|
|||||||
from django.urls import path
|
|
||||||
|
|
||||||
from . import views
|
|
||||||
# , newtest, getAppointments, selectAppointment
|
|
||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path("", views.index, name="index"),
|
|
||||||
# path("test", newtest.index, name="index"),
|
|
||||||
# path("getSchedule", getAppointments.index, name="index"),
|
|
||||||
# path("postSelectAppointment", selectAppointment.index, name="index"),
|
|
||||||
]
|
|
@ -1,8 +0,0 @@
|
|||||||
# from django.shortcuts import render
|
|
||||||
|
|
||||||
# # Create your views here.
|
|
||||||
from django.http import HttpResponse
|
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
|
||||||
return HttpResponse("Hello, world. You're at the polls index.")
|
|
Binary file not shown.
160
main.py
160
main.py
@ -1,108 +1,72 @@
|
|||||||
from GetSchedulePackager import getSchedulePackager
|
|
||||||
from postSelectAppointment import SelectAppointment
|
|
||||||
import json
|
import json
|
||||||
import signal
|
from fastapi import FastAPI
|
||||||
import sys
|
from fastapi.responses import JSONResponse
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
from pydantic import BaseModel
|
||||||
|
|
||||||
# Define request handler
|
app = FastAPI()
|
||||||
class RequestHandler(BaseHTTPRequestHandler):
|
|
||||||
|
|
||||||
def do_GET(self):
|
@app.get("/")
|
||||||
"""Handle GET requests and route based on path"""
|
def get_root():
|
||||||
if self.path == '/getAppointments':
|
res = {"message": "Hello World"}
|
||||||
self._send_response(getSchedulePackager())
|
|
||||||
elif self.path == '/interview_data':
|
|
||||||
self._send_response(doNothing()) # If you want to return an empty response
|
|
||||||
else:
|
|
||||||
self._send_error(404, "Not Found")
|
|
||||||
|
|
||||||
def do_POST(self):
|
# Return the response with the custom header
|
||||||
"""Handle POST requests to '/selectAppointment' or '/'"""
|
return JSONResponse(
|
||||||
content_length = int(self.headers['Content-Length'])
|
headers={
|
||||||
post_data = self.rfile.read(content_length)
|
"isBase64Encoded": "false", # Header Modification
|
||||||
|
},
|
||||||
# Try to parse JSON data from the request body
|
content={
|
||||||
try:
|
"body": res
|
||||||
json_data = json.loads(post_data.decode('utf-8'))
|
},
|
||||||
except json.JSONDecodeError:
|
|
||||||
self._send_error(400, "Invalid Request")
|
|
||||||
return
|
|
||||||
|
|
||||||
if self.path == '/selectAppointment':
|
|
||||||
self._send_response(SelectAppointment(json_data)) # Use SelectAppointment directly
|
|
||||||
elif self.path == '/':
|
|
||||||
self._send_response(doNothing()) # Empty response for the root route
|
|
||||||
else:
|
|
||||||
self._send_error(404, "Not Found")
|
|
||||||
|
|
||||||
def _send_response(self, res):
|
|
||||||
"""Send the response body with the given status code"""
|
|
||||||
if isinstance(res, dict):
|
|
||||||
# Ensure res has all the required keys
|
|
||||||
body = res.get("body", "") # Default to empty string if no body is provided
|
|
||||||
baseEncoded = res.get("isBase64ENcoded", "false") # Default to "false" if not provided
|
|
||||||
status_code = res.get("statusCode", 200) # Default to 200 if no statusCode is provided
|
|
||||||
|
|
||||||
# Convert body to string if it's not already
|
|
||||||
if isinstance(body, dict):
|
|
||||||
body = json.dumps(body)
|
|
||||||
|
|
||||||
# If body is base64 encoded, we would handle that differently, but currently we treat all as 'false'
|
|
||||||
|
|
||||||
response = {
|
# status_code=200 commented out just to show how to change it if you wanted
|
||||||
"statusCode": status_code,
|
)
|
||||||
"isBase64Encoded": baseEncoded,
|
|
||||||
"headers": {
|
|
||||||
"Content-Type": "application/json", # Specify content type
|
|
||||||
"X-IsBase64Encoded": baseEncoded # Indicating if the body is base64 encoded
|
|
||||||
},
|
|
||||||
"body": body
|
|
||||||
}
|
|
||||||
|
|
||||||
# Send the status code and headers
|
|
||||||
self.send_response(status_code)
|
|
||||||
self.send_header("Content-Type", "application/json")
|
|
||||||
self.end_headers()
|
|
||||||
|
|
||||||
# Write the JSON response body, ensuring it's encoded to utf-8
|
|
||||||
self.wfile.write(json.dumps(response).encode('utf-8'))
|
|
||||||
|
|
||||||
def _send_error(self, status_code=404, message="Not Found"):
|
|
||||||
"""Send error response with the same structure as normal responses"""
|
|
||||||
res = {
|
|
||||||
"statusCode": status_code,
|
|
||||||
"body": json.dumps({"message": message})
|
|
||||||
}
|
|
||||||
# Return the error response in the same format
|
|
||||||
self._send_response(res)
|
|
||||||
|
|
||||||
def doNothing():
|
|
||||||
"""Return an empty JSON response"""
|
|
||||||
return {
|
|
||||||
"statusCode": 200,
|
|
||||||
"isBase64ENcoded": "false",
|
|
||||||
"body": json.dumps({"message": ""})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# Graceful shutdown handler
|
# # Set headers
|
||||||
def signal_handler(sig, frame):
|
# headers = {
|
||||||
print("\nShutting down server gracefully...")
|
# "isBase64Encoded": "false", # Header Modification
|
||||||
sys.exit(0)
|
# }
|
||||||
|
|
||||||
# Set up and start the server
|
from GetSchedulePackager import getSchedulePackager
|
||||||
if __name__ == "__main__":
|
|
||||||
# Register signal handler for graceful shutdown (e.g., Ctrl+C)
|
|
||||||
signal.signal(signal.SIGINT, signal_handler)
|
|
||||||
|
|
||||||
# Set the server address (localhost) and port (8080)
|
@app.get("/getSchedule")
|
||||||
server_address = ('', 8080)
|
async def getSchedule():
|
||||||
httpd = HTTPServer(server_address, RequestHandler)
|
|
||||||
|
res = getSchedulePackager()
|
||||||
|
|
||||||
print("Server started on port 8080")
|
return JSONResponse(
|
||||||
try:
|
headers={
|
||||||
# Start the server and listen for requests
|
"isBase64Encoded": "false", # Header Modification
|
||||||
httpd.serve_forever()
|
},
|
||||||
except KeyboardInterrupt:
|
content={
|
||||||
pass
|
"body": res
|
||||||
|
},
|
||||||
|
|
||||||
|
# status_code=200 commented out just to show how to change it if you wanted
|
||||||
|
)
|
||||||
|
|
||||||
|
from postSelectAppointment import SelectAppointment
|
||||||
|
|
||||||
|
class Appointment(BaseModel):
|
||||||
|
intervieweeName: str
|
||||||
|
date: str
|
||||||
|
startTime: str
|
||||||
|
intervieweeEmail: str
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/SelectInterview")
|
||||||
|
async def postSelectInterview(rawRequest: Appointment):
|
||||||
|
|
||||||
|
requestDict = {key: str(value) for key, value in rawRequest.dict().items()}
|
||||||
|
res = SelectAppointment(requestDict)
|
||||||
|
|
||||||
|
return JSONResponse(
|
||||||
|
headers={
|
||||||
|
"isBase64Encoded": "false", # Header Modification
|
||||||
|
},
|
||||||
|
content={
|
||||||
|
"body": res
|
||||||
|
},
|
||||||
|
|
||||||
|
# status_code=200 commented out just to show how to change it if you wanted
|
||||||
|
)
|
69
newMain.py
69
newMain.py
@ -1,69 +0,0 @@
|
|||||||
import json
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from fastapi.responses import JSONResponse
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
@app.get("/")
|
|
||||||
def get_root():
|
|
||||||
res = {"message": "Hello World"}
|
|
||||||
|
|
||||||
# Return the response with the custom header
|
|
||||||
return JSONResponse(
|
|
||||||
headers={
|
|
||||||
"isBase64Encoded": "false", # Header Modification
|
|
||||||
},
|
|
||||||
content={
|
|
||||||
"body": res
|
|
||||||
},
|
|
||||||
|
|
||||||
# status_code=200 commented out just to show how to change it if you wanted
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# # Set headers
|
|
||||||
# headers = {
|
|
||||||
# "isBase64Encoded": "false", # Header Modification
|
|
||||||
# }
|
|
||||||
|
|
||||||
from GetSchedulePackager import getSchedulePackager
|
|
||||||
|
|
||||||
@app.get("/getSchedule")
|
|
||||||
async def getSchedule():
|
|
||||||
|
|
||||||
res = getSchedulePackager()
|
|
||||||
|
|
||||||
return JSONResponse(
|
|
||||||
headers={
|
|
||||||
"isBase64Encoded": "false", # Header Modification
|
|
||||||
},
|
|
||||||
content={
|
|
||||||
"body": res
|
|
||||||
},
|
|
||||||
|
|
||||||
# status_code=200 commented out just to show how to change it if you wanted
|
|
||||||
)
|
|
||||||
|
|
||||||
from postSelectAppointment import SelectAppointment
|
|
||||||
|
|
||||||
class Appointment(BaseModel):
|
|
||||||
name: str
|
|
||||||
date: str
|
|
||||||
|
|
||||||
@app.post("/SelectInterview")
|
|
||||||
async def postSelectInterview(rawRequest: dict):
|
|
||||||
|
|
||||||
|
|
||||||
res = SelectAppointment(rawRequest)
|
|
||||||
|
|
||||||
return JSONResponse(
|
|
||||||
headers={
|
|
||||||
"isBase64Encoded": "false", # Header Modification
|
|
||||||
},
|
|
||||||
content={
|
|
||||||
"body": res
|
|
||||||
},
|
|
||||||
|
|
||||||
# status_code=200 commented out just to show how to change it if you wanted
|
|
||||||
)
|
|
@ -1,6 +1,5 @@
|
|||||||
import json
|
from WriteDB import AppendAppointment
|
||||||
import datetime
|
|
||||||
import requests
|
|
||||||
|
|
||||||
def SelectAppointment (appointmentJson):
|
def SelectAppointment (appointmentJson):
|
||||||
"""
|
"""
|
||||||
@ -18,18 +17,15 @@ def SelectAppointment (appointmentJson):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
status = mockWriteFunction(appointmentJson)
|
status = AppendAppointment(date=appointmentJson["date"], start_time=appointmentJson["startTime"], interviewee_name=appointmentJson["intervieweeName"], interviewee_email=appointmentJson["intervieweeEmail"])
|
||||||
|
|
||||||
if status:
|
if status:
|
||||||
resBody = {"Success": True, "message": ""}
|
resBody = {"Success": True}
|
||||||
else:
|
else:
|
||||||
resBody = {"Success": False, "message": ""}
|
resBody = {"Success": False}
|
||||||
|
|
||||||
resBody["message"] = appointmentJson["message"]
|
# resBody["message"] = appointmentJson for testing
|
||||||
return resBody
|
return resBody
|
||||||
|
|
||||||
def mockWriteFunction(appTime):
|
|
||||||
return 0
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(SelectAppointment("10:00 AM"))
|
print(SelectAppointment("10:00 AM"))
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
"fastapi[standard]"
|
||||||
|
pandas
|
||||||
|
openpyxl
|
@ -60,7 +60,11 @@ def send_email(interviewee_email="darkicewolf50@gmail.com", interviewee_name="br
|
|||||||
</a>
|
</a>
|
||||||
<p>Best regards,</p>
|
<p>Best regards,</p>
|
||||||
<p>UCalgary Baja Interview Team</p>
|
<p>UCalgary Baja Interview Team</p>
|
||||||
<img src="https://picsum.photos/200/" alt="UCalgary Baja Team" />
|
<img
|
||||||
|
src="https://res.cloudinary.com/dpgrgsh7g/image/upload/v1733003224/UCalgaryBAJA_Logo-2024_mpmljh.png"
|
||||||
|
alt="UCalgary Baja Team"
|
||||||
|
height="120svh"
|
||||||
|
/>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
'''
|
'''
|
||||||
|
@ -20,6 +20,10 @@
|
|||||||
</a>
|
</a>
|
||||||
<p>Best regards,</p>
|
<p>Best regards,</p>
|
||||||
<p>UCalgary Baja Interview Team</p>
|
<p>UCalgary Baja Interview Team</p>
|
||||||
<img src="https://picsum.photos/200/" alt="UCalgary Baja Team" />
|
<img
|
||||||
|
src="https://res.cloudinary.com/dpgrgsh7g/image/upload/v1733003224/UCalgaryBAJA_Logo-2024_mpmljh.png"
|
||||||
|
alt="UCalgary Baja Team"
|
||||||
|
height="120svh"
|
||||||
|
/>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user