Skip to content

Commit 5c518f3

Browse files
committed
complete
0 parents  commit 5c518f3

File tree

7,712 files changed

+1022525
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

7,712 files changed

+1022525
-0
lines changed

chromedriver.exe

16.8 MB
Binary file not shown.

db.sqlite3

128 KB
Binary file not shown.

mailapp/__init__.py

Whitespace-only changes.
154 Bytes
Binary file not shown.
2.88 KB
Binary file not shown.
1008 Bytes
Binary file not shown.
642 Bytes
Binary file not shown.

mailapp/asgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for mailapp project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mailapp.settings')
15+
16+
application = get_asgi_application()

mailapp/settings.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
"""
2+
Django settings for mailapp project.
3+
4+
Generated by 'django-admin startproject' using Django 5.0.7.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.0/ref/settings/
11+
"""
12+
13+
from pathlib import Path
14+
import os
15+
16+
17+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
18+
BASE_DIR = Path(__file__).resolve().parent.parent
19+
20+
21+
# Quick-start development settings - unsuitable for production
22+
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
23+
24+
# SECURITY WARNING: keep the secret key used in production secret!
25+
SECRET_KEY = 'django-insecure-5u&2x)o%pv9$g4ru00w^3$crr)*fhar1nw*vu72wa^1c&^enrn'
26+
27+
# SECURITY WARNING: don't run with debug turned on in production!
28+
DEBUG = True
29+
30+
ALLOWED_HOSTS = []
31+
32+
33+
# Application definition
34+
35+
INSTALLED_APPS = [
36+
'django.contrib.admin',
37+
'django.contrib.auth',
38+
'django.contrib.contenttypes',
39+
'django.contrib.sessions',
40+
'django.contrib.messages',
41+
'django.contrib.staticfiles',
42+
'sendingapp'
43+
]
44+
45+
MIDDLEWARE = [
46+
'django.middleware.security.SecurityMiddleware',
47+
'django.contrib.sessions.middleware.SessionMiddleware',
48+
'django.middleware.common.CommonMiddleware',
49+
'django.middleware.csrf.CsrfViewMiddleware',
50+
'django.contrib.auth.middleware.AuthenticationMiddleware',
51+
'django.contrib.messages.middleware.MessageMiddleware',
52+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
53+
]
54+
55+
ROOT_URLCONF = 'mailapp.urls'
56+
57+
TEMPLATES = [
58+
{
59+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
60+
'DIRS': [],
61+
'APP_DIRS': True,
62+
'OPTIONS': {
63+
'context_processors': [
64+
'django.template.context_processors.debug',
65+
'django.template.context_processors.request',
66+
'django.contrib.auth.context_processors.auth',
67+
'django.contrib.messages.context_processors.messages',
68+
],
69+
},
70+
},
71+
]
72+
73+
WSGI_APPLICATION = 'mailapp.wsgi.application'
74+
75+
76+
# Database
77+
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
78+
79+
DATABASES = {
80+
'default': {
81+
'ENGINE': 'django.db.backends.sqlite3',
82+
'NAME': BASE_DIR / 'db.sqlite3',
83+
}
84+
}
85+
86+
87+
# Password validation
88+
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
89+
90+
AUTH_PASSWORD_VALIDATORS = [
91+
{
92+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
93+
},
94+
{
95+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
96+
},
97+
{
98+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
99+
},
100+
{
101+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
102+
},
103+
]
104+
105+
106+
# Internationalization
107+
# https://docs.djangoproject.com/en/5.0/topics/i18n/
108+
109+
LANGUAGE_CODE = 'en-us'
110+
111+
TIME_ZONE = 'UTC'
112+
113+
USE_I18N = True
114+
115+
USE_TZ = True
116+
117+
118+
# Static files (CSS, JavaScript, Images)
119+
# https://docs.djangoproject.com/en/5.0/howto/static-files/
120+
121+
STATIC_URL = 'static/'
122+
123+
# Default primary key field type
124+
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
125+
126+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
127+
128+
# ----------------------------
129+
# media config
130+
# ----------------------------
131+
132+
MEDIA_URL = '/media/'
133+
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
134+
135+
# ----------------------------
136+
# email config
137+
# ----------------------------
138+
139+
# EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
140+
141+
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
142+
EMAIL_HOST = 'smtp.gmail.com'
143+
EMAIL_PORT = 587
144+
EMAIL_USE_TLS = True
145+
EMAIL_HOST_USER = "sender_mail_id"
146+
# Note email app-password is different from regular password
147+
EMAIL_HOST_PASSWORD = 'mail_app_password'

mailapp/urls.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
URL configuration for mailapp project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.0/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
from django.contrib import admin
18+
from django.urls import path, include
19+
20+
urlpatterns = [
21+
path('', include('sendingapp.urls')),
22+
]

mailapp/wsgi.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for mailapp project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mailapp.settings')
15+
16+
application = get_wsgi_application()

manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mailapp.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

media/confirmation_page.png

22.7 KB
Loading

sendingapp/__init__.py

