diff --git a/app/api.py b/app/api.py index dcb9ae8..4a6c443 100644 --- a/app/api.py +++ b/app/api.py @@ -205,4 +205,11 @@ def register_api(app): return jsonify({"scraping_active": True}) else: current_app.logger.debug("Scraping is not active.") - return jsonify({"scraping_active": False}) \ No newline at end of file + 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}) \ No newline at end of file diff --git a/app/models.py b/app/models.py index 0f6e7d7..dea64b8 100644 --- a/app/models.py +++ b/app/models.py @@ -136,4 +136,7 @@ class Scraper: def stop_scraping(self): self.scraping_active = False - current_app.logger.debug("Scraping stopped by user") \ No newline at end of file + current_app.logger.debug("Scraping stopped by user") + + def get_end_time(self): + return self.end_time() \ No newline at end of file diff --git a/app/static/index.js b/app/static/index.js index c05bab3..d9304ac 100644 --- a/app/static/index.js +++ b/app/static/index.js @@ -4,7 +4,7 @@ class ScraperApp { this.stopButton = document.getElementById('stopButton'); this.startButton = document.getElementById('startButton'); this.activityIndicator = document.getElementById('activity_indicator'); - + this.endTimeElement = document.getElementById('end_time'); this.init(); } @@ -23,18 +23,38 @@ class ScraperApp { this.activityIndicator.classList.remove('text-bg-danger'); this.activityIndicator.classList.add('text-bg-success'); this.activityIndicator.textContent = 'Active'; + + this.endTimeElement.classList.remove('d-none'); + this.endTimeElement.textContent = data.end_time; + await this.fetchEndTime(); } else { this.startButton.disabled = false; this.stopButton.disabled = true; this.activityIndicator.classList.remove('text-bg-success'); this.activityIndicator.classList.add('text-bg-danger'); this.activityIndicator.textContent = 'Inactive'; + + this.endTimeElement.textContent = ''; + this.endTimeElement.classList.add('d-none'); } } catch (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) { event.preventDefault(); // Prevent the default form submission const formData = new FormData(this.form); diff --git a/app/templates/index.html b/app/templates/index.html index dcb5992..f6e01b8 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -2,7 +2,15 @@ {% block content %}
-

Scraper Inactive

+
+
+

Scraper

+
+
+ + Inactive +
+
{{ form.hidden_tag() }}
@@ -25,4 +33,4 @@
-{% endblock content %} +{% endblock content %} \ No newline at end of file