Spaces:
Paused
Paused
prabinpanta0
commited on
Commit
·
f9cf047
1
Parent(s):
9096cff
updated randomness
Browse files- app.py +19 -7
- form_filler.py +12 -9
- static/script.js +30 -13
app.py
CHANGED
@@ -35,13 +35,25 @@ def stop_form_filling():
|
|
35 |
|
36 |
@app.route('/status', methods=['GET'])
|
37 |
def get_status():
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
if __name__ == '__main__':
|
47 |
app.run(host='0.0.0.0', port=5000)
|
|
|
35 |
|
36 |
@app.route('/status', methods=['GET'])
|
37 |
def get_status():
|
38 |
+
with form_filler.lock:
|
39 |
+
if form_filler.responses_sent == 0 and form_filler.errors == 0 and form_filler.iterations_left == form_filler.total_iterations:
|
40 |
+
# This condition checks if everything is still initializing
|
41 |
+
return jsonify({
|
42 |
+
"total_iterations": form_filler.total_iterations,
|
43 |
+
"responses_sent": None, # Return None instead of 0 to indicate uninitialized
|
44 |
+
"errors": None,
|
45 |
+
"iterations_left": form_filler.iterations_left,
|
46 |
+
"environment_status": None
|
47 |
+
})
|
48 |
+
else:
|
49 |
+
return jsonify({
|
50 |
+
"total_iterations": form_filler.total_iterations,
|
51 |
+
"responses_sent": form_filler.responses_sent,
|
52 |
+
"errors": form_filler.errors,
|
53 |
+
"iterations_left": form_filler.iterations_left,
|
54 |
+
"environment_status": list(form_filler.environment_status)
|
55 |
+
})
|
56 |
+
|
57 |
|
58 |
if __name__ == '__main__':
|
59 |
app.run(host='0.0.0.0', port=5000)
|
form_filler.py
CHANGED
@@ -47,13 +47,15 @@ class FormFiller:
|
|
47 |
radio_buttons = driver.find_elements(By.CSS_SELECTOR, 'div[role="radiogroup"]')
|
48 |
for radio_group in radio_buttons:
|
49 |
options = radio_group.find_elements(By.CSS_SELECTOR, 'div[role="radio"]')
|
50 |
-
# Use weighted random choice
|
51 |
-
random.
|
|
|
|
|
52 |
|
53 |
# Handling checkboxes
|
54 |
checkboxes = driver.find_elements(By.CSS_SELECTOR, 'div[role="checkbox"]')
|
55 |
for checkbox in checkboxes:
|
56 |
-
if random.random() < 0.
|
57 |
checkbox.click()
|
58 |
|
59 |
# Handling multiple choice grids
|
@@ -62,12 +64,13 @@ class FormFiller:
|
|
62 |
rows = grid.find_elements(By.CSS_SELECTOR, 'div[role="row"]')
|
63 |
for row in rows:
|
64 |
options = row.find_elements(By.CSS_SELECTOR, 'div[role="radio"]')
|
65 |
-
#
|
66 |
-
random.
|
67 |
-
random.
|
|
|
68 |
|
69 |
# Submit the form
|
70 |
-
submit = driver.find_element(By.CSS_SELECTOR, 'div[role="button"]')
|
71 |
submit.click()
|
72 |
|
73 |
logging.info(f"Form submitted successfully by Environment {environment_id}")
|
@@ -80,7 +83,7 @@ class FormFiller:
|
|
80 |
)
|
81 |
|
82 |
# Wait and reload the form
|
83 |
-
time.sleep(random.uniform(
|
84 |
driver.get(url)
|
85 |
|
86 |
except Exception as e:
|
@@ -128,4 +131,4 @@ class FormFiller:
|
|
128 |
for i in range(remaining_iterations):
|
129 |
futures.append(executor.submit(self.fill_form, url, 1, update_callback, i + 1))
|
130 |
for future in futures:
|
131 |
-
future.result()
|
|
|
47 |
radio_buttons = driver.find_elements(By.CSS_SELECTOR, 'div[role="radiogroup"]')
|
48 |
for radio_group in radio_buttons:
|
49 |
options = radio_group.find_elements(By.CSS_SELECTOR, 'div[role="radio"]')
|
50 |
+
# Use weighted random choice with varying weights
|
51 |
+
weights = [random.random() for _ in options]
|
52 |
+
chosen_option = random.choices(options, weights=weights, k=1)[0]
|
53 |
+
chosen_option.click()
|
54 |
|
55 |
# Handling checkboxes
|
56 |
checkboxes = driver.find_elements(By.CSS_SELECTOR, 'div[role="checkbox"]')
|
57 |
for checkbox in checkboxes:
|
58 |
+
if random.random() < random.uniform(0.3, 0.7): # Vary checkbox selection probability
|
59 |
checkbox.click()
|
60 |
|
61 |
# Handling multiple choice grids
|
|
|
64 |
rows = grid.find_elements(By.CSS_SELECTOR, 'div[role="row"]')
|
65 |
for row in rows:
|
66 |
options = row.find_elements(By.CSS_SELECTOR, 'div[role="radio"]')
|
67 |
+
# Use weighted random choice for each row
|
68 |
+
weights = [random.random() for _ in options]
|
69 |
+
chosen_option = random.choices(options, weights=weights, k=1)[0]
|
70 |
+
chosen_option.click()
|
71 |
|
72 |
# Submit the form
|
73 |
+
submit = driver.find_element(By.CSS_SELECTOR, 'div[role="button"][aria-label="Submit"]')
|
74 |
submit.click()
|
75 |
|
76 |
logging.info(f"Form submitted successfully by Environment {environment_id}")
|
|
|
83 |
)
|
84 |
|
85 |
# Wait and reload the form
|
86 |
+
time.sleep(random.uniform(2, 8)) # Increase variation in wait time
|
87 |
driver.get(url)
|
88 |
|
89 |
except Exception as e:
|
|
|
131 |
for i in range(remaining_iterations):
|
132 |
futures.append(executor.submit(self.fill_form, url, 1, update_callback, i + 1))
|
133 |
for future in futures:
|
134 |
+
future.result()
|
static/script.js
CHANGED
@@ -33,18 +33,35 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
33 |
});
|
34 |
|
35 |
async function updateStatus() {
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
}
|
|
|
|
|
50 |
});
|
|
|
33 |
});
|
34 |
|
35 |
async function updateStatus() {
|
36 |
+
try {
|
37 |
+
const response = await fetch('/status');
|
38 |
+
if (!response.ok) {
|
39 |
+
throw new Error('Network response was not ok');
|
40 |
+
}
|
41 |
+
|
42 |
+
const data = await response.json();
|
43 |
+
|
44 |
+
// Only update the UI if the data is valid
|
45 |
+
if (data.responses_sent !== null && data.errors !== null && data.iterations_left !== null) {
|
46 |
+
statusDiv.innerHTML = `
|
47 |
+
<p>Total Iterations: ${data.total_iterations || 'N/A'}</p>
|
48 |
+
<p>Responses Sent: ${data.responses_sent}</p>
|
49 |
+
<p>Errors: ${data.errors}</p>
|
50 |
+
<p>Iterations Left: ${data.iterations_left}</p>
|
51 |
+
<h3>Environment Status:</h3>
|
52 |
+
<ul>
|
53 |
+
${data.environment_status && data.environment_status.length > 0 ?
|
54 |
+
data.environment_status.map(status => `<li>${status}</li>`).join('')
|
55 |
+
: '<li>No status available</li>'
|
56 |
+
}
|
57 |
+
</ul>
|
58 |
+
`;
|
59 |
+
}
|
60 |
+
} catch (error) {
|
61 |
+
console.error('Failed to update status:', error);
|
62 |
+
statusDiv.innerHTML = '<p>Error fetching status. Please try again later.</p>';
|
63 |
+
}
|
64 |
}
|
65 |
+
|
66 |
+
|
67 |
});
|