Skip to content

Commit

Permalink
Merge pull request #121 from ADORSYS-GIS/19-user-friendly-error-messages
Browse files Browse the repository at this point in the history
implementation of user friendly error message
  • Loading branch information
Blindspot22 committed Dec 2, 2023
2 parents 7108327 + 28b130c commit 7c9ae25
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

@app.route("/")
def index():
return redirect(url_for("input"))
return redirect(url_for("index.html"))

@app.route("/input")
def input():
return render_template("index.html")
return render_template("input.html")

#setting up backend to receive urls
@app.route('/save_url', methods=['POST'])
Expand Down
2 changes: 1 addition & 1 deletion error_handling.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import csv
import csv
import requests
from requests.exceptions import RequestException
import os
Expand Down
31 changes: 29 additions & 2 deletions templates/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,41 @@
{% block content %}
<div class="form-container">
<h2>Input Webpage URLs</h2>
<form action="" method="POST" class="input-form">
<form action="" method="POST" class="input-form" onsubmit="validateUrl(); return false;">
<textarea rows="5" cols="60" name="url" placeholder="https://example.com/python-page"></textarea>
<label for="depth">Depth of Scraping:</label>
<input type="number" name="depth" value="1" min="1">
</select>
<button class="btn" type="submit">Scrape Data</button>
</form>
</div>
<script>
// Function to check if a URL is valid
function isValidUrl(url) {
// Regular expression for a more permissive URL validation
const urlRegex = /^(ftp|http|https):\/\/[^ "]+$/;

// Allow URLs without specifying the protocol
const urlWithoutProtocolRegex = /^[^ "]+\.[a-zA-Z]{2,}$/;

// Check if the URL matches either of the regular expressions
return urlRegex.test(url) || urlWithoutProtocolRegex.test(url);
}

// Function to validate the entered URL
function validateUrl() {
// Get the URL value from the input field
const userUrl = document.getElementsByName("url")[0].value;

// Check if the URL is valid
if (isValidUrl(userUrl)) {
// Display success message if the URL is valid
console.log("URL is valid. Proceed with the entered URL: " + userUrl);
} else {
// Display error message if the URL is not valid
alert("Hello dear user, the URL you just passed in isn't valid. Example of an appropriate URL is adorsys.com");
}
}
</script>
{% endblock %}
{% block title %}
Input webpages URLs
Expand Down

0 comments on commit 7c9ae25

Please sign in to comment.