adds ending time to activity indicator

This commit is contained in:
2025-02-10 17:33:37 +01:00
parent a44c2bfc04
commit a6292d2d0f
4 changed files with 43 additions and 5 deletions

View File

@@ -206,3 +206,10 @@ def register_api(app):
else: else:
current_app.logger.debug("Scraping is not active.") current_app.logger.debug("Scraping is not active.")
return jsonify({"scraping_active": False}) return jsonify({"scraping_active": False})
@app.route('/scraping_get_end_time')
def scraping_get_end_time():
if scraper is None:
current_app.logger.debug("Scraper is not initialized.")
return jsonify({"scraping_active":False})
return jsonify({"end_time": scraper.end_time})

View File

@@ -137,3 +137,6 @@ class Scraper:
def stop_scraping(self): def stop_scraping(self):
self.scraping_active = False self.scraping_active = False
current_app.logger.debug("Scraping stopped by user") current_app.logger.debug("Scraping stopped by user")
def get_end_time(self):
return self.end_time()

View File

@@ -4,7 +4,7 @@ class ScraperApp {
this.stopButton = document.getElementById('stopButton'); this.stopButton = document.getElementById('stopButton');
this.startButton = document.getElementById('startButton'); this.startButton = document.getElementById('startButton');
this.activityIndicator = document.getElementById('activity_indicator'); this.activityIndicator = document.getElementById('activity_indicator');
this.endTimeElement = document.getElementById('end_time');
this.init(); this.init();
} }
@@ -23,18 +23,38 @@ class ScraperApp {
this.activityIndicator.classList.remove('text-bg-danger'); this.activityIndicator.classList.remove('text-bg-danger');
this.activityIndicator.classList.add('text-bg-success'); this.activityIndicator.classList.add('text-bg-success');
this.activityIndicator.textContent = 'Active'; this.activityIndicator.textContent = 'Active';
this.endTimeElement.classList.remove('d-none');
this.endTimeElement.textContent = data.end_time;
await this.fetchEndTime();
} else { } else {
this.startButton.disabled = false; this.startButton.disabled = false;
this.stopButton.disabled = true; this.stopButton.disabled = true;
this.activityIndicator.classList.remove('text-bg-success'); this.activityIndicator.classList.remove('text-bg-success');
this.activityIndicator.classList.add('text-bg-danger'); this.activityIndicator.classList.add('text-bg-danger');
this.activityIndicator.textContent = 'Inactive'; this.activityIndicator.textContent = 'Inactive';
this.endTimeElement.textContent = '';
this.endTimeElement.classList.add('d-none');
} }
} catch (error) { } catch (error) {
console.error('Error checking scraping status:', error); console.error('Error checking scraping status:', error);
} }
} }
async fetchEndTime() {
try {
const response = await fetch('/scraping_get_end_time');
const data = await response.json();
if (data.end_time) {
this.endTimeElement.textContent = `Track until: ${data.end_time}`;
}
} catch (error) {
this.endTimeElement.textContent = 'Error fetching end time';
console.error('Error fetching end time:', error);
}
}
async startScraping(event) { async startScraping(event) {
event.preventDefault(); // Prevent the default form submission event.preventDefault(); // Prevent the default form submission
const formData = new FormData(this.form); const formData = new FormData(this.form);

View File

@@ -2,7 +2,15 @@
{% block content %} {% block content %}
<section id="scrapingFormContainer" class="container-fluid d-flex justify-content-center"> <section id="scrapingFormContainer" class="container-fluid d-flex justify-content-center">
<div class="container-md my-5 mx-2 shadow-lg p-4 "> <div class="container-md my-5 mx-2 shadow-lg p-4 ">
<h2>Scraper <span id="activity_indicator" class="badge text-bg-danger">Inactive</span></h2> <div class="row">
<div class="col">
<h2>Scraper</h2>
</div>
<div class="col text-end">
<span id="end_time" class="badge text-bg-info d-none"></span>
<span id="activity_indicator" class="badge text-bg-danger fw-bold">Inactive</span>
</div>
</div>
<form id="scrapingForm" method="POST" action="{{ url_for('start_scraping') }}"> <form id="scrapingForm" method="POST" action="{{ url_for('start_scraping') }}">
{{ form.hidden_tag() }} {{ form.hidden_tag() }}
<div class="form-group"> <div class="form-group">