Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the frontend for fetching results #99

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def index():

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

#setting up backend to receive urls
@app.route('/save_url', methods=['POST'])
def scrape():
def scrap():
urls = request.form.getlist('urls')
validated_urls = validate_urls(urls)

Expand Down Expand Up @@ -97,4 +97,4 @@ def analysis():
return render_template('test.html')

if __name__ == '__main__':
app.run(debug=True)
app.run(debug=True)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions static/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// app.js

new Vue({
el: '#app',
data: {
loading: false,
results: [],
error: null
},
methods: {
fetchAnalysisResults() {
// Reset previous results and error
this.results = [];
this.error = null;

// Set loading state
this.loading = true;

// Simulate a request (replace with your actual API call)
setTimeout(() => {
// Simulated data
const success = Math.random() > 0.5;

if (success) {
this.results = ['Result 1', 'Result 2', 'Result 3'];
} else {
this.error = 'Failed to fetch results. Please try again.';
}

// Reset loading state
this.loading = false;
}, 3000); // Simulate a 3-second request
}
}
});
67 changes: 67 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!-- index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Analysis Results</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<!-- Include Vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue@2"></script>
<style>
body {
background-color: #f8f9fa;
}
#app {
max-width: 600px;
margin: 50px auto;
padding: 20px;
border: 1px solid #ced4da;
border-radius: 5px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
button {
margin-top: 10px;
}
.loading {
color: #007bff;
font-size: 18px;
font-weight: bold;
}
.results {
margin-top: 20px;
}
.error {
margin-top: 20px;
color: #dc3545;
}
</style>
</head>
<body>
<div id="app">
<h1 class="text-center mb-4">Analysis Results</h1>

<button class="btn btn-primary" @click="fetchAnalysisResults">Fetch Results</button>

<!-- Loading indicator -->
<div v-if="loading" class="loading text-center">Loading...</div>

<!-- Display results -->
<div v-if="!loading && results.length > 0" class="results">
<h2>Fetched Data:</h2>
<ul class="list-group">
<li v-for="result in results" :key="result" class="list-group-item">{{ result }}</li>
</ul>
</div>

<!-- Display error message -->
<div v-if="error" class="error">
<h2>Error:</h2>
<p>{{ error }}</p>
</div>
</div>

<script src="{{ url_for('static', filename='app.js') }}"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions templates/scraped_data.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<title>Scraped Data</title>
</head>
<body>
<div class="container mt-4">
<h2>Scraped Data</h2>

{% for data in data %}
<h3>{{ data['website'] }}</h3>
<ul>
{% for title in data['titles'] %}
<li>{{ title }}</li>
{% endfor %}
</ul>
{% endfor %}
</div>
</body>
</html>