-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo_notes.py
110 lines (94 loc) · 4.42 KB
/
info_notes.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
from connection_google import *
from save_data import *
def check_barriers(driver, note):
# Barrier 1: Check if it stopped at the home page
try:
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, '__title26-inner'))
)
raise Exception("Erro: The site took a long time to load and stopped on the home page")
except Exception as e:
if "home page" in str(e):
raise # Propagate the exception to the outer try
# Barrier 2: Check if the note exists
try:
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, '__title20-inner'))
)
raise Exception(f"Erro: Note {note} does not exist")
except Exception as e:
if "does not exist" in str(e):
raise # Propagate the exception to the outer try
def get_info_notes(notes, language, notes_data, notes_read, driver, first_note, all_notes):
try:
for note in notes:
if note in notes_read:
continue
else:
notes_read.append(note)
if note in all_notes:
last_note_info = {}
note_info = all_notes.get(note, "void")
last_note_info = {
note: note_info
}
notes_data.update(last_note_info)
continue
url = f'https://me.sap.com/notes/{note}/{language["idiom"]}'
driver.get(url)
if first_note:
check_barriers(driver, note)
first_note = False
# Collecting note information
try:
h2_element = WebDriverWait(driver, 60).until(
EC.presence_of_element_located((By.TAG_NAME, 'h2'))
)
title = f'{language["note"]}{h2_element.text}'
note_info = {
note: {
"title": h2_element.text,
"url": url,
"prerequisites": {}
}
}
try:
rows = WebDriverWait(driver, 4).until(
EC.presence_of_all_elements_located(
(By.CSS_SELECTOR, 'tr[data-sap-ui^="__item23-__table2-"]')
)
)
except Exception:
rows = []
if not rows:
note_info[note]["prerequisites"]["void"] = {}
notes_data.update(note_info)
save_data(notes_data)
continue
else:
pre_notes = []
for row in rows:
software_component = row.find_element(By.CSS_SELECTOR, 'td:nth-child(2) span').text
from_version = row.find_element(By.CSS_SELECTOR, 'td:nth-child(3) span').text
to_version = row.find_element(By.CSS_SELECTOR, 'td:nth-child(4) span').text
pre_note = row.find_element(By.CSS_SELECTOR, 'td:nth-child(5) span').text
title = row.find_element(By.CSS_SELECTOR, 'td:nth-child(6) span').text
component = row.find_element(By.CSS_SELECTOR, 'td:nth-child(7) span').text
note_info[note]["prerequisites"].setdefault(software_component, {})
note_info[note]["prerequisites"][software_component].setdefault(from_version, {})
note_info[note]["prerequisites"][software_component][from_version].setdefault(to_version, {})
note_info[note]["prerequisites"][software_component][from_version][to_version][pre_note] = {
"title": title,
"component": component
}
if pre_note not in pre_notes:
pre_notes.append(pre_note)
notes_data.update(note_info)
save_data(notes_data)
get_info_notes(pre_notes, language, notes_data, notes_read, driver, first_note, all_notes)
except Exception as e:
print(f"{language["error_collect"]} {note}: {e}")
continue
except Exception as e:
print(language["error_to_get_notes"] + str(e))
raise # Ensures that the exception is raised to the caller