Whitespace-only changes.
157 Bytes
Binary file not shown.
201 Bytes
Binary file not shown.
471 Bytes
Binary file not shown.
198 Bytes
Binary file not shown.
289 Bytes
Binary file not shown.
4.97 KB
Binary file not shown.

sendingapp/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

sendingapp/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class SendingappConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'sendingapp'

sendingapp/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.

sendingapp/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

sendingapp/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

sendingapp/urls.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.urls import path
2+
# from .views import send_test_email, send_advanced_email, home
3+
from .views import home
4+
5+
urlpatterns = [
6+
path('', home),
7+
# path('text/', send_test_email),
8+
# path('file/', send_advanced_email)
9+
10+
]

sendingapp/views.py

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Create your views here.
2+
from django.core.mail import send_mail
3+
from django.http import HttpResponse
4+
from django.core.mail import EmailMessage
5+
6+
from django.conf import settings
7+
import os
8+
9+
from selenium import webdriver
10+
from selenium.webdriver.chrome.service import Service
11+
from selenium.webdriver.common.by import By
12+
from selenium.webdriver.common.keys import Keys
13+
from selenium.webdriver.support.ui import WebDriverWait
14+
from selenium.webdriver.support import expected_conditions as EC
15+
import time
16+
17+
18+
def home(request):
19+
20+
chromedriver_path = os.path.join(settings.BASE_DIR, 'chromedriver.exe')
21+
22+
# Initialize the WebDriver
23+
service = Service(executable_path=chromedriver_path)
24+
driver = webdriver.Chrome(service=service)
25+
26+
try:
27+
# Open the Google Form
28+
driver.get("https://docs.google.com/forms/d/e/1FAIpQLSdUCd3UWQ3VOgeg0ZzNeT-xzNawU8AJ7Xidml-w1vhfBcvBWQ/viewform")
29+
driver.maximize_window()
30+
31+
def wait_and_clear(element):
32+
WebDriverWait(driver, 30).until(EC.element_to_be_clickable(element))
33+
driver.execute_script("arguments[0].scrollIntoView();", element)
34+
element.clear()
35+
36+
# Wait until the input element is present
37+
WebDriverWait(driver, 20).until(
38+
EC.presence_of_element_located((By.CLASS_NAME, 'whsOnd'))
39+
)
40+
41+
42+
b_element = WebDriverWait(driver, 30).until(
43+
EC.presence_of_element_located((By.XPATH, "//span[@class='M7eMe']/b"))
44+
)
45+
46+
code_text = b_element.text
47+
print(code_text)
48+
49+
input_elements = driver.find_elements(By.CLASS_NAME, 'whsOnd')
50+
51+
input_data = [
52+
"J Rohit",
53+
"1234567890",
54+
55+
"123456",
56+
"01/01/1990",
57+
"Male"
58+
]
59+
60+
input_data.append(code_text)
61+
62+
for element, data in zip(input_elements, input_data):
63+
wait_and_clear(element)
64+
element.send_keys(data)
65+
66+
# Wait for the textarea element
67+
WebDriverWait(driver, 20).until(
68+
EC.presence_of_element_located((By.CLASS_NAME, 'KHxj8b'))
69+
)
70+
textarea_element = driver.find_element(By.CLASS_NAME, 'KHxj8b')
71+
wait_and_clear(textarea_element)
72+
textarea_element.send_keys("1234 Main St") # Full Address
73+
74+
# Submit the form
75+
submit_button = WebDriverWait(driver, 30).until(
76+
EC.element_to_be_clickable((By.XPATH, "//span[text()='Submit']"))
77+
)
78+
driver.execute_script("arguments[0].scrollIntoView();", submit_button)
79+
submit_button.click()
80+
81+
# Wait and capture screenshot
82+
WebDriverWait(driver, 20).until(
83+
EC.presence_of_element_located((By.XPATH, "//div[contains(text(), 'response has been recorded')]"))
84+
)
85+
86+
# saving screenshot to the specified path
87+
screenshot_path = os.path.join(settings.BASE_DIR, 'media', 'confirmation_page.png')
88+
driver.save_screenshot(screenshot_path)
89+
90+
# Sending the email
91+
subject = "Python (Selenium) Assignment - Rohit J"
92+
body = """
93+
Dear Sir/Mam,
94+
95+
I hope this email finds you well.
96+
97+
Best regards,
98+
Rohit J
99+
"""
100+
email_from = "sender_mail_id"
101+
recipient_list = ['recipient_mail']
102+
cc_list = ['cc_mail']
103+
104+
email = EmailMessage(subject, body, email_from, recipient_list, cc=cc_list)
105+
email.content_subtype = 'html'
106+
email.attach_file(screenshot_path)
107+
email.send()
108+
109+
except Exception as e:
110+
print(f"An error occurred: {e}")
111+
# Print page source
112+
# print(driver.page_source)
113+
finally:
114+
time.sleep(30)
115+
driver.quit()
116+
117+
return HttpResponse("home page")
118+
119+

0 commit comments

Comments
 (0)