Giter VIP home page Giter VIP logo

pcexpress-pickup's Introduction

pcexpress-pickup

A script to check for available pickup times at PC Express locations

Usage

$ python check_all_by_postal_code.py
usage: check_all_by_postal_code.py [-h] [-p P] [-lat LAT] [-long LONG] [-d D] [-r] [-id ID] [-brands BRANDS]

optional arguments:
  -h, --help         show this help message and exit
  -p P, -postal P    ex: m5w1e6
  -lat LAT           ex: 43.703344
  -long LONG         ex: -79.524619
  -d D, -distance D  Search distance in KM
  -r, -report        report lat + long and stores found within search distance. will not check available pickup times
  -id ID             comma seperated store IDs ex: 1111,1122
  -brands BRANDS     filter by comma seperated store brands ex: loblaw,superstore,zehrs

Report a list of stores available within a 10KM radius

$ python check_all_by_postal_code.py -p m5e1w6 -d 10 -r
For faster lookup times use: -lat 43.703344 -long -79.524619
superstore, id: 2800, 2549 Weston Rd Toronto, Ontario M9N 2A7, approx 0.9 KM away
<...>
fortinos, id: 0096, 3940 Hwy 7 RR 2 Vaughan, Ontario L4L 9C3, approx 9.8 KM away

Use -lat and -long to avoid doing a postal code lookup each time

$ python check_all_by_postal_code.py -lat 43.703344 -long -79.524619 -d 10 
9 available at nofrills at 245 Dixon Rd Etobicoke, Ontario M9P 2M4 approx 1.8 KM away
2020-04-14 09:00:00-04:00
<...>
2020-04-23 19:00:00-04:00

1 available at loblaw at 270 The Kingsway Etobicoke, Ontario M9A 3T7 approx 4.7 KM away
2020-04-23 16:00:00-04:00

1 available at loblaw at 3671 Dundas St W Toronto, Ontario M6S 2T3 approx 4.8 KM away
2020-04-23 16:00:00-04:00

Use -id to search for pickup times at specific stores. Geo lookup disaabled, so distance will always be 0 KM

$ python check_all_by_postal_code.py -id 2800,3480,1174
20 available at loblaw at 270 The Kingsway Etobicoke, Ontario M9A 3T7 approx 0 KM away
2020-04-14 14:00:00-04:00
<...>
2020-04-23 15:00:00-04:00

Installation using a python3 virtual environment - python 3.6 or newer required

$ git clone https://github.com/shmick/pcexpress-pickup
$ python3 -m venv pcexpress-pickup/
$ cd pcexpress-pickup/
$ source bin/activate
$ pip install -r requirements.txt 

Run via Docker

$ docker run shmick/pcexpress-pickup -lat 43.703344 -long -79.524619
8 available at nofrills at 245 Dixon Rd Etobicoke, Ontario M9P 2M4 approx 1.8 KM away
2020-04-23 12:00:00-04:00
<...>
2020-04-23 19:00:00-04:00

1 available at loblaw at 3671 Dundas St W Toronto, Ontario M6S 2T3 approx 4.8 KM away
2020-04-23 16:00:00-04:00

Build and run your own container

$ git clone https://github.com/shmick/pcexpress-pickup
$ cd pcexpress-pickup/
$ docker build -t pcexpress-pickup:latest .
$ docker run shmick/pcexpress-pickup

Notes

https://www.pcexpress.ca/bundle.js contains a list of all pcexpress pickup locations as well as plenty of other store and location metadata.

Active stores locations have been extracted to locations.json, which is what the utility uses.

The entire unfiltered location dataset has been saved to unfiltered-locations.json

location sample data

{
  "locations": [
    {
      "id": "0925",
      "contactNumber": "7096430850",
      "name": "Prince Rupert Street",
      "storeId": "0925",
      "storeBannerId": "dominion",
      "locationType": "STORE",
      "pickupType": "STORE",
      "bufferTimeInHours": 2,
      "partner": null,
      "visible": true,
      "isShoppable": true,
      "geoPoint": {
        "latitude": 48.546052,
        "longitude": -58.582397
      },
      "address": {
        "country": "Canada",
        "region": "Newfoundland and Labrador",
        "town": "Stephenville",
        "line1": "62 Prince Rupert St",
        "line2": null,
        "postalCode": "A2N 3W7",
        "formattedAddress": "62 Prince Rupert St Stephenville, Newfoundland and Labrador A2N 3W7"
      },
      "timeZone": "Canada/Newfoundland",
      "features": []
    },
    {
      "id": "0927",
      "contactNumber": "7096513437",
      "name": "Laurell Road",
      "storeId": "0927",
      "storeBannerId": "dominion",
      "locationType": "STORE",
      "pickupType": "STORE",
      "bufferTimeInHours": 2,
      "partner": null,
      "visible": true,
      "isShoppable": true,
      "geoPoint": {
        "latitude": 48.949657,
        "longitude": -54.60071
      },
      "address": {
        "country": "Canada",
        "region": "Newfoundland and Labrador",
        "town": "Gander",
        "line1": "100 Laurell Rd",
        "line2": null,
        "postalCode": "A1V 2V5",
        "formattedAddress": "100 Laurell Rd Gander, Newfoundland and Labrador A1V 2V5"
      },
      "timeZone": "Canada/Newfoundland",
      "features": []
    }
  ]
}

pcexpress-pickup's People

Contributors

1adam avatar dependabot[bot] avatar shmick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pcexpress-pickup's Issues

Distance calculation is off in more rural areas

If we look at postal codes like "N0M" it covers an area more than 100km wide.

geocoder.ca provides a free rate limited API, unfortunately it outputs XML

index 323dd7d..d8ea270 100644
--- a/check_all_by_postal_code.py
+++ b/check_all_by_postal_code.py
@@ -5,6 +5,7 @@ import haversine
 from datetime import datetime
 from dateutil import tz
 from haversine import haversine, Unit
+from xml.etree import ElementTree

 # f-strings requires python 3.6
 MIN_PYTHON = (3, 6)
@@ -31,12 +32,11 @@ try:
 except:
     mode = ""

-geo_url = "https://geogratis.gc.ca/services/geolocation/en/locate?q=" + postal_code
+geo_url = "https://geocoder.ca/?&geoit=xml&topmatches=0&postal=" + postal_code
 geo_data = requests.get(geo_url)
-geo_json = geo_data.json()
-coords = geo_json[0]["geometry"]["coordinates"]
-pLat = coords[1]
-pLong = coords[0]
+root = ElementTree.fromstring(geo_data.content)
+pLat = float(root[0].text)
+pLong = float(root[1].text)
 myLatLong = (pLat, pLong)```

IndexError: list index out of range (doesn't like some postal codes)

git show --oneline -s

0aa87be (HEAD -> master, origin/master, origin/HEAD) update readme

python3 ./check_all_by_postal_code.py l8b0c1 1

Traceback (most recent call last):
File "./check_all_by_postal_code.py", line 37, in
coords = geo_json[0]["geometry"]["coordinates"]
IndexError: list index out of range

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.