From 32511344b7dca5eb950adba6249681e9b33afce9 Mon Sep 17 00:00:00 2001 From: steven Date: Sun, 20 Apr 2025 11:34:54 -0400 Subject: [PATCH 1/2] fix costco --- app.py | 24 ++++++++++++++++++----- templates/map.html | 47 +++++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/app.py b/app.py index 25b5bd7..20375a1 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,6 @@ from flask import Flask,render_template,send_from_directory from flask_caching import Cache -import requests +import httpx app=Flask(__name__) app.config['CACHE_TYPE']='SimpleCache' @@ -14,14 +14,28 @@ def index(): def favicon(): return send_from_directory(app.static_folder,"gas.svg") -@app.route("/gas.csv") +@app.route("/samsclub.csv") @cache.cached(timeout=1800) -def gas(): - result=["Sams https://www.samsclub.com/local/fuel-center/-/X"] +def sams(): 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() + headers={'User-Agent':'Mozilla/5.0','Accept-Encoding':'ztsd'} + sams=httpx.get(url,headers=headers,timeout=10).json() + result=[] for s in sams: if 'gasPrices' in s: 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']}") return "\n".join(result) + +@app.route("/costco.csv") +@cache.cached(timeout=1800) +def costco(): + url='https://www.costco.com/AjaxWarehouseBrowseLookupView?hasGas=true&populateWarehouseDetails=true' + headers={'Accept':'*/*','Accept-Encoding':'gzip,deflate,br,zstd','Accept-Language':'en','Referer':'costco.com','Sec-Fetch-Mode':'cors','User-Agent':'Mozilla/5.0 Firefox/140.0'} + costco=httpx.Client(http2=True).get(url,headers=headers,timeout=60).json()[1:] + result=[] + 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']}") + return "\n".join(result) diff --git a/templates/map.html b/templates/map.html index 9aee7fe..d1111b9 100644 --- a/templates/map.html +++ b/templates/map.html @@ -14,44 +14,45 @@ color:black; text-decoration:none; } -.Sams{ +.samsclub,.costco{ display:flex; border-radius:33%; text-align:center; align-items:center; font-size:14px; font-weight:bold; - background-color:rgba(0,103,160,0.5); } +.samsclub{background-color:rgba(0,103,160,0.5);} +.costco{background-color:rgba(227,42,54,0.5);}
From f682a0fa80c5c77a6cdc3aac6838de1fa205c40f Mon Sep 17 00:00:00 2001 From: steven Date: Sun, 20 Apr 2025 11:36:19 -0400 Subject: [PATCH 2/2] keep user's last position --- templates/map.html | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/templates/map.html b/templates/map.html index d1111b9..106bc2d 100644 --- a/templates/map.html +++ b/templates/map.html @@ -53,6 +53,31 @@ for (const [chain,url] of Object.entries(chains)){ layerControl.addOverlay(L.layerGroup(),`${chain} request was blocked :(`) }) } +const lastPosition=localStorage.getItem("lastPosition"); +if(lastPosition){ + const pos=JSON.parse(lastPosition); + map.setView(pos.coords,pos.zoom); +} +map.on("moveend zoomend",function(){ + const center=map.getCenter(); + localStorage.setItem("lastPosition",JSON.stringify({coords:[center.lat,center.lng],zoom:map.getZoom()})); +}); +const ResetViewControl=L.Control.extend({ + onAdd:function(map){ + const btn=L.DomUtil.create('button','leaflet-bar leaflet-control'); + btn.innerHTML='⌂'; + btn.title='Reset view'; + btn.style.backgroundColor='white'; + btn.style.font='22px bold'; + btn.style.cursor='pointer'; + L.DomEvent.on(btn,'click',function(e){ + localStorage.removeItem("lastPosition"); + location.reload(); + }); + return btn; + } +}); +map.addControl(new ResetViewControl({position:'topleft'}));