From 26a97d4317ee828c2b93eefdd06a1bd573978f4f Mon Sep 17 00:00:00 2001 From: steven Date: Wed, 26 Mar 2025 00:52:44 -0400 Subject: [PATCH 1/2] update center --- templates/map.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/map.html b/templates/map.html index 54df09a..3532f63 100644 --- a/templates/map.html +++ b/templates/map.html @@ -45,7 +45,7 @@ fetch('gas.csv').then(response => response.ok ? response.text() : null).then(csv return } document.getElementById("map").innerHTML="" - let map = L.map('map', {center: [38.25, -85.65], zoom: 11, layers: [L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')]}); + let map = L.map('map', {center: [38.243, -85.647], zoom: 11, layers: [L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')]}); let storeLayers = {}; let store,url; csv.split('\n').forEach(line => { From 80aea735335e7be1216453fa9f4a501cf60dbadd Mon Sep 17 00:00:00 2001 From: steven Date: Wed, 26 Mar 2025 23:04:03 -0400 Subject: [PATCH 2/2] remove unneeded code --- app.py | 62 +++++++++++--------------------------- templates/map.html | 75 +++++++++++++++++++--------------------------- 2 files changed, 47 insertions(+), 90 deletions(-) diff --git a/app.py b/app.py index e23b813..2255982 100644 --- a/app.py +++ b/app.py @@ -1,11 +1,10 @@ -from flask import Flask, render_template, send_from_directory +from flask import Flask,render_template,send_from_directory from flask_caching import Cache import requests -app = Flask(__name__) -app.config['CACHE_TYPE'] = 'SimpleCache' -app.config['CACHE_DEFAULT_TIMEOUT'] = 1800 -cache = Cache(app) +app=Flask(__name__) +app.config['CACHE_TYPE']='SimpleCache' +cache=Cache(app) @app.route("/") def index(): @@ -13,50 +12,23 @@ def index(): @app.route("/gas.svg") def favicon(): - return send_from_directory(app.static_folder, "gas.svg") + return send_from_directory(app.static_folder,"gas.svg") @app.route("/gas.csv") +@cache.cached(timeout=1800) def gas(): - data = cache.get("gas") - if data: return data - - result = ["Sams https://www.samsclub.com/local/fuel-center/-/X"] - for s in samsdata(): + result=["Sams https://www.samsclub.com/local/fuel-center/-/X"] + url='https://www.samsclub.com/api/node/vivaldi/browse/v2/clubfinder/list?distance=10000&nbrOfStores=1000&singleLineAddr=10001' + sams=requests.get(url,headers={'User-Agent':'Mozilla/5.0','Accept-Encoding':'ztsd'}).json() + for s in sams: if 'gasPrices' in s: - p = {11:0,16:0} - for grade in s['gasPrices']: - if grade['gradeId'] in p: - p[grade['gradeId']] = int(grade['price']*100) + p={g['gradeId']:int(g['price']*100) for g in s['gasPrices']} result.append(f"{p[11]},{p[16]},{s['geoPoint']['latitude']},{s['geoPoint']['longitude']},{s['id']}") result.append("Costco https://www.costco.com/warehouse-locations-X.html#:~:text=Gas%20Station") - for s in costcodata(): - if 'US' == s['country'] and 'regular' in s['gasPrices'] and 'PR' != s['state']: - p = {'regular':0,'premium':0} - for grade in p: - p[grade] = int(float(s['gasPrices'][grade])*100) + url='https://www.costco.com/AjaxWarehouseBrowseLookupView?hasGas=true&populateWarehouseDetails=true' + costco=requests.get(url,headers={'User-Agent':'Mozilla/5.0','Accept-Encoding':'gzip'}).json()[1:] + for s in costco: + if 'regular' in s['gasPrices'] and s['country']=='US': + p={g:int(float(s['gasPrices'][g])*100) for g in ['regular','premium']} result.append(f"{p['regular']},{p['premium']},{s['latitude']},{s['longitude']},{s['displayName']}") - data = "\n".join(result) - cache.set("gas", data) - return data - -@app.route("/sams.json") -def samsdata(): - data = cache.get("sams") - if data: return data - - url = 'https://www.samsclub.com/api/node/vivaldi/browse/v2/clubfinder/list?distance=10000&nbrOfStores=1000&singleLineAddr=10001' - response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0', 'Accept-Encoding': 'ztsd'}) - data = response.json() - cache.set("sams", data) - return data - -@app.route("/costco.json") -def costcodata(): - data = cache.get("costco") - if data: return data - - url = 'https://www.costco.com/AjaxWarehouseBrowseLookupView?hasGas=true&populateWarehouseDetails=true' - response = requests.get(url, headers={'User-Agent': 'Mozilla', 'Accept-Encoding': 'gzip'}) - data = response.json()[1:] - cache.set("costco", data) - return data + return "\n".join(result) diff --git a/templates/map.html b/templates/map.html index 3532f63..c866d89 100644 --- a/templates/map.html +++ b/templates/map.html @@ -3,62 +3,47 @@ Gas Prices - + + + - - -
Fetching the latest prices from Sam's and Costco's slow servers...
+