python-leafly is available for download through the Python Package Index (PyPi). You can install it right away using pip or easy_install.
pip install leafly
To get started, you're going to need to sign up as a developer on the Leafly developer site. Once you've got an application ID and a key, you're ready to go.
import leafly
leafly = Leafly(app_id, key)
To turn on debug logging:
import logging
logging.basicConfig(level=logging.DEBUG)
python-leafly maps directly to the Leafly API itself. E.g., to get all available strains:
response = leafly.strains()
strains = response['Strains']
for strain in strains:
print strain['UrlName']
To retrieve strain details, just use the UrlName
attribute (i.e., a slug) on a strain object and pass it in as a component to the leafly object.
response = leafly.strains['blue-dream']()
response = leafly.strains['blue-dream'].reviews(take=10, page=0)
for review in response['reviews']:
print review['id'], review['text']
response = leafly.strains['blue-dream'].reviews[1234]()
print response['rating']
response = leafly.strains['blue-dream'].photos(take=10, page=0)
for photo in response['photos']:
print photo['thumb']
response = leafly.strains['blue-dream'].availability(lat=47.606, lon=-122.333)
for dispensary in response:
print dispensary['name']
response = leafly.locations(take=10, page=0, latitude=47.606, longitude=-122.333, hasedibles=True)
for dispensary in response['stores']:
print dispensary['name']
response = leafly.locations['herbal-nation']()
print response['permalink']
response = leafly.locations['herbal-nation'].menu()
for item in response:
print item['name']
response = leafly.locations['herbal-nation'].reviews(skip=0, take=10)
for review in response['reviews']
print review['comments']