-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdashboard.py
147 lines (109 loc) · 4.63 KB
/
dashboard.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import re
import math
import smtplib
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--ignore-certificate-errors")
chrome_options.add_argument("--disable-popup-blocking")
wd=webdriver.Chrome(chrome_options=chrome_options)
username = "admin"
password = "admin123"
login_url = "https://newstheme.krahatfoundation.org/wp-login.php/"
def login():
wd.get(login_url)
form = wd.find_element_by_id('loginform')
form_post_url = form.get_attribute('action')
# login_url is the current URL
if login_url != form_post_url:
wd.get(form_post_url)
form = wd.find_element_by_id('loginform')
time.sleep(1)
ele = wd.find_element_by_xpath("//input[@id='user_login']")
ele.send_keys(username)
time.sleep(1)
ele1 = wd.find_element_by_xpath("//input[@id='user_pass']")
ele1.send_keys(password)
elements = wd.find_element_by_xpath("//input[@id='wp-submit']")
elements.click()
def post_report():
login()
element = wd.find_element_by_xpath("(//div[@id='adminmenuwrap']/ul/li/a)[2]")
element.click()
element = wd.find_element_by_xpath("(//span[@class='count'])[1]")
num_posts = element.get_attribute("innerText")
num_posts = num_posts[1:-1]
num_posts = int(num_posts)
num_posts = num_posts/20
num_posts = math.ceil(num_posts)
if(num_posts > 5):
num_posts = 5
post_title_data = []
post_links = []
categorys = []
all_data = []
post_seo_score = []
tags = []
time.sleep(3)
#Post Title
j=0
for num in range(num_posts):
j+=1
time.sleep(3)
element = wd.find_element_by_xpath("//table[@class='wp-list-table widefat fixed striped table-view-list posts']")
element.click()
#Post Title
post_titles = element.find_elements_by_xpath("//table[@class='wp-list-table widefat fixed striped table-view-list posts']/tbody/tr/td/strong/a")
for post_title in post_titles:
post_title_data.append(post_title.get_attribute('innerText'))
#Post links
post_titles_links = element.find_elements_by_xpath("//table[@class='wp-list-table widefat fixed striped table-view-list posts']/tbody/tr/td/strong/a")
for post_title_l in post_titles_links:
post_links.append(post_title_l.get_attribute('href'))
#Category
cate = element.find_elements_by_xpath("//table[@class='wp-list-table widefat fixed striped table-view-list posts']/tbody/tr/td[@class='categories column-categories']/a")
for category in cate:
categorys.append(category.get_attribute('innerText'))
#Post SEO Score
post_seo = element.find_elements_by_xpath("//table[@class='wp-list-table widefat fixed striped table-view-list posts']/tbody/tr/td/span[starts-with(@class, 'rank-math-column-display seo-score ')]/strong")
for seo_score in post_seo:
data = seo_score.get_attribute('innerText')
post_seo_score.append(data[:2])
#Tags of Post
post_tags = element.find_elements_by_xpath("//td[@class='tags column-tags']")
for all_tag in post_tags:
tags.append(all_tag.get_attribute('innerText'))
if(j<num_posts):
element = wd.find_element_by_xpath("(//a[@class='next-page button'])[2]")
element.click()
for i in zip(post_title_data, post_links, categorys, post_seo_score, tags):
all_data.append(i)
return all_data
def dashboard():
data = post_report()
seo_prob = []
tag_prob = []
for i in data:
seo = i[3]
if(int(seo) <= 30):
seo_prob.append(i[1])
if(i[4] == "—\nNo tags"):
tag_prob.append(i[1])
s = smtplib.SMTP(host='smtp.gmail.com', port=587)
print("Send Request For Login...")
s.starttls()
print("Hand Saking")
s.login("[email protected]", "P...d")
print("Login...")
message = """\
Subject: Site Problem Detection
Here is the list of SEO Score Problems:"""+ str(seo_prob) +"""Here is the list of Tag Score Problems:.""" + str(tag_prob) +"""."""
s.sendmail("[email protected]", "[email protected]", message)
print("Mail Send Sucessfully!!!")
s.quit()
dashboard()