-
Notifications
You must be signed in to change notification settings - Fork 7
/
index_taken_surveys.py
74 lines (63 loc) · 3.57 KB
/
index_taken_surveys.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
import random
import time
import json
from datetime import timedelta
from selenium.webdriver.common.by import By
from web_functions import Web_Functions
from selenium.webdriver.common.action_chains import ActionChains
pulse = Web_Functions(user="selenium")
driver = pulse.open_site('https://collegepulse.com/app/analyze')
pulse.wait_until_element_appears('page-number ')
page_numbers = driver.find_elements_by_class_name('page-number ')
responses = pulse.wait_until_element_appears('responses', find_type = By.ID)
sort_by_responses_btn = driver.find_element_by_id('responses')
pulse.click(sort_by_responses_btn)
print(f"TAKEN SURVEY PAGES FOUND: {len(page_numbers)}\n")
time.sleep(5)
for i in range(1, len(page_numbers) + 1):
# click page_number
pulse.wait_until_element_appears(str(i), By.ID)
page_number = driver.find_element_by_id(str(i))
print(f"... clicking page {page_number.text} button ...")
pulse.click(page_number)
time.sleep(2.5)
surveys = pulse.find_available_surveys(type="all")
web = surveys[0]
mobile = surveys[1]
web_stats = {"questions": 0, "respondents": 0, "time": "00:00:00", "names": []}
mobile_stats = {"questions": 0, "respondents": 0, "time": "00:00:00", "names": []}
for survey in web:
survey_text = survey.text.split('\n')
print(f"WEB: {survey_text}")
web_stats["questions"] += int(survey_text[-2])
web_stats["respondents"] += int(survey_text[2])
web_stats["time"] = pulse.add_times(web_stats['time'], survey_text[-1])
web_stats["names"].append(survey_text[1])
for survey in mobile:
survey_text = survey.text.split('\n')
print(f"MOBILE: {survey_text}")
mobile_stats["questions"] += int(survey_text[-2])
mobile_stats["respondents"] += int(survey_text[4])
mobile_stats["time"] = pulse.add_times(mobile_stats['time'], survey_text[-1])
mobile_stats["names"].append(survey_text[3])
# write these stats to a file to keep track
with open(r'tests\survey_stats\taken_survey_stats.json', 'r') as fp:
all_survey_stats = json.load(fp)
all_survey_stats["Total_Surveys"] += len(web) + len(mobile)
all_survey_stats["Web_Surveys"] += len(web)
all_survey_stats["Mobile_Surveys"] += len(mobile)
all_survey_stats["Mobile_Questions"] += mobile_stats["questions"]
all_survey_stats["Web_Questions"] += web_stats["questions"]
all_survey_stats["Total_Questions"] += mobile_stats["questions"] + web_stats["points"]
all_survey_stats["Web_Time_Expected"] = pulse.add_times(all_survey_stats["Web_Time_Expected"], web_stats['time'])
all_survey_stats["Mobile_Time_Expected"] = pulse.add_times(all_survey_stats["Mobile_Time_Expected"], mobile_stats['time'])
all_survey_stats["Total_Time_Expected"] = pulse.add_times(all_survey_stats["Web_Time_Expected"], all_survey_stats["Mobile_Time_Expected"])
all_survey_stats["Web_Total_Respondents"] += web_stats["respondents"]
all_survey_stats["Mobile_Total_Respondents"] += mobile_stats["respondents"]
all_survey_stats["Total_Respondents"] += mobile_stats["respondents"] + web_stats["respondents"]
[all_survey_stats["Web_Survey_List"].append(name) for name in web_stats["names"]]
[all_survey_stats["Mobile_Survey_List"].append(name) for name in mobile_stats["names"]]
with open(r'tests\survey_stats\taken_survey_stats.json', 'w') as fp:
json.dump(all_survey_stats, fp, indent=2)
print(f"SURVEYS FOUND on PAGE {page_number.text}: WEB {len(web)} MOBILE {len(mobile)}")
driver.quit()