diff --git a/README.md b/README.md index 99d4ff227e17f8d76cfa9c5eefcfea2cf05a9487..c61606b925058e3de40f7555578d72ddd7c66f33 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,22 @@ --- +pretty_name: cannabis_licenses annotations_creators: - expert-generated language_creators: - expert-generated license: - cc-by-4.0 -pretty_name: cannabis_licenses -size_categories: - - 10K - + --> ## Table of Contents - [Table of Contents](#table-of-contents) @@ -68,33 +63,34 @@ The dataset is partitioned into 18 subsets for each state and the aggregate. | [California](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/ca) | `ca` | ✅ | | [Colorado](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/co) | `co` | ✅ | | [Connecticut](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/ct) | `ct` | ✅ | +| [Delaware](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/de) | `md` | ✅ | | [Illinois](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/il) | `il` | ✅ | | [Maine](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/me) | `me` | ✅ | +| [Maryland](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/md) | `md` | ⚠️ Under development | | [Massachusetts](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/ma) | `ma` | ✅ | | [Michigan](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/mi) | `mi` | ✅ | +| [Missouri](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/mo) | `mo` | ✅ | | [Montana](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/mt) | `mt` | ✅ | | [Nevada](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/nv) | `nv` | ✅ | | [New Jersey](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/nj) | `nj` | ✅ | -| New York | `ny` | ⏳ Expected 2022 Q4 | -| [New Mexico](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/nm) | `nm` | ⚠️ Under development | +| [New Mexico](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/nm) | `nm` | ✅ | +| [New York](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/ny) | `ny` | ⚠️ Under development | | [Oregon](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/or) | `or` | ✅ | | [Rhode Island](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/ri) | `ri` | ✅ | | [Vermont](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/vt) | `vt` | ✅ | | Virginia | `va` | ⏳ Expected 2024 | | [Washington](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/wa) | `wa` | ✅ | -The following (18) states have issued medical cannabis licenses, but are not (yet) included in the dataset: +The following states have issued medical cannabis licenses, but are not (yet) included in the dataset: - Alabama - Arkansas -- Delaware - District of Columbia (D.C.) - Florida +- Kentucky (2024) - Louisiana -- Maryland - Minnesota - Mississippi -- Missouri - New Hampshire - North Dakota - Ohio @@ -112,15 +108,13 @@ You can load the licenses for each state. For example: from datasets import load_dataset # Get the licenses for a specific state. -dataset = load_dataset('cannlytics/cannabis_licenses', 'ca') +dataset = load_dataset('cannlytics/cannabis_licenses', 'all') data = dataset['data'] -assert len(data) > 0 -print('%i licenses.' % len(data)) ``` ### Data Fields -Below is a non-exhaustive list of fields, used to standardize the various data that are encountered, that you may expect encounter in the parsed COA data. +Below is a non-exhaustive list of fields, used to standardize the various data that are encountered, that you may expect to find for each observation. | Field | Example | Description | |-------|-----|-------------| @@ -161,8 +155,7 @@ The data is split into subsets by state. You can retrieve all licenses by reques from datasets import load_dataset # Get all cannabis licenses. -repo = 'cannlytics/cannabis_licenses' -dataset = load_dataset(repo, 'all') +dataset = load_dataset('cannlytics/cannabis_licenses', 'all') data = dataset['data'] ``` @@ -181,14 +174,18 @@ Data about organizations operating in the cannabis industry for each state is va | California | | | Colorado | | | Connecticut | | +| Delaware | | | Illinois | | | Maine | | +| Maryland | | | Massachusetts | | | Michigan | | +| Missouri | | | Montana | | | Nevada | | | New Jersey | | | New Mexico | | +| New York | | | Oregon | | | Rhode Island | | | Vermont | | @@ -218,7 +215,7 @@ python algorithms/main.py Or you can run each algorithm individually. For example: ``` -python algorithms/get_licenses_ca.py +python algorithms/get_licenses_ny.py ``` ### Personal and Sensitive Information @@ -249,7 +246,7 @@ Curated by [🔥Cannlytics](https://cannlytics.com)
### License ``` -Copyright (c) 2022 Cannlytics and the Cannabis Data Science Team +Copyright (c) 2022-2023 Cannlytics and the Cannabis Data Science Team The files associated with this dataset are licensed under a Creative Commons Attribution 4.0 International license. @@ -268,11 +265,11 @@ to a third party. Please cite the following if you use the code examples in your research: ```bibtex -@misc{cannlytics2022, +@misc{cannlytics2023, title={Cannabis Data Science}, author={Skeate, Keegan and O'Sullivan-Sutherland, Candace}, journal={https://github.com/cannlytics/cannabis-data-science}, - year={2022} + year={2023} } ``` diff --git a/algorithms/get_licenses_ak.py b/algorithms/get_licenses_ak.py index 3a705233f7a62818e3b23f3517e00c118d56080d..743134446f225526046384f2f636bc9774d66678 100644 --- a/algorithms/get_licenses_ak.py +++ b/algorithms/get_licenses_ak.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get Alaska Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/6/2022 +Updated: 8/17/2023 License: Description: @@ -35,16 +35,10 @@ import pandas as pd from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By -from selenium.webdriver.chrome.service import Service -try: - import chromedriver_binary # Adds chromedriver binary to path. -except ImportError: - pass # Otherwise, ChromeDriver should be in your path. - # Specify where your data lives. DATA_DIR = '../data/ak' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'AK' @@ -65,42 +59,20 @@ ALASKA = { } -def get_licenses_ak( - data_dir: Optional[str] = None, - env_file: Optional[str] = '.env', - ): - """Get Alaska cannabis license data.""" - - # Initialize Selenium and specify options. - service = Service() - options = Options() - options.add_argument('--window-size=1920,1200') - - # DEV: Run with the browser open. - # options.headless = False - - # PRODUCTION: Run with the browser closed. - options.add_argument('--headless') - options.add_argument('--disable-gpu') - options.add_argument('--no-sandbox') - - # Initiate a Selenium driver. - driver = webdriver.Chrome(options=options, service=service) - - # Load the license page. - driver.get(ALASKA['licenses_url']) - - # Get the license type select. +def get_license_types(driver): + """Get all license types from the select on the page.""" license_types = [] options = driver.find_elements(by=By.TAG_NAME, value='option') for option in options: text = option.text if text: license_types.append(text) + return license_types + - # Iterate over all of the license types. +def extract_table_data(driver, columns, license_types): + """Extract data from the table on the page.""" data = [] - columns = list(ALASKA['licenses']['columns'].values()) for license_type in license_types: # Set the text into the select. @@ -124,10 +96,121 @@ def get_licenses_ak( obs[column] = cell.text.replace('\n', ', ') data.append(obs) - # End the browser session. - service.stop() + return data + + +def search_for_license_addresses( + licenses: pd.DataFrame, + api_key: str, + fields: Optional[list] = None, + ) -> pd.DataFrame: + """ + Search for address for each retail license. + Args: + licenses (pd.DataFrame): A DataFrame containing retail license information, including business names and addresses. + api_key (str): A Google Places API key. + fields (list, optional): A list of fields to be returned by the API. Defaults to None. + Returns: + pd.DataFrame: A DataFrame containing the original license information, as well as corresponding address, phone, and website data. + """ + + # Initialize variables. + queries = {} + if fields is None: + fields = [ + 'formatted_address', + 'formatted_phone_number', + 'geometry/location/lat', + 'geometry/location/lng', + 'website', + ] + + # Reset and assign new columns to the licenses DataFrame. + licenses = licenses.reset_index(drop=True) + licenses = licenses.assign( + premise_street_address=None, + premise_county=None, + premise_latitude=None, + premise_longitude=None, + business_phone=None, + business_website=None, + ) + + # Iterate over each license, search for the address, and record the results in the DataFrame. + for index, row in licenses.iterrows(): + query = ', '.join([row['business_dba_name'], row['address']]) + gis_data = queries.get(query) + + # Query Google Place API, if necessary. + if gis_data is None: + try: + gis_data = search_for_address(query, api_key=api_key, fields=fields) + except: + gis_data = {} + queries[query] = gis_data + + # Record the query results. + licenses.iat[index, licenses.columns.get_loc('premise_street_address')] = gis_data.get('street') + licenses.iat[index, licenses.columns.get_loc('premise_county')] = gis_data.get('county') + licenses.iat[index, licenses.columns.get_loc('premise_latitude')] = gis_data.get('latitude') + licenses.iat[index, licenses.columns.get_loc('premise_longitude')] = gis_data.get('longitude') + licenses.iat[index, licenses.columns.get_loc('business_phone')] = gis_data.get('formatted_phone_number') + licenses.iat[index, licenses.columns.get_loc('business_website')] = gis_data.get('website') + + return licenses + + +def save_license_data( + licenses: pd.DataFrame, + state: str, + data_dir: str = '.', + ) -> None: + """ + Save license data to CSV files. + Args: + licenses (pd.DataFrame): A DataFrame containing license information. + state (str): The two-letter abbreviation for the state associated with the licenses. + data_dir (str, optional): The directory in which to save the data. If None, the data will not be saved. Defaults to None. + """ + if not os.path.exists(data_dir): + os.makedirs(data_dir) + date = datetime.now().strftime('%Y-%m-%d') + retailers = licenses.loc[licenses['license_type'] == 'Retail Marijuana Store'] + licenses.to_csv(f'{data_dir}/licenses-{state.lower()}-{date}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{state.lower()}-latest.csv', index=False) + retailers.to_csv(f'{data_dir}/retailers-{state.lower()}-{date}.csv', index=False) - # Standardize the license data. + +def get_licenses_ak( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ): + """Get Alaska cannabis license data.""" + + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config.get('GOOGLE_MAPS_API_KEY') + + # Initiate a Selenium driver. + # FIXME: ChromeDriver is not working on Windows. + try: + options = Options() + options.add_argument('--headless') + driver = webdriver.Chrome(options=options) + except: + driver = webdriver.Edge() + + # Load the licenses page. + driver.get(ALASKA['licenses_url']) + + # Get the license type select. + license_types = get_license_types(driver) + + # Get all licenses by type. + columns = list(ALASKA['licenses']['columns'].values()) + data = extract_table_data(driver, columns, license_types) + + # Standardize the licenses. licenses = pd.DataFrame(data) licenses = licenses.assign( business_legal_name=licenses['business_dba_name'], @@ -163,49 +246,18 @@ def get_licenses_ak( ) # Search for address for each retail license. - # Only search for a query once, then re-use the response. - # Note: There is probably a much, much more efficient way to do this!!! - config = dotenv_values(env_file) - api_key = config['GOOGLE_MAPS_API_KEY'] - queries = {} - fields = [ - 'formatted_address', - 'formatted_phone_number', - 'geometry/location/lat', - 'geometry/location/lng', - 'website', - ] - licenses = licenses.reset_index(drop=True) - licenses = licenses.assign( - premise_street_address=None, - premise_county=None, - premise_latitude=None, - premise_longitude=None, - business_phone=None, - business_website=None, - ) - for index, row in licenses.iterrows(): - - # Query Google Place API, if necessary. - query = ', '.join([row['business_dba_name'], row['address']]) - gis_data = queries.get(query) - if gis_data is None: - try: - gis_data = search_for_address(query, api_key=api_key, fields=fields) - except: - gis_data = {} - queries[query] = gis_data - - # Record the query. - licenses.iat[index, licenses.columns.get_loc('premise_street_address')] = gis_data.get('street') - licenses.iat[index, licenses.columns.get_loc('premise_county')] = gis_data.get('county') - licenses.iat[index, licenses.columns.get_loc('premise_latitude')] = gis_data.get('latitude') - licenses.iat[index, licenses.columns.get_loc('premise_longitude')] = gis_data.get('longitude') - licenses.iat[index, licenses.columns.get_loc('business_phone')] = gis_data.get('formatted_phone_number') - licenses.iat[index, licenses.columns.get_loc('business_website')] = gis_data.get('website') - - # Clean-up after GIS. - licenses.drop(columns=['address'], inplace=True) + if google_maps_api_key: + fields = [ + 'formatted_address', + 'formatted_phone_number', + 'geometry/location/lat', + 'geometry/location/lng', + 'website', + ] + licenses = search_for_license_addresses(licenses, google_maps_api_key, fields) + + # Clean-up after adding GIS data. + licenses.drop(columns=['address'], inplace=True) # Optional: Search for business website for email and a photo. licenses['business_email'] = None @@ -216,15 +268,12 @@ def get_licenses_ak( # Save and return the data. if data_dir is not None: - if not os.path.exists(data_dir): os.makedirs(data_dir) - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - retailers = licenses.loc[licenses['license_type'] == 'Retail Marijuana Store'] - licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) - retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) + save_license_data(licenses, STATE, data_dir) return licenses # === Test === +# [✓] Tested: 2023-08-12 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_az.py b/algorithms/get_licenses_az.py index 45a35cdbd998087999cb72703345a3eeddb83581..9fa07682ead4844b2aa44e2c3a77355381c573bd 100644 --- a/algorithms/get_licenses_az.py +++ b/algorithms/get_licenses_az.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get Arizona Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/27/2022 -Updated: 10/7/2022 +Updated: 8/17/2023 License: Description: @@ -18,16 +18,22 @@ Data Source: - Arizona Department of Health Services | Division of Licensing URL: +TODO: + + [ ] Separate the functionality into functions. + [ ] Make the code more robust to errors. + [ ] Make Google Maps API key optional. + """ # Standard imports. from datetime import datetime -from dotenv import dotenv_values +# from dotenv import dotenv_values import os from time import sleep -from typing import Optional +from typing import List, Optional # External imports. -from cannlytics.data.gis import geocode_addresses +# from cannlytics.data.gis import geocode_addresses import pandas as pd import zipcodes @@ -38,15 +44,15 @@ from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait -try: - import chromedriver_binary # Adds chromedriver binary to path. -except ImportError: - pass # Otherwise, ChromeDriver should be in your path. +# try: +# import chromedriver_binary # Adds chromedriver binary to path. +# except ImportError: +# pass # Otherwise, ChromeDriver should be in your path. # Specify where your data lives. DATA_DIR = '../data/az' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'AZ' @@ -57,7 +63,7 @@ ARIZONA = { } -def county_from_zip(x): +def get_county_from_zip(x): """Find a county given a zip code. Returns `None` if no match.""" try: return zipcodes.matching(x)[0]['county'] @@ -65,6 +71,70 @@ def county_from_zip(x): return None +def initialize_selenium(): + """Initialize a web driver.""" + try: + service = Service() + options = Options() + options.add_argument('--window-size=1920,1200') + options.add_argument('--headless') + options.add_argument('--disable-gpu') + options.add_argument('--no-sandbox') + return webdriver.Chrome(options=options, service=service) + except: + return webdriver.Edge() + + +def click_load_more(driver, container): + """Click "Load more" until all of the licenses are visible.""" + more = True + while(more): + button = container.find_element(by=By.TAG_NAME, value='button') + driver.execute_script('arguments[0].scrollIntoView(true);', button) + button.click() + counter = container.find_element(by=By.CLASS_NAME, value='count-text') + more = int(counter.text.replace(' more', '')) + + +def get_license_data_from_html(index, el): + """Get a retailer's data.""" + xpath = f'/html/body/div[3]/div[2]/div/div[2]/div[2]/div/div/c-azcc-portal-home/c-azcc-map/div/div[2]/div[2]/div[2]/div[{index + 1}]/c-azcc-map-list-item/div' + list_item = el.find_element(by=By.XPATH, value=xpath) + body = list_item.find_element(by=By.CLASS_NAME, value='slds-media__body') + divs = body.find_elements(by=By.TAG_NAME, value='div') + name = divs[0].text + legal_name = divs[1].text + if not name: + name = legal_name + address = divs[3].text + address_parts = address.split(',') + parts = divs[2].text.split(' · ') + link = divs[-1].find_element(by=By.TAG_NAME, value='a') + href = link.get_attribute('href') + return { + 'address': address, + 'details_url': href, + 'business_legal_name': legal_name, + 'business_dba_name': name, + 'business_phone': parts[-1], + 'license_status': parts[0], + 'license_type': parts[1], + 'premise_street_address': address_parts[0].strip(), + 'premise_city': address_parts[1].strip(), + 'premise_zip_code': address_parts[-1].replace('AZ ', '').strip(), + } + + +def get_value_from_links(links: List[str], prefix: str): + """Get a certain key from given links.""" + for link in links: + href = link.get_attribute('href') + if href is None: + continue + if href.startswith(prefix): + return link.text + + def get_licenses_az( data_dir: Optional[str] = None, env_file: Optional[str] = '.env', @@ -74,21 +144,8 @@ def get_licenses_az( # Create directories if necessary. if not os.path.exists(data_dir): os.makedirs(data_dir) - # Initialize Selenium and specify options. - service = Service() - options = Options() - options.add_argument('--window-size=1920,1200') - - # DEV: Run with the browser open. - # options.headless = False - - # PRODUCTION: Run with the browser closed. - options.add_argument('--headless') - options.add_argument('--disable-gpu') - options.add_argument('--no-sandbox') - - # Initiate a Selenium driver. - driver = webdriver.Chrome(options=options, service=service) + # Initialize Selenium. + driver = initialize_selenium() # Load the license page. driver.get(ARIZONA['licenses_url']) @@ -98,52 +155,18 @@ def get_licenses_az( # Get the map container. container = driver.find_element(by=By.CLASS_NAME, value='slds-container_center') + # Scroll to the bottom of the page. + driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', container) + sleep(1) + # Click "Load more" until all of the licenses are visible. - more = True - while(more): - button = container.find_element(by=By.TAG_NAME, value='button') - driver.execute_script('arguments[0].scrollIntoView(true);', button) - button.click() - counter = container.find_element(by=By.CLASS_NAME, value='count-text') - more = int(counter.text.replace(' more', '')) + click_load_more(driver, container) # Get license data for each retailer. data = [] els = container.find_elements(by=By.CLASS_NAME, value='map-list__item') - for i, el in enumerate(els): - - # Get a retailer's data. - count = i + 1 - xpath = f'/html/body/div[3]/div[2]/div/div[2]/div[2]/div/div/c-azcc-portal-home/c-azcc-map/div/div[2]/div[2]/div[2]/div[{count}]/c-azcc-map-list-item/div' - list_item = el.find_element(by=By.XPATH, value=xpath) - body = list_item.find_element(by=By.CLASS_NAME, value='slds-media__body') - divs = body.find_elements(by=By.TAG_NAME, value='div') - name = divs[0].text - legal_name = divs[1].text - if not name: - name = legal_name - address = divs[3].text - address_parts = address.split(',') - parts = divs[2].text.split(' · ') - - # Get the retailer's link to get more details. - link = divs[-1].find_element(by=By.TAG_NAME, value='a') - href = link.get_attribute('href') - - # Record the retailer's data. - obs = { - 'address': address, - 'details_url': href, - 'business_legal_name': legal_name, - 'business_dba_name': name, - 'business_phone': parts[-1], - 'license_status': parts[0], - 'license_type': parts[1], - 'premise_street_address': address_parts[0].strip(), - 'premise_city': address_parts[1].strip(), - 'premise_zip_code': address_parts[-1].replace('AZ ', '').strip(), - } - data.append(obs) + for index, el in enumerate(els): + data.append(get_license_data_from_html(index, el)) # Standardize the retailer data. retailers = pd.DataFrame(data) @@ -181,30 +204,24 @@ def get_licenses_az( container = driver.find_element(by=By.CLASS_NAME, value='slds-container_center') sleep(4) - # Get the `business_email`. + # Get links. links = container.find_elements(by=By.TAG_NAME, value='a') - for link in links: - href = link.get_attribute('href') - if href is None: continue - if href.startswith('mailto'): - business_email = href.replace('mailto:', '') - col = retailers.columns.get_loc('business_email') - retailers.iat[index, col] = business_email - break - # Get the `license_number` - for link in links: - href = link.get_attribute('href') - if href is None: continue - if href.startswith('https://azdhs-licensing'): - col = retailers.columns.get_loc('license_number') - retailers.iat[index, col] = link.text - break + # Get the `business_email`. + business_email = get_value_from_links(links, 'mailto:') + col = retailers.columns.get_loc('business_email') + retailers.iat[index, col] = business_email + + # Get the `license_number`. + license_number = get_value_from_links(links, 'https://azdhs-licensing') + col = retailers.columns.get_loc('license_number') + retailers.iat[index, col] = license_number # Get the `premise_latitude` and `premise_longitude`. for link in links: href = link.get_attribute('href') - if href is None: continue + if href is None: + continue if href.startswith('https://maps.google.com/'): coords = href.split('=')[1].split('&')[0].split(',') lat_col = retailers.columns.get_loc('premise_latitude') @@ -213,35 +230,45 @@ def get_licenses_az( retailers.iat[index, long_col] = float(coords[1]) break + # FIXME: Scroll down to the bottom of the page. + driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', container) + sleep(1) + # Get the `issue_date`. key = 'License Effective' - el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text") + el = container.find_element('xpath', f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text") col = retailers.columns.get_loc('issue_date') retailers.iat[index, col] = el.text # Get the `expiration_date`. key = 'License Expires' - el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text") + el = container.find_element('xpath', f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text") col = retailers.columns.get_loc('expiration_date') retailers.iat[index, col] = el.text # Get the `business_owner_name`. key = 'Owner / License' - el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text") + el = container.find_element('xpath', f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text") col = retailers.columns.get_loc('expiration_date') retailers.iat[index, col] = el.text # Get the `license_designation` ("Services"). key = 'Services' - el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-rich-text") - col = retailers.columns.get_loc('license_designation') - retailers.iat[index, col] = el.text + try: + el = container.find_element('xpath', f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-rich-text") + col = retailers.columns.get_loc('license_designation') + retailers.iat[index, col] = el.text + except: + pass # Create entries for cultivations. cultivator = retailers.iloc[index].copy() key = 'Offsite Cultivation Address' - el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text") - address = el.text + try: + el = container.find_element('xpath', f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text") + address = el.text + except: + address = None if address: parts = address.split(',') cultivator['address'] = address @@ -249,13 +276,17 @@ def get_licenses_az( cultivator['premise_city'] = parts[1].strip() cultivator['premise_zip_code'] = parts[-1].replace(STATE, '').strip() cultivator['license_type'] = 'Offsite Cultivation' - cultivators.append(cultivator, ignore_index=True) + # cultivators.append(cultivator, ignore_index=True) + cultivators.loc[len(cultivators)] = cultivator # Create entries for manufacturers. manufacturer = retailers.iloc[index].copy() key = 'Manufacture Address' - el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text") - address = el.text + try: + el = container.find_element('xpath', f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text") + address = el.text + except: + address = None if address: parts = address.split(',') manufacturer['address'] = address @@ -263,22 +294,28 @@ def get_licenses_az( manufacturer['premise_city'] = parts[1].strip() manufacturer['premise_zip_code'] = parts[-1].replace(STATE, '').strip() manufacturer['license_type'] = 'Offsite Cultivation' - manufacturers.append(manufacturer, ignore_index=True) + # manufacturers.append(manufacturer, ignore_index=True) + manufacturers.loc[len(manufacturers)] = manufacturer # End the browser session. - service.stop() - retailers.drop(column=['address', 'details_url'], inplace=True) + try: + driver.close() + except: + pass + + # Drop unnecessary columns. + retailers.drop(columns=['address', 'details_url'], inplace=True) # Lookup counties by zip code. - retailers['premise_county'] = retailers['premise_zip_code'].apply(county_from_zip) - cultivators['premise_county'] = cultivators['premise_zip_code'].apply(county_from_zip) - manufacturers['premise_county'] = manufacturers['premise_zip_code'].apply(county_from_zip) + retailers['premise_county'] = retailers['premise_zip_code'].apply(get_county_from_zip) + cultivators['premise_county'] = cultivators['premise_zip_code'].apply(get_county_from_zip) + manufacturers['premise_county'] = manufacturers['premise_zip_code'].apply(get_county_from_zip) - # Setup geocoding - config = dotenv_values(env_file) - api_key = config['GOOGLE_MAPS_API_KEY'] - drop_cols = ['state', 'state_name', 'county', 'address', 'formatted_address'] - gis_cols = {'latitude': 'premise_latitude', 'longitude': 'premise_longitude'} + # TODO: Setup geocoding + # config = dotenv_values(env_file) + # api_key = config['GOOGLE_MAPS_API_KEY'] + # drop_cols = ['state', 'state_name', 'county', 'address', 'formatted_address'] + # gis_cols = {'latitude': 'premise_latitude', 'longitude': 'premise_longitude'} # # Geocode cultivators. # cultivators = geocode_addresses(cultivators, api_key=api_key, address_field='address') @@ -299,20 +336,24 @@ def get_licenses_az( timestamp = datetime.now().isoformat() licenses['data_refreshed_date'] = timestamp retailers['data_refreshed_date'] = timestamp - # cultivators['data_refreshed_date'] = timestamp - # manufacturers['data_refreshed_date'] = timestamp + cultivators['data_refreshed_date'] = timestamp + manufacturers['data_refreshed_date'] = timestamp # Save and return the data. if data_dir is not None: - timestamp = timestamp[:19].replace(':', '-') - licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) - retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) - # cultivators.to_csv(f'{data_dir}/cultivators-{STATE.lower()}-{timestamp}.csv', index=False) - # manufacturers.to_csv(f'{data_dir}/manufacturers-{STATE.lower()}-{timestamp}.csv', index=False) + date = timestamp[:10] + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{date}.csv', index=False) + cultivators.to_csv(f'{data_dir}/cultivators-{STATE.lower()}-{date}.csv', index=False) + manufacturers.to_csv(f'{data_dir}/manufacturers-{STATE.lower()}-{date}.csv', index=False) + + # Return the licenses. return licenses # === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. @@ -330,4 +371,3 @@ if __name__ == '__main__': data_dir = args.get('d', args.get('data_dir')) env_file = args.get('env_file') data = get_licenses_az(data_dir, env_file=env_file) - diff --git a/algorithms/get_licenses_ca.py b/algorithms/get_licenses_ca.py index 92d8dcb1867cb15838c8a1766e99adbb12121ae2..3ca65f624e9da5bbcda8c97824a9e532d2deba65 100644 --- a/algorithms/get_licenses_ca.py +++ b/algorithms/get_licenses_ca.py @@ -6,7 +6,7 @@ Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/16/2022 -Updated: 9/27/2022 +Updated: 8/17/2023 License: Description: @@ -90,10 +90,14 @@ def get_licenses_ca( # Save and return the data. if data_dir is not None: if not os.path.exists(data_dir): os.makedirs(data_dir) - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - license_data.to_csv(f'{data_dir}/licenses-ca-{timestamp}.csv', index=False) + date = datetime.now().strftime('%Y-%m-%d') + license_data.to_csv(f'{data_dir}/licenses-ca-{date}.csv', index=False) + license_data.to_csv(f'{data_dir}/licenses-ca-latest.csv', index=False) return license_data + +# === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_co.py b/algorithms/get_licenses_co.py index d54babcb5c229672f83b8149c49a2a623502ff37..072e875b9c15e2ed603375c1c1c53c5bafba247d 100644 --- a/algorithms/get_licenses_co.py +++ b/algorithms/get_licenses_co.py @@ -6,7 +6,7 @@ Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/4/2022 +Updated: 9/20/2023 License: Description: @@ -36,7 +36,7 @@ import requests # Specify where your data lives. DATA_DIR = '../data/co' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'CO' @@ -151,8 +151,8 @@ def get_licenses_co( config = dotenv_values(env_file) api_key = config['GOOGLE_MAPS_API_KEY'] cols = ['business_dba_name', 'premise_city', 'premise_state', 'premise_zip_code'] - retailers = licenses.loc[licenses['license_type'] == 'Stores'] - retailers['query'] = retailers[cols].apply( + retailers = licenses.loc[licenses['license_type'] == 'Stores'].copy() + retailers['query'] = retailers.loc[:, cols].apply( lambda row: ', '.join(row.values.astype(str)), axis=1, ) @@ -192,16 +192,33 @@ def get_licenses_co( # Clean-up after getting GIS data. retailers.drop(columns=['query'], inplace=True) + # TODO: Merge retailer fields with licenses. + new_fields = [ + 'license_number', + 'premise_street_address', + 'premise_county', + 'premise_latitude', + 'premise_longitude', + 'business_website', + 'business_phone' + ] + licenses = pd.merge(licenses, retailers[new_fields], how='left', on='license_number') + licenses.loc[licenses['business_phone_y'].notna(), 'business_phone_x'] = licenses['business_phone_y'] + licenses.drop(columns=['business_phone_y'], inplace=True) + licenses.rename(columns={'business_phone_x': 'business_phone'}, inplace=True) + # Save and return the data. if data_dir is not None: if not os.path.exists(data_dir): os.makedirs(data_dir) timestamp = datetime.now().isoformat()[:19].replace(':', '-') licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) return licenses # === Test === +# [✓] Tested: 2023-09-20 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_ct.py b/algorithms/get_licenses_ct.py index 9a2cb48c5398e0c2e989b2bc8d24acbbf7d8be59..fb4c1eb7eb17b9dfbeb94143b0ef6e01e287e632 100644 --- a/algorithms/get_licenses_ct.py +++ b/algorithms/get_licenses_ct.py @@ -6,7 +6,7 @@ Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/3/2022 +Updated: 8/17/2023 License: Description: @@ -34,7 +34,7 @@ import requests # Specify where your data lives. DATA_DIR = '../data/ct' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'CT' @@ -133,17 +133,23 @@ def get_licenses_ct( retailers.rename(columns=gis_cols, inplace=True) # Get the refreshed date. - retailers['data_refreshed_date'] = datetime.now().isoformat() + timestamp = datetime.now().isoformat() + retailers['data_refreshed_date'] = timestamp - # Save and return the data. + # Save the data. if data_dir is not None: if not os.path.exists(data_dir): os.makedirs(data_dir) - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) + date = timestamp[:10] + retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{date}.csv', index=False) + retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + + # Return the licenses. return retailers # === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_de.py b/algorithms/get_licenses_de.py new file mode 100644 index 0000000000000000000000000000000000000000..172e1ba23335712a9bde244384b2963c0661387b --- /dev/null +++ b/algorithms/get_licenses_de.py @@ -0,0 +1,182 @@ +""" +Cannabis Licenses | Get Delaware Licenses +Copyright (c) 2023 Cannlytics + +Authors: + Keegan Skeate + Candace O'Sullivan-Sutherland +Created: 4/25/2023 +Updated: 8/13/2023 +License: + +Description: + + Collect Delaware cannabis license data. + +Data Source: + + - Delaware Health Care Commission + URL: + +""" +# Standard imports: +from datetime import datetime +import os +from typing import Optional + +# External imports: +from bs4 import BeautifulSoup +from cannlytics.data.gis import geocode_addresses +from dotenv import dotenv_values +import pandas as pd +import requests + + +# Specify where your data lives. +DATA_DIR = '../data/de' +ENV_FILE = '../../../.env' + +# Specify state-specific constants. +STATE = 'DE' +DELAWARE = { + 'licensing_authority_id': 'DHCC', + 'licensing_authority': 'Delaware Health Care Commission', + 'licenses_url': 'https://dhss.delaware.gov/dhss/dph/hsp/medmarcc.html', +} + + +def get_gis_data(df: pd.DataFrame, api_key: str) -> pd.DataFrame: + """Get GIS data.""" + drop_cols = ['state', 'state_name', 'address', 'formatted_address'] + rename_cols = { + 'county': 'premise_county', + 'latitude': 'premise_latitude', + 'longitude': 'premise_longitude' + } + df = geocode_addresses(df, api_key=api_key, address_field='address') + get_city = lambda x: x.split(', ')[1].split(',')[0] if STATE in str(x) else x + df['premise_city'] = df['formatted_address'].apply(get_city) + df.drop(columns=drop_cols, inplace=True) + return df.rename(columns=rename_cols) + + +def get_licenses_de( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ): + """Get Delaware cannabis license data.""" + + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config.get('GOOGLE_MAPS_API_KEY') + if google_maps_api_key is None: + print('Proceeding without `GOOGLE_MAPS_API_KEY`.') + + # Get the license webpage. + url = DELAWARE['licenses_url'] + response = requests.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + + # Get the licenses table. + table = soup.find('table') + + # Extract the license names. + license_names = [x.text for x in table.find_all('strong') + table.find_all('b')] + license_names = [x for x in license_names if x != 'Additional Links'] + + # Extract the license websites. + websites = [x.text for x in table.find_all('a') if x] + websites = [x for x in websites if x.startswith('http')] + + # Get address and phone number. + pars = table.find_all('p') + addresses, phone_numbers = [], [] + for par in pars: + + # Identify the company name. + names = [x.text for x in par.find_all('strong') + par.find_all('b')] + if not names: + continue + + # Iterate over all companies. + for name in names: + + # Get the lines. + lines = par.text.split(name)[-1].split('http')[0].split('\t\t\t\t\t\t') + lines = [x.replace('\r', '').replace('\n', '') for x in lines[1:]] + + # Get the phone number. + phone_number = lines[-1] + phone_numbers.append(phone_number) + + # Get the address. + address = ' '.join(lines[:-1]) + addresses.append(address) + + # Compile the license data. + data = pd.DataFrame({ + 'business_legal_name': license_names, + 'business_website': websites, + 'address': addresses, + 'phone_number': phone_numbers, + }) + + # Augment with GIS data. + if google_maps_api_key: + data = get_gis_data(data, google_maps_api_key) + + # Standardize the licenses. + data = data.assign( + id=data.index.astype(str), + business_dba_name=data['business_legal_name'], + licensing_authority_id=DELAWARE['licensing_authority_id'], + licensing_authority=DELAWARE['licensing_authority'], + premise_state=STATE, + license_status_date=None, + license_type='Commercial - Retailer', + license_term=None, + issue_date=None, + expiration_date=None, + business_structure=None, + activity=None, + parcel_number=None, + business_image_url=None, + ) + + # Define metadata. + data['data_refreshed_date'] = datetime.now().isoformat() + + # Sort the columns in alphabetical order + data.sort_index(axis=1, inplace=True) + + # Save all of the licenses. + if data_dir is not None: + if not os.path.exists(data_dir): + os.makedirs(data_dir) + date = datetime.now().isoformat()[:10] + data.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + data.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + + # Return the licenses. + return data + + +# === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate +if __name__ == '__main__': + + # Support command line usage. + import argparse + try: + arg_parser = argparse.ArgumentParser() + arg_parser.add_argument('--d', dest='data_dir', type=str) + arg_parser.add_argument('--data_dir', dest='data_dir', type=str) + arg_parser.add_argument('--env', dest='env_file', type=str) + args = arg_parser.parse_args() + except SystemExit: + args = {'d': DATA_DIR, 'env_file': ENV_FILE} + + # Get licenses, saving them to the specified directory. + data_dir = args.get('d', args.get('data_dir')) + env_file = args.get('env_file') + data = get_licenses_de(data_dir, env_file=env_file) diff --git a/algorithms/get_licenses_fl.py b/algorithms/get_licenses_fl.py new file mode 100644 index 0000000000000000000000000000000000000000..916503aa5771fff556ce85ed927d44059e4192c7 --- /dev/null +++ b/algorithms/get_licenses_fl.py @@ -0,0 +1,292 @@ +""" +Florida cannabis licenses and lab results +Copyright (c) 2023 Cannlytics + +Authors: + Keegan Skeate + Candace O'Sullivan-Sutherland +Created: 5/18/2023 +Updated: 8/14/2023 +License: + +Description: + + Archive Florida cannabis license data. + +Data Sources: + + - [Florida Labs](https://knowthefactsmmj.com/cmtl/) + - [Florida Licenses](https://knowthefactsmmj.com/mmtc/) + +Resources: + + - 'https://www.reddit.com/r/FLMedicalTrees/search/?q=COA' + - https://www.reddit.com/r/FLMedicalTrees/comments/1272per/anyone_have_batch_s_they_can_share_for_our/ + - https://www.reddit.com/r/FLMedicalTrees/comments/vdnpqf/coa_accumulation/ + +""" +# Standard imports: +from datetime import datetime +import os +from typing import Optional + +# External imports: +from bs4 import BeautifulSoup +from cannlytics.data.gis import geocode_addresses +from dotenv import dotenv_values +import pandas as pd +import requests + + +# Specify state-specific constants. +STATE = 'FL' +FLORIDA = { + 'licensing_authority_id': 'OMMU', + 'licensing_authority': 'Florida Office of Medical Marijuana Use', + 'licenses_url': 'https://knowthefactsmmj.com/mmtc/', + 'labs_url': 'https://knowthefactsmmj.com/cmtl/', + 'columns': { + 'Name': 'business_dba_name', + 'Phone': 'business_phone', + 'Email': 'business_email', + 'Authorization Status': 'license_status', + 'License Number': 'license_number', + }, + 'labs_columns': { + 'Name': 'business_dba_name', + 'Phone': 'business_phone', + 'Email': 'business_email', + 'Address': 'address', + 'Date Certified': 'issue_date', + } +} + + +#----------------------------------------------------------------------- +# Get Florida labs. +#----------------------------------------------------------------------- + +def get_labs_fl( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ) -> pd.DataFrame: + """Get labs in Florida.""" + + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config.get('GOOGLE_MAPS_API_KEY') + if google_maps_api_key is None: + print('Proceeding without `GOOGLE_MAPS_API_KEY`.') + + # Get the licenses URL. + url = FLORIDA['labs_url'] + response = requests.get(url) + if response.status_code != 200: + print(f"Request failed with status {response.status_code}") + + # Get the table data. + soup = BeautifulSoup(response.content, 'html.parser') + table = soup.find('table') + rows = table.find_all('tr')[1:] + columns = FLORIDA['labs_columns'] + observations = [] + for row in rows: + cells = row.find_all('td') + cells = [x.text.replace('\n', ' ').strip() for x in cells] + observations.append(cells) + + # Convert the list of rows into a DataFrame. + df = pd.DataFrame(observations) + df.columns = list(columns.values()) + + # Geocode licenses. + if google_maps_api_key is not None: + df = geocode_addresses( + df, + api_key=google_maps_api_key, + address_field='address', + ) + df.rename(columns={ + # 'county': 'premise_county', + 'latitude': 'premise_latitude', + 'longitude': 'premise_longitude' + }, inplace=True) + parts = df['formatted_address'].str.split(',', n=3, expand=True) + df['premise_street'] = parts[0] + df['premise_city'] = parts[1] + df['premise_state'] = STATE + df['premise_zip_code'] = parts[2].str.replace(STATE, '').str.strip() + drop_cols = ['address', 'formatted_address', 'county', 'state', 'state_name'] + df.drop(columns=drop_cols, inplace=True) + + # Standardize the licenses data. + df = df.assign( + business_legal_name=df['business_dba_name'], + licensing_authority_id=FLORIDA['licensing_authority_id'], + licensing_authority=FLORIDA['licensing_authority'], + business_structure=None, + business_owner_name=None, + parcel_number=None, + expiration_date=None, + business_image_url=None, + business_website=None, + license_status_date=None, + license_type='Lab', + license_designation=None, + activity=None, + ) + + # Set metadata. + df['data_refreshed_date'] = datetime.now().isoformat() + + # Save the data. + if data_dir is not None: + if not os.path.exists(data_dir): os.makedirs(data_dir) + df.to_csv(f'{data_dir}/labs-{STATE.lower()}-latest.csv', index=False) + + # Return the data. + return df + + +#----------------------------------------------------------------------- +# Get Florida retailers. +#----------------------------------------------------------------------- + +def get_retailers_fl( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ) -> pd.DataFrame: + """Get retailers in Florida.""" + + # Get the licenses URL. + url = FLORIDA['licenses_url'] + response = requests.get(url) + if response.status_code != 200: + print(f"Request failed with status {response.status_code}") + + # TODO: Get the retailers from each page! + + # Geocode licenses. + if google_maps_api_key is not None: + df = geocode_addresses( + df, + api_key=google_maps_api_key, + address_field='address', + ) + # FIXME: Would be ideal to also get the county. + df['premise_county'] = None + df.rename(columns={ + # 'county': 'premise_county', + 'latitude': 'premise_latitude', + 'longitude': 'premise_longitude' + }, inplace=True) + parts = df['formatted_address'].str.split(',', n=3, expand=True) + df['premise_street'] = parts[0] + df['premise_city'] = parts[1] + df['premise_state'] = STATE + df['premise_zip_code'] = parts[2].str.replace(STATE, '').str.strip() + drop_cols = ['address', 'formatted_address'] + df.drop(columns=drop_cols, inplace=True) + + raise NotImplementedError + + +#----------------------------------------------------------------------- +# Get Florida licenses. +#----------------------------------------------------------------------- + +def get_licenses_fl( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ) -> pd.DataFrame: + """Get licenses in Florida.""" + + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config.get('GOOGLE_MAPS_API_KEY') + if google_maps_api_key is None: + print('Proceeding without `GOOGLE_MAPS_API_KEY`.') + + # Get the licenses URL. + url = FLORIDA['licenses_url'] + response = requests.get(url) + if response.status_code != 200: + print(f"Request failed with status {response.status_code}") + + # Get the table data. + soup = BeautifulSoup(response.content, 'html.parser') + table = soup.find('table') + cells = table.text.split('\n') + cells = [x for x in cells if x] + columns = FLORIDA['columns'] + rows = cells[len(columns):] + rows = [rows[i:i+len(columns)] for i in range(0, len(rows), len(columns))] + + # Convert the list of rows into a DataFrame. + df = pd.DataFrame(rows) + df.columns = list(columns.values()) + + # Get the business website and license URLs from each row. + business_websites, license_urls = [], [] + table_rows = table.find_all('tr')[1:] + for row in table_rows: + columns = row.find_all('td') + business_link = columns[0].find('a') + business_websites.append(business_link['href'] if business_link else None) + license_link = columns[-1].find('a') + license_urls.append(license_link['href'] if license_link else None) + df['business_website'] = business_websites + df['license_url'] = license_urls + + # TODO: Get issue date from the license PDF. + # (Will need to apply OCR to get a PDF first.) + df['issue_date'] = None + + # TODO: Get the business legal name from the license PDF. + df['business_legal_name'] = df['business_dba_name'] + + # Standardize the licenses data. + df = df.assign( + licensing_authority_id=FLORIDA['licensing_authority_id'], + licensing_authority=FLORIDA['licensing_authority'], + business_structure=None, + business_owner_name=None, + parcel_number=None, + expiration_date=None, + business_image_url=None, + business_website=None, + license_status='Active', + license_status_date=None, + license_type='Medical - Retailer', + license_designation=None, + activity=None, + ) + + # Set metadata. + df['data_refreshed_date'] = datetime.now().isoformat() + + # Save the data. + if data_dir is not None: + if not os.path.exists(data_dir): os.makedirs(data_dir) + df.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + + # Return the data. + return df + + +# === Tests === +# [✓] Tested: 2023-08-14 by Keegan Skeate +if __name__ == '__main__': + + # Specify where your data lives. + data_dir = '../data/fl' + env_file = '../../../.env' + + # [✓] TEST: Get Florida labs. + labs = get_labs_fl(data_dir=data_dir, env_file=env_file) + + # [ ] TEST: Get Florida retailers. + + + # [✓] TEST: Get Florida licenses. + licenses = get_licenses_fl(data_dir=data_dir, env_file=env_file) diff --git a/algorithms/get_licenses_il.py b/algorithms/get_licenses_il.py index fbb2a4f8a14945253c1d4b7f04642e2002c7987d..d083a6d45407701fefca5216f45f7a3695a7a914 100644 --- a/algorithms/get_licenses_il.py +++ b/algorithms/get_licenses_il.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get Illinois Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/3/2022 +Updated: 8/13/2023 License: Description: @@ -35,7 +35,7 @@ import requests # Specify where your data lives. DATA_DIR = '../data/il' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'IL' @@ -43,7 +43,7 @@ ILLINOIS = { 'licensing_authority_id': 'IDFPR', 'licensing_authority': 'Illinois Department of Financial and Professional Regulation', 'retailers': { - 'url': 'https://www.idfpr.com/LicenseLookup/AdultUseDispensaries.pdf', + 'url': 'https://idfpr.illinois.gov/content/dam/soi/en/web/idfpr/licenselookup/adultusedispensaries.pdf', 'columns': [ 'business_legal_name', 'business_dba_name', @@ -53,6 +53,8 @@ ILLINOIS = { 'license_number', ], }, + # Alt: https://idfpr.illinois.gov/content/dam/soi/en/web/idfpr/forms/auc/2022-10-11-conditional-licenses-list.pdf + # Medical: https://idfpr.illinois.gov/content/dam/soi/en/web/idfpr/forms/mc/listoflicenseddispensaries.pdf } @@ -89,6 +91,7 @@ def get_licenses_il( table_data += table # Standardize the data. + # rows = [[x for x in row if x] for row in table_data] licensee_columns = ILLINOIS['retailers']['columns'] retailers = pd.DataFrame(table_data, columns=licensee_columns) retailers = retailers.assign( @@ -122,8 +125,9 @@ def get_licenses_il( # Separate address into 'street', 'city', 'state', 'zip_code', 'phone_number'. streets, cities, states, zip_codes, phone_numbers = [], [], [], [], [] - for index, row in retailers.iterrows(): - parts = row.address.split(' \n') + for _, row in retailers.iterrows(): + parts = row.address.split('\n') + parts = [part.strip() for part in parts] streets.append(parts[0]) phone_numbers.append(parts[-1]) locales = parts[1] @@ -171,10 +175,13 @@ def get_licenses_il( if data_dir is not None: timestamp = datetime.now().isoformat()[:19].replace(':', '-') retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) + retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) + retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) return retailers # === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_ma.py b/algorithms/get_licenses_ma.py index 6d71672305226fa2d3e0bdb45cbd3be58313a294..681b8797d896416741de4867d09c12b2f15b42cb 100644 --- a/algorithms/get_licenses_ma.py +++ b/algorithms/get_licenses_ma.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get Massachusetts Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/7/2022 +Updated: 9/19/2023 License: Description: @@ -25,7 +25,8 @@ import os from typing import Optional # External imports. -from cannlytics.data.opendata import OpenData +from cannlytics.data import OpenData +from cannlytics.utils import snake_case # Specify where your data lives. @@ -38,45 +39,71 @@ MASSACHUSETTS = { 'licensing_authority': 'Massachusetts Cannabis Control Commission', 'licenses': { 'columns': { - 'license_number': 'license_number', - 'business_name': 'business_legal_name', - 'establishment_address_1': 'premise_street_address', - 'establishment_address_2': 'premise_street_address_2', + 'mailing_address_1': 'mailing_address_1', + 'zip': 'premise_zip_code', + 'ee_priority_number_from_account': 'ee_priority_number_from_account', 'establishment_city': 'premise_city', - 'establishment_zipcode': 'premise_zip_code', - 'county': 'premise_county', - 'license_type': 'license_type', - 'application_status': 'license_status', - 'lic_status': 'license_term', - 'approved_license_type': 'license_designation', - 'commence_operations_date': 'license_status_date', - 'massachusetts_business': 'id', - 'dba_name': 'business_dba_name', - 'establishment_activities': 'activity', - 'cccupdatedate': 'data_refreshed_date', - 'establishment_state': 'premise_state', + 'rmd_priority_number_from_account': 'rmd_priority_number_from_account', + 'cultivation_environment': 'cultivation_environment', + 'application_classification_split_2': 'application_classification_split_2', + 'mailing_city': 'mailing_city', 'latitude': 'premise_latitude', + 'ee_priority_number_from_application': 'ee_priority_number_from_application', + 'business_address_2': 'business_address_2', + 'establishment_zipcode': 'establishment_zipcode', + 'submitted_date': 'submitted_date', + 'county_lat': 'county_lat', + 'mailing_address_2': 'mailing_address_2', + 'approved_license_type': 'approved_license_type', 'longitude': 'premise_longitude', - }, - 'drop': [ - 'square_footage_establishment', - 'cooperative_total_canopy', - 'cooperative_cultivation_environment', - 'establishment_cultivation_environment', - 'abutters_count', - 'is_abutters_notified', - 'business_zipcode', - 'dph_rmd_number', - 'geocoded_county', - 'geocoded_address', - 'name_of_rmd', - 'priority_applicant_type', - 'rmd_priority_certification', - 'dba_registration_city', - 'county_lat', - 'county_long', - ] - }, + 'license_type': 'license_type', + 'application_number': 'application_number', + 'first_compliance_review_date': 'first_compliance_review_date', + 'establishment_address_2': 'establishment_address_2', + 'cccupdatedate': 'cccupdatedate', + 'license_number': 'license_number', + 'business_name': 'business_legal_name', + 'business_state': 'business_state', + 'lic_fee_amount': 'lic_fee_amount', + 'region': 'region', + 'business_city': 'business_city', + 'fee_waiver_ee_or_se_number': 'fee_waiver_ee_or_se_number', + 'geocoded_county': 'geocoded_county', + 'business_zipcode': 'business_zipcode', + 'application_approved_date': 'application_approved_date', + 'town': 'town', + 'cultivation_tier': 'cultivation_tier', + 'application_classification': 'application_classification', + 'application_status': 'application_status', + 'ein_tin': 'ein_tin', + 'priority': 'priority', + 'dbe': 'dbe', + 'rmd_priority_status': 'rmd_priority_status', + 'lic_status': 'license_status', + 'lic_fee_payment_submitted_date': 'lic_fee_payment_submitted_date', + 'establishment_state': 'establishment_state', + 'business_address_1': 'business_address_1', + 'ee_priority_status': 'ee_priority_status', + 'cnb_deemed_complete_date': 'cnb_deemed_complete_date', + 'mailing_zipcode': 'mailing_zipcode', + 'lic_expiration_date': 'expiration_date', + 'commence_operations_date': 'commence_operations_date', + 'establishment_county': 'establishment_county', + 'pmt_amount': 'pmt_amount', + 'fee_waiver_request': 'fee_waiver_request', + 'lic_start_date': 'lic_start_date', + 'county': 'premise_county', + 'application_classification_split_1': 'application_classification_split_1', + 'establishment_address': 'establishment_address', + 'county_long': 'county_long', + 'mailing_state': 'mailing_state', + 'approved_license_stages': 'approved_license_stages', + 'application_created_date': 'issue_date', + 'rmd_priority_number_from_application': 'rmd_priority_number_from_application', + 'geocoded_address': 'geocoded_address', + 'cnb_dt_of_final_licensure': 'cnb_dt_of_final_licensure', + } + } } @@ -90,45 +117,45 @@ def get_licenses_ma( ccc = OpenData() licenses = ccc.get_licensees('approved') + # Standardize the fields. + columns = MASSACHUSETTS['licenses']['columns'] + licenses.columns = [snake_case(col) for col in licenses.columns] + licenses.rename(columns=columns, inplace=True) + licenses['business_dba_name'] = licenses['business_legal_name'] + + # Remove duplicates. + licenses.drop_duplicates(subset=['business_legal_name'], inplace=True) + # Standardize the licenses data. - constants = MASSACHUSETTS['licenses'] - licenses.drop(columns=constants['drop'], inplace=True) - licenses.rename(columns=constants['columns'], inplace=True) licenses = licenses.assign( + premise_state=STATE, licensing_authority_id=MASSACHUSETTS['licensing_authority_id'], licensing_authority=MASSACHUSETTS['licensing_authority'], + # business_dba_name=licenses['business_legal_name'], business_structure=None, business_email=None, business_owner_name=None, parcel_number=None, - issue_date=None, - expiration_date=None, business_image_url=None, business_website=None, business_phone=None, ) - # Append `premise_street_address_2` to `premise_street_address`. - cols = ['premise_street_address', 'premise_street_address_2'] - licenses['premise_street_address'] = licenses[cols].apply( - lambda x : '{} {}'.format(x[0].strip(), x[1]).replace('nan', '').strip().replace(' ', ' '), - axis=1, - ) - licenses.drop(columns=['premise_street_address_2'], inplace=True) - # Optional: Look-up business websites for each license. # Save and return the data. if data_dir is not None: if not os.path.exists(data_dir): os.makedirs(data_dir) - timestamp = datetime.now().isoformat()[:19].replace(':', '-') + date = datetime.now().strftime('%Y-%m-%d') retailers = licenses.loc[licenses['license_type'].str.contains('Retailer')] - retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) - licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) + retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{date}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) return licenses # === Test === +# [✓] Tested: 2023-09-19 by Keegan Skeate if __name__ == '__main__': # Support command line usage. @@ -142,5 +169,7 @@ if __name__ == '__main__': args = {'d': DATA_DIR} # Get licenses, saving them to the specified directory. + # FIXME: This results in a different number of licenses each time! data_dir = args.get('d', args.get('data_dir')) data = get_licenses_ma(data_dir) + print(len(data)) diff --git a/algorithms/get_licenses_md.py b/algorithms/get_licenses_md.py new file mode 100644 index 0000000000000000000000000000000000000000..96657f8f93c591727e2995f6aabc57241cd42771 --- /dev/null +++ b/algorithms/get_licenses_md.py @@ -0,0 +1,252 @@ +""" +Cannabis Licenses | Get Maryland Licenses +Copyright (c) 2022-2023 Cannlytics + +Authors: + Keegan Skeate + Candace O'Sullivan-Sutherland +Created: 11/29/2022 +Updated: 8/13/2023 +License: + +Description: + + Collect Maryland cannabis license data. + +Data Source: + + - Maryland Medical Cannabis Commission + URL: + +""" +# Standard imports: +from datetime import datetime +import os +import re +from typing import Optional +from urllib.parse import urlparse + +# External imports: +from bs4 import BeautifulSoup +from cannlytics.data.gis import geocode_addresses +from dotenv import dotenv_values +import pandas as pd +import requests + + +# Specify where your data lives. +DATA_DIR = '../data/md' +ENV_FILE = '../../../.env' + +# Specify state-specific constants. +STATE = 'MD' +MARYLAND = { + 'licensing_authority_id': 'MMCC', + 'licensing_authority': 'Maryland Medical Cannabis Commission', + 'licenses_url': 'https://mmcc.maryland.gov/Pages/Dispensaries.aspx', +} + + +def get_gis_data(df, api_key): + """Get GIS data.""" + drop_cols = ['state', 'state_name', 'address', 'formatted_address'] + rename_cols = { + 'county': 'premise_county', + 'latitude': 'premise_latitude', + 'longitude': 'premise_longitude' + } + df = geocode_addresses(df, api_key=api_key, address_field='address') + get_city = lambda x: x.split(', ')[1].split(',')[0] if STATE in str(x) else x + get_street = lambda x: str(x).split(', ')[0] + df['premise_city'] = df['formatted_address'].apply(get_city) + df['premise_street_address'] = df['formatted_address'].apply(get_street) + df.drop(columns=drop_cols, inplace=True) + return df.rename(columns=rename_cols) + + +def get_licenses_md( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ): + """Get Maryland cannabis license data.""" + + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config.get('GOOGLE_MAPS_API_KEY') + if google_maps_api_key is None: + print('Proceeding without `GOOGLE_MAPS_API_KEY`.') + + # Get the license webpage. + url = MARYLAND['licenses_url'] + response = requests.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + + # Extract the license data. + data = [] + for td in soup.find_all('td'): + entry = {} + + # Record license data if there is an image. + img = td.find('img') + if img: + + # TODO: Record the image. + # entry['image'] = img['src'] + + # Record the email and website. + entry['business_website'] = None + links = td.find_all('a') + for link in links: + if 'mailto' in link['href']: + entry['business_email'] = link['href'][7:] + elif 'http' in link['href']: + entry['business_website'] = link['href'] + + # Handle plain text websites. + if entry['business_website'] is None and entry['business_email']: + domain = entry['business_email'].split('@')[1] + entry['business_website'] = 'https://www.' + domain + + # Get the business name. + entry['business_legal_name'] = img['alt'] + if not entry['business_legal_name']: + parsed_url = urlparse(url) + entry['business_legal_name'] = parsed_url.netloc.split('.')[0].title() + + # Hot-fix: Get the business name from the website. + # FIXME: This is sub-perfect. + if entry['business_legal_name'] == 'Mmcc': + website = entry['business_website'] + if 'www' in website: + entry['business_legal_name'] = \ + website \ + .split('www.')[1] \ + .split('.')[0] \ + .title() + else: + entry['business_legal_name'] = \ + website \ + .split('//')[1] \ + .split('.')[0] \ + .title() + + # Find phone numbers in text. + # Note: Uses regular expression to match: xxx-xxx-xxxx + text = td.text.strip() + phone_number_pattern = re.compile(r'\d{3}-\d{3}-\d{4}') + phone_numbers = phone_number_pattern.findall(text) + if phone_numbers: + entry['business_phone'] = phone_numbers[0] + else: + entry['business_phone'] = None + + # Otherwise record just the name and address. + else: + lines = [x.text.replace('\u200b', '') for x in td.contents] + lines = [x for x in lines if x] + if not lines: + continue + entry['business_legal_name'] = lines[0].strip() + + # Get the street address. + address = ', '.join(line.strip() for line in lines[1:]) + address = address.replace('\xa0', ' ') + entry['address'] = address + + # Look for phone number below address. + phone_number_pattern = re.compile(r'\d{3}-\d{3}-\d{4}') + phone_numbers = phone_number_pattern.findall(address) + if phone_numbers: + entry['business_phone'] = phone_numbers[0] + entry['address'] = address.split(phone_numbers[0])[0].strip() + else: + entry['business_phone'] = None + + # Handle missed addresses. + if not entry.get('address'): + address = td.text.split(', MD ')[0] \ + .replace('\u200b', ' ') \ + .replace('\n', ' ') \ + .replace('\xa0', ' ') \ + .replace(' ', ' ') \ + .strip() + zip_code = re.findall(r'MD \b\d{5}\b', td.text) + if zip_code: + zip_code = zip_code[0].split('MD ')[-1] + else: + zip_code = '' + address = f'{address}, MD {zip_code}'.strip() + + # Clean address. + address = address.split('http')[0].strip() + if entry.get('business_phone'): + address = address.split(entry['business_phone'])[0].strip() + if entry.get('business_email'): + address = address.split(entry['business_email'])[0].strip() + entry['address'] = address + + # Add the entry to the data. + data.append(entry) + + # Standardize the license data. + retailers = pd.DataFrame(data) + retailers = retailers.assign( + id=retailers.index, + license_status=None, + business_dba_name=retailers['business_legal_name'], + license_number=None, + licensing_authority_id=MARYLAND['licensing_authority_id'], + licensing_authority=MARYLAND['licensing_authority'], + license_designation='Adult-Use', + premise_state=STATE, + license_status_date=None, + license_term=None, + issue_date=None, + expiration_date=None, + business_owner_name=None, + business_structure=None, + activity=None, + parcel_number=None, + business_image_url=None, + license_type=None, + ) + + # Get GIS data. + if google_maps_api_key: + retailers = get_gis_data(retailers, google_maps_api_key) + + # Define metadata. + retailers['data_refreshed_date'] = datetime.now().isoformat() + + # Save the data. + if data_dir is not None: + if not os.path.exists(data_dir): + os.makedirs(data_dir) + date = datetime.now().isoformat()[:10] + retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{date}.csv', index=False) + retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + + # Return the licenses. + return retailers + + +# === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate +if __name__ == '__main__': + + # Support command line usage. + import argparse + try: + arg_parser = argparse.ArgumentParser() + arg_parser.add_argument('--d', dest='data_dir', type=str) + arg_parser.add_argument('--data_dir', dest='data_dir', type=str) + arg_parser.add_argument('--env', dest='env_file', type=str) + args = arg_parser.parse_args() + except SystemExit: + args = {'d': DATA_DIR, 'env_file': ENV_FILE} + + # Get licenses, saving them to the specified directory. + data_dir = args.get('d', args.get('data_dir')) + env_file = args.get('env_file') + data = get_licenses_md(data_dir, env_file=env_file) diff --git a/algorithms/get_licenses_me.py b/algorithms/get_licenses_me.py index 3d62714d5041864caeaa1ee1834622e941304ddc..08b671573345f72b5b94cf5440596aae8c0b6394 100644 --- a/algorithms/get_licenses_me.py +++ b/algorithms/get_licenses_me.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get Maine Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/7/2022 +Updated: 8/17/2023 License: Description: @@ -18,6 +18,13 @@ Data Source: - Maine Office of Cannabis Policy URL: +# TODO: + + [ ] Priority: Save the retailers in a stand-alone data file. + [ ] Separate the functionality into functions. + [ ] Make the code more robust to errors. + [ ] Make Google Maps API key optional. + """ # Standard imports. from datetime import datetime @@ -34,7 +41,7 @@ import requests # Specify where your data lives. DATA_DIR = '../data/me' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'ME' @@ -68,6 +75,10 @@ def get_licenses_me( ): """Get Maine cannabis license data.""" + # Load the environment variables. + config = dotenv_values(env_file) + api_key = config['GOOGLE_MAPS_API_KEY'] + # Create the necessary directories. file_dir = f'{data_dir}/.datasets' if not os.path.exists(data_dir): os.makedirs(data_dir) @@ -133,14 +144,14 @@ def get_licenses_me( ) # Get the refreshed date. - date = licenses_source_file.split('\\')[-1].split('.')[0].replace(licenses_key, '') - date = date.replace('%20', '') - date = '-'.join([date[:2], date[2:4], date[4:]]) - licenses['data_refreshed_date'] = pd.to_datetime(date).isoformat() + try: + date = licenses_source_file[-15:] + date = date.replace('_', '-').replace('.xlsx', '') + licenses['data_refreshed_date'] = pd.to_datetime(date).isoformat() + except: + licenses['data_refreshed_date'] = datetime.now().isoformat() # Geocode licenses to get `premise_latitude` and `premise_longitude`. - config = dotenv_values(env_file) - api_key = config['GOOGLE_MAPS_API_KEY'] cols = ['premise_city', 'premise_state'] licenses['address'] = licenses[cols].apply( lambda row: ', '.join(row.values.astype(str)), @@ -162,12 +173,17 @@ def get_licenses_me( # Save and return the data. if data_dir is not None: - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) + date = datetime.now().strftime('%Y-%m-%d') + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + # TODO: Save the retailers in a stand-alone data file. + + # Return the licenses. return licenses # === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_mi.py b/algorithms/get_licenses_mi.py index 9e5f5748802bdf7d1af870e74cd973661681c2da..f476c01b3487cdde14ba630347ba73bd8f0ab4d0 100644 --- a/algorithms/get_licenses_mi.py +++ b/algorithms/get_licenses_mi.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get Michigan Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/8/2022 +Updated: 8/17/2023 License: Description: @@ -18,11 +18,16 @@ Data Source: - Michigan Cannabis Regulatory Agency URL: +TODO: + + [ ] Separate the functionality into functions. + [ ] Make the code more robust to errors. + [ ] Make Google Maps API key optional. + """ # Standard imports. from datetime import datetime import os -from time import sleep from typing import Optional # External imports. @@ -38,15 +43,15 @@ from selenium.webdriver.chrome.service import Service from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support.ui import Select -try: - import chromedriver_binary # Adds chromedriver binary to path. -except ImportError: - pass # Otherwise, ChromeDriver should be in your path. +# try: +# import chromedriver_binary # Adds chromedriver binary to path. +# except ImportError: +# pass # Otherwise, ChromeDriver should be in your path. # Specify where your data lives. DATA_DIR = '../data/mi' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'MI' @@ -73,9 +78,8 @@ MICHIGAN = { def wait_for_id_invisible(driver, value, seconds=30): """Wait for a given value to be invisible.""" - WebDriverWait(driver, seconds).until( - EC.invisibility_of_element((By.ID, value)) - ) + el = (By.ID, value) + WebDriverWait(driver, seconds).until(EC.invisibility_of_element(el)) def get_licenses_mi( @@ -84,21 +88,21 @@ def get_licenses_mi( ): """Get Michigan cannabis license data.""" - # Initialize Selenium and specify options. - service = Service() - options = Options() - options.add_argument('--window-size=1920,1200') - - # DEV: Run with the browser open. - options.headless = False - - # PRODUCTION: Run with the browser closed. - # options.add_argument('--headless') - # options.add_argument('--disable-gpu') - # options.add_argument('--no-sandbox') + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config['GOOGLE_MAPS_API_KEY'] - # Initiate a Selenium driver. - driver = webdriver.Chrome(options=options, service=service) + # Initialize Selenium. + try: + service = Service() + options = Options() + options.add_argument('--window-size=1920,1200') + options.add_argument('--headless') + options.add_argument('--disable-gpu') + options.add_argument('--no-sandbox') + driver = webdriver.Chrome(options=options, service=service) + except: + driver = webdriver.Edge() # Load the license page. url = MICHIGAN['licenses_url'] @@ -112,11 +116,11 @@ def get_licenses_mi( text = option.text if text and '--' not in text: license_types.append(text) - + # Restrict certain license types. license_types = license_types[1:-2] - # FIXME: Iterate over license types. + # Iterate over license types to get the data. data = [] columns = list(MICHIGAN['licenses']['columns'].values()) for license_type in license_types: @@ -164,7 +168,10 @@ def get_licenses_mi( # https://aca-prod.accela.com/MIMM/Cap/CapHome.aspx?module=Licenses&TabName=Licenses&TabList=Home%7C0%7CLicenses%7C1%7CAdult_Use%7C2%7CEnforcement%7C3%7CRegistryCards%7C4%7CCurrentTabIndex%7C1 # End the browser session. - service.stop() + try: + service.stop() + except: + pass # Standardize the data. licenses = pd.DataFrame(data) @@ -203,8 +210,6 @@ def get_licenses_mi( ) # Geocode the licenses. - config = dotenv_values(env_file) - google_maps_api_key = config['GOOGLE_MAPS_API_KEY'] licenses = geocode_addresses( licenses, api_key=google_maps_api_key, @@ -229,17 +234,22 @@ def get_licenses_mi( licenses.rename(columns=gis_cols, inplace=True) # Get the refreshed date. - licenses['data_refreshed_date'] = datetime.now().isoformat() + timestamp = datetime.now().isoformat() + licenses['data_refreshed_date'] = timestamp # Save and return the data. if data_dir is not None: if not os.path.exists(data_dir): os.makedirs(data_dir) - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) + date = timestamp[:10] + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + + # Return the licenses. return licenses # === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_mo.py b/algorithms/get_licenses_mo.py new file mode 100644 index 0000000000000000000000000000000000000000..d4cc32a7104e390783d2ceb56e3e007cc6ff80f2 --- /dev/null +++ b/algorithms/get_licenses_mo.py @@ -0,0 +1,257 @@ +""" +Cannabis Licenses | Get Missouri Licenses +Copyright (c) 2023 Cannlytics + +Authors: + Keegan Skeate + Candace O'Sullivan-Sutherland +Created: 4/26/2023 +Updated: 8/13/2023 +License: + +Description: + + Collect Missouri cannabis license data. + +Requirements: + + The script leverages Google Maps to attempt to geocode license + addresses. Ensure that you have a `.env` file with a valid + Google Maps API specified as `GOOGLE_MAPS_API_KEY`. + +Command-line Usage: + + python get_licenses_mo.py --data_dir --env + +Data Source: + + - Missouri Medical Cannabis Licenses + URL: + +""" +# Standard imports: +from datetime import datetime +import os +import re +from typing import Optional + +# External imports: +from bs4 import BeautifulSoup +from cannlytics.data.gis import geocode_addresses +from dotenv import dotenv_values +import numpy as np +import pandas as pd +import requests +import zipcodes + + +# Specify where your data lives. +DATA_DIR = '../data/mo' +ENV_FILE = '../../../.env' + +# Specify state-specific constants. +STATE = 'MO' +MISSOURI = { + 'licensing_authority_id': 'MDHSS', + 'licensing_authority': 'Missouri Department of Health and Senior Services', + 'licenses_url': 'https://health.mo.gov/safety/cannabis/licensed-facilities.php', + 'columns': { + 'Medical': 'medical', + 'Comprehensive': 'adult_use', + 'Approved to Operate': 'license_status', + 'License \nNumber': 'license_number', + 'Entity Name': 'business_legal_name', + 'City': 'premise_city', + 'State': 'premise_state', + 'Postal Code': 'premise_zip_code', + ' Contact \nInformation 1': 'first_name', + 'Contact \nInformation 1': 'first_name', + 'Contact \nInformation 2': 'last_name', + 'Contact \nPhone': 'business_phone' + }, + 'drop': ['first_name', 'last_name'], +} + + +def format_phone_number(x): + """Format phone numbers as ###-###-####.""" + digits = re.sub(r'\D', '', x) + return '{}-{}-{}'.format(digits[:3], digits[3:6], digits[6:]) + + +def get_gis_data(df: pd.DataFrame, api_key: str) -> pd.DataFrame: + """Get GIS data.""" + drop_cols = ['state', 'state_name', 'address', 'formatted_address'] + rename_cols = { + 'county': 'premise_county', + 'latitude': 'premise_latitude', + 'longitude': 'premise_longitude' + } + df = geocode_addresses(df, api_key=api_key, address_field='address') + get_city = lambda x: x.split(', ')[1].split(',')[0] if STATE in str(x) else x + df['premise_city'] = df['formatted_address'].apply(get_city) + df.drop(columns=drop_cols, inplace=True) + return df.rename(columns=rename_cols) + + +def get_licenses_mo( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ): + """Get Missouri cannabis license data.""" + + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config.get('GOOGLE_MAPS_API_KEY') + if google_maps_api_key is None: + print('Proceeding without `GOOGLE_MAPS_API_KEY`.') + + # Create the download directory if it doesn't exist. + download_dir = os.path.join(data_dir, '.datasets') + if not os.path.exists(download_dir): + os.makedirs(download_dir) + + # Get the licenses website content. + url = MISSOURI['licenses_url'] + response = requests.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + + # Find all workbook links on the website. + links = soup.find_all('a') + xlsx_links = [x for x in links if x.get('href').endswith('.xlsx')] + + # Download the files to the download directory. + datafiles = [] + base = 'https://health.mo.gov/safety/cannabis/xls/' + for link in xlsx_links: + file_url = base + link.get('href').split('/')[-1] + file_name = os.path.join(download_dir, os.path.basename(file_url)) + with open(file_name, 'wb') as file: + response = requests.get(file_url) + file.write(response.content) + datafiles.append(file_name) + + # Open each datafile and extract the data. + licenses = [] + for datafile in datafiles: + + # Get the license type from the filename. + license_type = datafile.split('\\')[-1].replace('.xlsx', '') \ + .replace('licensed-', '') \ + .replace('-facilities', '') + + # Open the workbook. + data = pd.read_excel(datafile, skiprows=1) + + # Rename columns. + data.rename(columns=MISSOURI['columns'], inplace=True) + + # Replace non-NaN columns with True and NaN columns with False. + data['license_status'] = data['license_status'].notna() \ + .map({True: 'Active', False: 'Inactive'}) + + # Combine medical / adult_use into `license_designation`. + try: + data['medical'] = data['medical'].notna().map({True: True, False: False}) + data['adult_use'] = data['adult_use'].notna().map({True: True, False: False}) + conditions = [ + (data['medical'] & data['adult_use']), + (data['medical']), + (data['adult_use']) + ] + choices = [ + 'medical and adult-use', + 'medical', + 'adult-use' + ] + data['license_designation'] = np.select(conditions, choices, default=None) + except KeyError: + data['license_designation'] = 'adult-use' + + # Combine owner name columns. + data['business_owner_name'] = data['first_name'].str.cat( + data['last_name'], + sep=' ', + ) + + # Clean the phone numbers. + data['business_phone'] = data['business_phone'].apply(str).apply(format_phone_number) + + # Drop unused columns. + unnamed = [x for x in data.columns if re.match('^Unnamed', x)] + to_drop = MISSOURI['drop'] + unnamed + data.drop(to_drop, axis=1, inplace=True) + + # Augment GIS data. + data['address'] = data['business_legal_name'] + ', ' + data['premise_city'] + ', ' + data['premise_state'] + ' ' + data['premise_zip_code'].astype(str) + data = get_gis_data(data, google_maps_api_key) + + # Get the county. + get_county = lambda x: zipcodes.matching(x)[0]['county'] + data['county'] = data['premise_zip_code'].astype(str).apply(get_county) + + # Standardize the license data. + data = data.assign( + id=data['license_number'].astype(str), + business_dba_name=data['business_legal_name'], + licensing_authority_id=MISSOURI['licensing_authority_id'], + licensing_authority=MISSOURI['licensing_authority'], + premise_state=STATE, + license_status_date=None, + license_type=license_type, + license_term=None, + issue_date=None, + expiration_date=None, + business_structure=None, + activity=None, + parcel_number=None, + business_image_url=None, + ) + + # Define metadata. + data['data_refreshed_date'] = datetime.now().isoformat() + + # Sort the columns in alphabetical order + data.sort_index(axis=1, inplace=True) + + # Save the data. + if data_dir is not None: + if not os.path.exists(data_dir): + os.makedirs(data_dir) + date = datetime.now().isoformat()[:10] + outfile = f'{data_dir}/{license_type}-{STATE.lower()}-{date}.csv' + data.to_csv(outfile, index=False) + + # Record the licenses. + licenses.append(data) + + # Save all of the licenses. + licenses = pd.concat(licenses) + if data_dir is not None: + date = datetime.now().isoformat()[:10] + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + + # Return the licenses. + return licenses + + +# === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate +if __name__ == '__main__': + + # Support command line usage. + import argparse + try: + arg_parser = argparse.ArgumentParser() + arg_parser.add_argument('--d', dest='data_dir', type=str) + arg_parser.add_argument('--data_dir', dest='data_dir', type=str) + arg_parser.add_argument('--env', dest='env_file', type=str) + args = arg_parser.parse_args() + except SystemExit: + args = {'data_dir': DATA_DIR, 'env_file': ENV_FILE} + + # Get licenses, saving them to the specified directory. + data_dir = args.get('d', args.get('data_dir')) + env_file = args.get('env_file') + data = get_licenses_mo(data_dir, env_file=env_file) diff --git a/algorithms/get_licenses_mt.py b/algorithms/get_licenses_mt.py index 346ba8607e6205e6afec16ee5d030d8162f22892..a923dd2d718bc49b08023c9a64a53aad770a41b5 100644 --- a/algorithms/get_licenses_mt.py +++ b/algorithms/get_licenses_mt.py @@ -6,7 +6,7 @@ Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/27/2022 -Updated: 10/5/2022 +Updated: 8/17/2023 License: Description: @@ -35,7 +35,7 @@ import requests # Specify where your data lives. DATA_DIR = '../data/mt' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'MT' @@ -67,9 +67,11 @@ MONTANA = { ] }, 'retailers': { - 'url': 'https://mtrevenue.gov/?mdocs-file=60245', + 'url': 'https://mtrevenue.gov/wp-content/uploads/dlm_uploads/2023/08/Dispensary-8-2023.pdf', 'columns': ['city', 'dba', 'license_type', 'phone'] }, + # FIXME: Add other license types. + # https://mtrevenue.gov/cannabis/#CannabisLicenses 'processors': {'url': 'https://mtrevenue.gov/?mdocs-file=60250'}, 'cultivators': {'url': 'https://mtrevenue.gov/?mdocs-file=60252'}, 'labs': {'url': 'https://mtrevenue.gov/?mdocs-file=60248'}, @@ -248,17 +250,23 @@ def get_licenses_mt( retailers.drop(columns=['query'], inplace=True) # Get the refreshed date. - retailers['data_refreshed_date'] = datetime.now().isoformat() + timestamp = datetime.now().isoformat() + retailers['data_refreshed_date'] = timestamp - # Save and return the data. + # Save the data. if data_dir is not None: if not os.path.exists(data_dir): os.makedirs(data_dir) - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) + date = timestamp[:10] + retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{date}.csv', index=False) + retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + + # Return the data. return retailers # === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_nj.py b/algorithms/get_licenses_nj.py index 3023488cc65df8aff353fb8600bb3d0898fda510..f8ddc80668a3c67c9b18d5c3b3d9b420a9013976 100644 --- a/algorithms/get_licenses_nj.py +++ b/algorithms/get_licenses_nj.py @@ -6,7 +6,7 @@ Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 9/29/2022 +Updated: 8/17/2023 License: Description: @@ -75,6 +75,7 @@ def get_licenses_nj( ) # Standardize the data. + timestamp = datetime.now().isoformat() drop_cols = ['dispensary_location', 'location', 'website'] data.drop(columns=drop_cols, inplace=True) data.rename(columns=NEW_JERSEY['retailers']['columns'], inplace=True) @@ -96,7 +97,7 @@ def get_licenses_nj( data['id'] = None data['license_number'] = None data['license_status'] = None - data['data_refreshed_date'] = datetime.now().isoformat() + data['data_refreshed_date'] = timestamp # Convert certain columns from upper case title case. cols = ['premise_city', 'premise_county', 'premise_street_address'] @@ -106,12 +107,14 @@ def get_licenses_nj( # Save and return the data. if data_dir is not None: if not os.path.exists(data_dir): os.makedirs(data_dir) - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - data.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) + date = timestamp[:10] + data.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + data.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) return data # === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_nm.py b/algorithms/get_licenses_nm.py index 5b7d125b4d60574b089d65f2a50a2fca82822184..42dfd1d58d505909b896ca4545aff4f1dba317ff 100644 --- a/algorithms/get_licenses_nm.py +++ b/algorithms/get_licenses_nm.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get New Mexico Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/6/2022 +Updated: 8/18/2023 License: Description: @@ -18,6 +18,15 @@ Data Source: - New Mexico Regulation and Licensing Department | Cannabis Control Division URL: +TODO: + - [ ] Also collect: + * "Cannabis Manufacturer" + * "Cannabis Producer" + * "Cannabis Producer Microbusiness" + - [ ] Replace `sleep` with `WebDriverWait` where possible. + - [ ] Handle multiple search results for a single address. + - [ ] Ensure geocoding is working correctly. + """ # Standard imports. from datetime import datetime @@ -37,15 +46,11 @@ from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait -try: - import chromedriver_binary # Adds chromedriver binary to path. -except ImportError: - pass # Otherwise, ChromeDriver should be in your path. - +# try: +# import chromedriver_binary # Adds chromedriver binary to path. +# except ImportError: +# pass # Otherwise, ChromeDriver should be in your path. -# Specify where your data lives. -DATA_DIR = '../data/nm' -ENV_FILE = '../.env' # Specify state-specific constants. STATE = 'NM' @@ -59,29 +64,39 @@ NEW_MEXICO = { def get_licenses_nm( data_dir: Optional[str] = None, env_file: Optional[str] = '.env', + verbose: Optional[bool] = True, ): """Get New Mexico cannabis license data.""" + # Load environment variables. + geocode = False + try: + config = dotenv_values(env_file) + api_key = config['GOOGLE_MAPS_API_KEY'] + geocode = True + if verbose: + print('Retrieved Google Maps API key for geocoding addresses.') + except: + print('Proceeding without geocoding. Set `GOOGLE_MAPS_API_KEY` in your `env_file` to enable the geocoding of addresses.') + # Create directories if necessary. if not os.path.exists(data_dir): os.makedirs(data_dir) - # Initialize Selenium and specify options. - service = Service() - options = Options() - options.add_argument('--window-size=1920,1200') - - # DEV: Run with the browser open. - options.headless = False - - # PRODUCTION: Run with the browser closed. - # options.add_argument('--headless') - # options.add_argument('--disable-gpu') - # options.add_argument('--no-sandbox') - - # Initiate a Selenium driver. - driver = webdriver.Chrome(options=options, service=service) + # Initialize Selenium. + try: + service = Service() + options = Options() + options.add_argument('--window-size=1920,1200') + options.add_argument('--headless') + options.add_argument('--disable-gpu') + options.add_argument('--no-sandbox') + driver = webdriver.Chrome(options=options, service=service) + except: + driver = webdriver.Edge() # Load the license page. + if verbose: + print('Driver initialized. Loading license page...') driver.get(NEW_MEXICO['licenses_url']) # FIXME: Wait for the page to load by waiting to detect the image. @@ -90,22 +105,25 @@ def get_licenses_nm( # WebDriverWait(driver, 15).until(EC.presence_of_element_located(el)) # except TimeoutException: # print('Failed to load page within %i seconds.' % (30)) - sleep(5) + sleep(6) - # Get the main content and click "License Type" raido. + # Get the main content and click "License Type" radio. content = driver.find_element(by=By.CLASS_NAME, value='siteforceContentArea') radio = content.find_element(by=By.CLASS_NAME, value='slds-radio--faux') radio.click() - sleep(2) + sleep(3) # Select retailers. # TODO: Also get "Cannabis Manufacturer", "Cannabis Producer", and # "Cannabis Producer Microbusiness". + # FIXME: Handle NoSuchElementException search = content.find_element(by=By.ID, value='comboboxId-40') search.click() choices = content.find_elements(by=By.CLASS_NAME, value='slds-listbox__item') for choice in choices: if choice.text == 'Cannabis Retailer': + if verbose: + print('Searching cannabis retailers...') choice.click() sleep(2) break @@ -120,6 +138,8 @@ def get_licenses_nm( sleep(5) data = [] iterate = True + if verbose: + print('Getting all licenses...') while(iterate): # Get all of the licenses. @@ -138,10 +158,11 @@ def get_licenses_nm( }) # Get the page number and stop at the last page. - # FIXME: This doesn't correctly break! par = content.find_elements(by=By.TAG_NAME, value='p')[-1].text page_number = int(par.split(' ')[2]) total_pages = int(par.split(' ')[-2]) + if verbose: + print('Retrieved licenses from page %i/%i' % (page_number, total_pages)) if page_number == total_pages: iterate = False @@ -149,12 +170,17 @@ def get_licenses_nm( buttons = content.find_elements(by=By.TAG_NAME, value='button') for button in buttons: if button.text == 'Next Page': - button.click() + try: + button.click() + except: + break sleep(5) break # Search for each license name, 1 by 1, to get details. retailers = pd.DataFrame(columns=['business_legal_name']) + if verbose: + print('Getting details for %i licenses...' % len(data)) for i, licensee in enumerate(data): # Skip recorded rows. @@ -162,6 +188,7 @@ def get_licenses_nm( continue # Click the "Business Name" search field. + sleep(2) content = driver.find_element(by=By.CLASS_NAME, value='siteforceContentArea') radio = content.find_elements(by=By.CLASS_NAME, value='slds-radio--faux')[1] radio.click() @@ -176,30 +203,28 @@ def get_licenses_nm( search = content.find_element(by=By.CLASS_NAME, value='vlocity-btn') search.click() - # FIXME: Wait for the table to load. + # Wait for the table to load. + # TODO: Prefer to use WebDriverWait over sleep. # WebDriverWait(content, 5).until(EC.presence_of_element_located((By.CLASS_NAME, 'slds-button_icon'))) - sleep(1.5) + sleep(3) # Click the "Action" button to get to the details page. - # FIXME: There can be multiple search candidates! + # FIXME: There can be multiple search candidates! How to handle this? action = content.find_element(by=By.CLASS_NAME, value='slds-button_icon') try: action.click() except: - continue # FIXME: Formally check if "No record found!". + # TODO: Formally check if "No record found!". + continue - # FIXME: Wait for the details page to load. - el = (By.CLASS_NAME, 'body') - WebDriverWait(driver, 5).until(EC.presence_of_element_located(el)) + # Wait for the details page to load. + # TODO: Prefer to use WebDriverWait over sleep. + # WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CLASS_NAME, 'body'))) + sleep(5) # Get the page page = driver.find_element(by=By.CLASS_NAME, value='body') - # FIXME: Wait for the details to load! - # el = (By.TAG_NAME, 'vlocity_ins-omniscript-step') - # WebDriverWait(page, 5).until(EC.presence_of_element_located(el)) - sleep(1.5) - # Get all of the details! fields = [ 'license_number', @@ -218,7 +243,7 @@ def get_licenses_nm( for j, value in enumerate(values): data[i][fields[j]] = value.text - # Create multiple entries for each address!!! + # Create multiple entries for each address. premises = page.find_elements(by=By.CLASS_NAME, value='block-header') for premise in premises: values = premise.text.split('\n') @@ -226,13 +251,24 @@ def get_licenses_nm( licensee['license_number'] = values[2] retailers = pd.concat([retailers, pd.DataFrame([licensee])]) - # Click the "Back to Search" button. - back_button = page.find_element(by=By.CLASS_NAME, value='vlocity-btn') - back_button.click() + # Scroll to the bottom of the page. + driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") sleep(1) + # Click the "Back to Search" button. + if verbose: + print('%i. Details collected for %s' % (i + 1, licensee['business_legal_name'])) + try: + back_button = page.find_element(by=By.CLASS_NAME, value='vlocity-btn') + back_button.click() + except: + driver.get(NEW_MEXICO['licenses_url']) # FIXME: Hot-fix. + # End the browser session. - service.stop() + try: + driver.close() + except: + pass # Standardize the data, restricting to "Approved" retailers. retailers = retailers.loc[retailers['license_status'] == 'Active'] @@ -258,40 +294,51 @@ def get_licenses_nm( retailers['data_refreshed_date'] = datetime.now().isoformat() # Geocode licenses. - # FIXME: This is not working as intended. Perhaps try `search_for_address`? - config = dotenv_values(env_file) - api_key = config['GOOGLE_MAPS_API_KEY'] - retailers = geocode_addresses(retailers, api_key=api_key, address_field='address') - retailers['premise_street_address'] = retailers['formatted_address'].apply( - lambda x: x.split(',')[0] if STATE in str(x) else x - ) - retailers['premise_city'] = retailers['formatted_address'].apply( - lambda x: x.split(', ')[1].split(',')[0] if STATE in str(x) else x - ) - retailers['premise_zip_code'] = retailers['formatted_address'].apply( - lambda x: x.split(', ')[2].split(',')[0].split(' ')[-1] if STATE in str(x) else x - ) - drop_cols = ['state', 'state_name', 'address', 'formatted_address', - 'details_url'] - gis_cols = { - 'county': 'premise_county', - 'latitude': 'premise_latitude', - 'longitude': 'premise_longitude' - } - retailers.drop(columns=drop_cols, inplace=True) - retailers.rename(columns=gis_cols, inplace=True) + if geocode: + + # FIXME: This is not working as intended. + # Perhaps try `search_for_address`? + retailers = geocode_addresses(retailers, api_key=api_key, address_field='address') + retailers['premise_street_address'] = retailers['formatted_address'].apply( + lambda x: x.split(',')[0] if STATE in str(x) else x + ) + retailers['premise_city'] = retailers['formatted_address'].apply( + lambda x: x.split(', ')[1].split(',')[0] if STATE in str(x) else x + ) + retailers['premise_zip_code'] = retailers['formatted_address'].apply( + lambda x: x.split(', ')[2].split(',')[0].split(' ')[-1] if STATE in str(x) else x + ) + drop_cols = ['state', 'state_name', 'address', 'formatted_address', + 'details_url'] + gis_cols = { + 'county': 'premise_county', + 'latitude': 'premise_latitude', + 'longitude': 'premise_longitude' + } + retailers.drop(columns=drop_cols, inplace=True) + retailers.rename(columns=gis_cols, inplace=True) # Save and return the data. if data_dir is not None: - if not os.path.exists(data_dir): os.makedirs(data_dir) - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) + if not os.path.exists(data_dir): + os.makedirs(data_dir) + date = datetime.now().isoformat()[:10] + retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{date}.csv', index=False) + retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-latest.csv', index=False) + + # Return the licenses. return retailers # === Test === +# [✓] Tested: 2023-08-14 by Keegan Skeate if __name__ == '__main__': + # Specify where your data lives. + DATA_DIR = '../data/nm' + ENV_FILE = '../../../.env' + # Support command line usage. import argparse try: diff --git a/algorithms/get_licenses_nv.py b/algorithms/get_licenses_nv.py index 15f79ec3e0ff748fe4727331a2063df2815a8f27..01fcc83f19ac9d2ce6e65e3a0043635bc05b5252 100644 --- a/algorithms/get_licenses_nv.py +++ b/algorithms/get_licenses_nv.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get Nevada Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 9/29/2022 +Updated: 8/13/2023 License: Description: @@ -34,7 +34,7 @@ import requests # Specify where your data lives. DATA_DIR = '../data/nv' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'NV' @@ -61,6 +61,10 @@ def get_licenses_nv( ): """Get Nevada cannabis license data.""" + # Get the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config['GOOGLE_MAPS_API_KEY'] + # Create the necessary directories. file_dir = f'{data_dir}/.datasets' if not os.path.exists(data_dir): os.makedirs(data_dir) @@ -128,6 +132,7 @@ def get_licenses_nv( if data_dir is not None: timestamp = datetime.now().isoformat()[:19].replace(':', '-') licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) #-------------------------------------------------------------------------- # Get retailer data @@ -142,18 +147,19 @@ def get_licenses_nv( except AttributeError: continue rows = table.find_all('td') - for row in rows: - cells = row.text.split(' – ') - name = cells[0] - street = cells[1] - designation = cells[-1] - retailers.append({ - 'business_legal_name': name, - 'business_dba_name': name, - 'license_designation': designation, - 'premise_city': city, - 'premise_street_address': street, - }) + vector = [x.text for x in rows] + retailer = {} + for cell in vector: + if ' – ' in cell: + parts = cell.split(' – ') + retailer['business_legal_name'] = parts[0] + retailer['business_dba_name'] = parts[0] + retailer['premise_street_address'] = parts[1] + retailer['license_designation'] = parts[-1] + retailer['premise_city'] = city + else: + retailer['delivery'] = cell + retailers.append(retailer) # Standardize the retailers. retailers = pd.DataFrame(retailers) @@ -183,8 +189,6 @@ def get_licenses_nv( retailers['data_refreshed_date'] = datetime.now().isoformat() # Geocode the retailers. - config = dotenv_values(env_file) - google_maps_api_key = config['GOOGLE_MAPS_API_KEY'] cols = ['premise_street_address', 'premise_city', 'premise_state'] retailers['address'] = retailers[cols].apply( lambda row: ', '.join(row.values.astype(str)), @@ -201,7 +205,7 @@ def get_licenses_nv( 'latitude': 'premise_latitude', 'longitude': 'premise_longitude' } - licenses['premise_zip_code'] = licenses['formatted_address'].apply( + retailers['premise_zip_code'] = retailers['formatted_address'].apply( lambda x: x.split(', ')[2].split(',')[0].split(' ')[-1] if STATE in str(x) else x ) retailers.drop(columns=drop_cols, inplace=True) @@ -211,11 +215,14 @@ def get_licenses_nv( if data_dir is not None: timestamp = datetime.now().isoformat()[:19].replace(':', '-') retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) + retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-latest.csv', index=False) # Return all of the data. return pd.concat([licenses, retailers]) +# === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_ny.py b/algorithms/get_licenses_ny.py new file mode 100644 index 0000000000000000000000000000000000000000..37c77fc703ae41ecc26f31b18d533eaa778a220e --- /dev/null +++ b/algorithms/get_licenses_ny.py @@ -0,0 +1,445 @@ +""" +Cannabis Licenses | Get New York Licenses +Copyright (c) 2022-2023 Cannlytics + +Authors: + Keegan Skeate + Candace O'Sullivan-Sutherland +Created: 11/29/2022 +Updated: 9/20/2023 +License: + +Description: + + Collect New York cannabis license data. + +Data Source: + + - New York State Office of Cannabis Management + URL: + +""" +# Standard imports: +from datetime import datetime +import json +import os +from typing import Optional + +# External imports: +from bs4 import BeautifulSoup +from cannlytics.data.gis import geocode_addresses +from dotenv import dotenv_values +import pandas as pd +import pdfplumber +import requests + + +# Specify where your data lives. +DATA_DIR = '../data/ny' +ENV_FILE = '../../../.env' + +# Specify state-specific constants. +STATE = 'NY' +NEW_YORK = { + 'licensing_authority_id': 'OCM', + 'licensing_authority': 'New York State Office of Cannabis Management', + 'cultivators': { + 'source': 'https://cannabis.ny.gov/adult-use-conditional-cultivator', + 'url': 'https://cannabis.ny.gov/list-aucc-licenses', + }, + 'retailers': { + 'source': 'https://cannabis.ny.gov/conditional-adult-use-retail-dispensary', + 'url': 'https://cannabis.ny.gov/caurd-licenses', + }, + 'processors': { + 'source': 'https://cannabis.ny.gov/adult-use-conditional-processor', + 'url': 'https://cannabis.ny.gov/list-aucp-licenses', + }, + 'labs': { + 'source': 'https://cannabis.ny.gov/cannabis-laboratories', + 'url': 'https://cannabis.ny.gov/cannabis-laboratories', + 'limits': 'https://cannabis.ny.gov/laboratory-testing-limits', + 'qc': 'https://cannabis.ny.gov/laboratory-quality-system-standard', + 'regulations': 'https://cannabis.ny.gov/part-130-cannabis-laboratories-adopted', + 'columns': { + 'Permit # (OCM-CPL-XXXX)': 'license_number', + 'Lab Name': 'business_legal_name', + 'City': 'premise_city', + 'Cannabinoids (including d-10 THC)': 'cannabinoids', + 'Filth/Foreign Material': 'foreign_matter', + 'Metals (Heavy)': 'heavy_metals', + 'Microbiology*': 'microbes', + 'Moisture Content': 'moisture_content', + 'Mycotoxins/Aflatoxins': 'mycotoxins', + 'Pesticides': 'pesticides', + 'Residual Solvents': 'residual_solvents', + 'Terpenes': 'terpenes', + 'Water Activity': 'water_activity', + } + }, +} + + +def get_gis_data(df, api_key): + """Get GIS data.""" + drop_cols = ['state', 'state_name', 'address', 'formatted_address'] + rename_cols = { + 'county': 'premise_county', + 'latitude': 'premise_latitude', + 'longitude': 'premise_longitude' + } + df = geocode_addresses(df, api_key=api_key, address_field='address') + get_city = lambda x: x.split(', ')[1].split(',')[0] if STATE in str(x) else x + get_street = lambda x: str(x).split(', ')[0] + df['premise_city'] = df['formatted_address'].apply(get_city) + df['premise_street_address'] = df['formatted_address'].apply(get_street) + df.drop(columns=drop_cols, inplace=True) + return df.rename(columns=rename_cols) + + +def get_retailers_ny( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ) -> pd.DataFrame: + """Get New York cannabis retailers.""" + + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config.get('GOOGLE_MAPS_API_KEY') + if google_maps_api_key is None: + print('Proceeding without `GOOGLE_MAPS_API_KEY`.') + + # Create a dataset directory. + dataset_dir = os.path.join(data_dir, '.datasets') + if not os.path.exists(dataset_dir): + os.mkdir(dataset_dir) + + # Download the licenses document. + url = NEW_YORK['retailers']['url'] + response = requests.get(url) + pdf_file = os.path.join(dataset_dir, 'ny-retailers.pdf') + with open(pdf_file, 'wb') as f: + f.write(response.content) + + # Read the PDF. + doc = pdfplumber.open(pdf_file) + data = [] + for page in doc.pages: + table = page.extract_table() + if table is None: + continue + rows = [x for x in table if x[0] and x[0] != 'License Number' and x[0] != 'Application ID'] + data.extend(rows) + + # Close the PDF. + doc.close() + + # Remove the empty columns. + data = [[x for x in sublist if x is not None] for sublist in data] + + # Create a dataframe. + columns = [ + 'license_number', + 'business_legal_name', + 'county', + 'business_email', + 'business_phone', + ] + df = pd.DataFrame(data, columns=columns) + + # TODO: Determine active vs inactive licenses by * in `business_legal_name`. + + + # TODO: Standardize the licenses. + df['premise_state'] = STATE + + + # TODO: Augment GIS data. + + + # Define metadata. + df['data_refreshed_date'] = datetime.now().isoformat() + + # Sort the columns in alphabetical order + df.sort_index(axis=1, inplace=True) + + # Save the data. + if data_dir is not None: + if not os.path.exists(data_dir): + os.makedirs(data_dir) + date = datetime.now().isoformat()[:10] + outfile = f'{data_dir}/retailers-{STATE.lower()}-{date}.csv' + df.to_csv(outfile, index=False) + + # Return the data. + return df + + +def get_cultivators_ny( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ) -> pd.DataFrame: + """Get New York cannabis cultivators.""" + + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config.get('GOOGLE_MAPS_API_KEY') + if google_maps_api_key is None: + print('Proceeding without `GOOGLE_MAPS_API_KEY`.') + + # Create a dataset directory. + dataset_dir = os.path.join(data_dir, '.datasets') + if not os.path.exists(dataset_dir): + os.mkdir(dataset_dir) + + # Download the licenses document. + url = NEW_YORK['cultivators']['url'] + response = requests.get(url) + pdf_file = os.path.join(dataset_dir, 'ny-cultivators.pdf') + with open(pdf_file, 'wb') as f: + f.write(response.content) + + # Read the PDF. + doc = pdfplumber.open(pdf_file) + data = [] + for page in doc.pages: + table = page.extract_table() + if table is None: + continue + rows = [x for x in table if x[0] and x[0] != 'License Number' and x[0] != 'Application ID'] + data.extend(rows) + + # Close the PDF. + doc.close() + + # Remove the empty columns. + data = [[x for x in sublist if x is not None] for sublist in data] + + # Create a dataframe. + columns = [ + 'license_number', + 'business_legal_name', + 'county', + 'business_email', + 'business_phone', + ] + df = pd.DataFrame(data, columns=columns) + + + + # TODO: Standardize the data. + + + + # TODO: Augment GIS data. + + + + # # Define metadata. + # df['data_refreshed_date'] = datetime.now().isoformat() + + # # Sort the columns in alphabetical order + # df.sort_index(axis=1, inplace=True) + + # # Save the data. + # if data_dir is not None: + # if not os.path.exists(data_dir): + # os.makedirs(data_dir) + # date = datetime.now().isoformat()[:10] + # outfile = f'{data_dir}/cultivators-{STATE.lower()}-{date}.csv' + # df.to_csv(outfile, index=False) + + # # Return the data. + # return df + + + raise NotImplementedError + + +def get_processors_ny( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ) -> pd.DataFrame: + """Get New York cannabis processors.""" + + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config.get('GOOGLE_MAPS_API_KEY') + if google_maps_api_key is None: + print('Proceeding without `GOOGLE_MAPS_API_KEY`.') + + + # TODO: Get the data from the web / PDF. + + + + # TODO: Standardize the data. + + + + # TODO: Augment GIS data. + + + + # # Define metadata. + # df['data_refreshed_date'] = datetime.now().isoformat() + + # # Sort the columns in alphabetical order + # df.sort_index(axis=1, inplace=True) + + # # Save the data. + # if data_dir is not None: + # if not os.path.exists(data_dir): + # os.makedirs(data_dir) + # date = datetime.now().isoformat()[:10] + # outfile = f'{data_dir}/processors-{STATE.lower()}-{date}.csv' + # df.to_csv(outfile, index=False) + + # # Return the data. + # return df + + raise NotImplementedError + + +def get_labs_ny( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ) -> pd.DataFrame: + """Get New York cannabis labs.""" + + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config.get('GOOGLE_MAPS_API_KEY') + if google_maps_api_key is None: + print('Proceeding without `GOOGLE_MAPS_API_KEY`.') + + # Get the lab list from the web. + url = NEW_YORK['labs']['source'] + response = requests.get(url) + soup = BeautifulSoup(response.content, 'html.parser') + + # Find the table. + table = soup.find('table') + + # Get the table headers. + data = [] + header_row = table.find('thead').find('tr') + headers = [header.get_text(strip=True) for header in header_row.find_all('th')] + data.append(headers) + + # Get the table rows. + table_body = table.find('tbody') + rows = table_body.find_all('tr') + for row in rows: + cols = row.find_all('td') + cols = [col.get_text(strip=True) for col in cols] + data.append(cols) + + # Format a DataFrame. + df = pd.DataFrame(data[1:], columns=data[0]) + + # Rename columns. + df.rename(columns=NEW_YORK['labs']['columns'], inplace=True) + + # Identify analyses for each lab. + analyses = list(df.columns[3:]) + combine_analyses = lambda x: json.dumps([n for n in analyses if x[n] == 'x']) + df['analyses'] = df.apply(combine_analyses, axis=1) + df.drop(columns=analyses, inplace=True) + + # Augment GIS data. + if google_maps_api_key: + df['address'] = df['business_legal_name'] + ', ' + df['premise_city'] + ', ' + STATE + df = get_gis_data(df, api_key=google_maps_api_key) + + # Standardize the data. + df = df.assign( + id=df['license_number'].astype(str), + business_dba_name=df['business_legal_name'], + licensing_authority_id=NEW_YORK['licensing_authority_id'], + licensing_authority=NEW_YORK['licensing_authority'], + premise_state=STATE, + license_status_date=None, + license_type='lab', + license_term=None, + issue_date=None, + expiration_date=None, + business_structure=None, + activity=None, + parcel_number=None, + business_image_url=None, + ) + + # Define metadata. + df['data_refreshed_date'] = datetime.now().isoformat() + + # Sort the columns in alphabetical order + df.sort_index(axis=1, inplace=True) + + # Save the data. + if data_dir is not None: + if not os.path.exists(data_dir): + os.makedirs(data_dir) + date = datetime.now().isoformat()[:10] + outfile = f'{data_dir}/labs-{STATE.lower()}-{date}.csv' + df.to_csv(outfile, index=False) + + # Return the data. + return df + + +def get_medical_ny(): + """Get New York medical cannabis dispensaries.""" + raise NotImplementedError + + +def get_licenses_ny( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ): + """Get New York cannabis license data.""" + + # Get the data for the various licenses. + retailers = get_retailers_ny(data_dir, env_file) + labs = get_labs_ny(data_dir, env_file) + # FIXME: The following are not yet implemented. + # cultivators = get_cultivators_ny(data_dir, env_file) + # processors = get_processors_ny(data_dir, env_file) + # Future work: + # medical = get_medical_ny(data_dir, env_file) + + # Compile the data. + # sets = [retailers, cultivators, processors, labs] + sets = [retailers, labs] + licenses = pd.concat(sets, ignore_index=True) + licenses['premise_state'] = STATE + + # Save all of the licenses. + if data_dir is not None: + date = datetime.now().isoformat()[:10] + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{date}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + + # Return the licenses. + return licenses + + +# === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate +if __name__ == '__main__': + + # Support command line usage. + import argparse + try: + arg_parser = argparse.ArgumentParser() + arg_parser.add_argument('--d', dest='data_dir', type=str) + arg_parser.add_argument('--data_dir', dest='data_dir', type=str) + arg_parser.add_argument('--env', dest='env_file', type=str) + args = arg_parser.parse_args() + except SystemExit: + args = {'d': DATA_DIR, 'env_file': ENV_FILE} + + # Get licenses, saving them to the specified directory. + data_dir = args.get('d', args.get('data_dir')) + env_file = args.get('env_file') + data = get_licenses_ny(data_dir, env_file=env_file) diff --git a/algorithms/get_licenses_or.py b/algorithms/get_licenses_or.py index 0d770ac72930271b71819daecdfd4db1fc4664b3..2ebd8eb3e31d3b1b9230d5f187d92547f1117e29 100644 --- a/algorithms/get_licenses_or.py +++ b/algorithms/get_licenses_or.py @@ -6,7 +6,7 @@ Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/28/2022 -Updated: 10/7/2022 +Updated: 8/13/2023 License: Description: @@ -33,7 +33,7 @@ from cannlytics.data.gis import geocode_addresses # Specify where your data lives. DATA_DIR = '../data/or' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. OREGON = { @@ -191,9 +191,12 @@ def get_licenses_or( if data_dir is not None: timestamp = datetime.now().isoformat()[:19].replace(':', '-') data.to_csv(f'{data_dir}/licenses-or-{timestamp}.csv', index=False) + data.to_csv(f'{data_dir}/licenses-or-latest.csv', index=False) return data +# === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_ri.py b/algorithms/get_licenses_ri.py index fea1ffa1517bab406884f04bbfe3083a824e0e93..f60176fb3990f00d92aef7b8b65ae8fa8604f3b6 100644 --- a/algorithms/get_licenses_ri.py +++ b/algorithms/get_licenses_ri.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get Rhode Island Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/3/2022 +Updated: 8/13/2023 License: Description: @@ -18,6 +18,12 @@ Data Source: - Rhode Island URL: +TODO: + + [ ] Split up functionality into re-usable functions. + [ ] Make geocoding optional. + [ ] Make the code more robust to errors. + """ # Standard imports. from datetime import datetime @@ -34,7 +40,7 @@ import requests # Specify where your data lives. DATA_DIR = '../data/ri' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'RI' @@ -48,7 +54,9 @@ RHODE_ISLAND = { 'business_legal_name', 'address', 'business_phone', - 'license_designation', + 'business_website', + 'cultivator', + 'retailer', ], } } @@ -60,6 +68,10 @@ def get_licenses_ri( ): """Get Rhode Island cannabis license data.""" + # Load environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config['GOOGLE_MAPS_API_KEY'] + # Get the licenses webpage. url = RHODE_ISLAND['retailers']['url'] response = requests.get(url) @@ -75,7 +87,10 @@ def get_licenses_ri( obs = {} for i, cell in enumerate(cells): column = columns[i] - obs[column] = cell.text + if column == 'business_website': + obs[column] = cell.find('a')['href'] + else: + obs[column] = cell.text.replace('\n', '').replace('\t\t\t', ' ') data.append(obs) # Optional: It's possible to download the certificate to get it's `issue_date`. @@ -85,8 +100,8 @@ def get_licenses_ri( retailers['id'] = retailers['license_number'] retailers['licensing_authority_id'] = RHODE_ISLAND['licensing_authority_id'] retailers['licensing_authority'] = RHODE_ISLAND['licensing_authority'] - retailers['premise_state'] = STATE retailers['license_type'] = 'Commercial - Retailer' + retailers['premise_state'] = STATE retailers['license_status'] = 'Active' retailers['license_status_date'] = None retailers['license_term'] = None @@ -98,11 +113,10 @@ def get_licenses_ri( retailers['activity'] = None retailers['parcel_number'] = None retailers['business_image_url'] = None - retailers['business_website'] = None # Correct `license_designation`. coding = dict(Yes='Adult Use and Cultivation', No='Adult Use') - retailers['license_designation'] = retailers['license_designation'].map(coding) + retailers['license_designation'] = retailers['cultivator'].map(coding) # Correct `business_dba_name`. criterion = retailers['business_legal_name'].str.contains('D/B/A') @@ -127,8 +141,6 @@ def get_licenses_ri( retailers['data_refreshed_date'] = pd.to_datetime(date).isoformat() # Geocode the licenses. - config = dotenv_values(env_file) - google_maps_api_key = config['GOOGLE_MAPS_API_KEY'] retailers = geocode_addresses( retailers, api_key=google_maps_api_key, @@ -157,9 +169,14 @@ def get_licenses_ri( if not os.path.exists(data_dir): os.makedirs(data_dir) timestamp = datetime.now().isoformat()[:19].replace(':', '-') retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) + retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) + + # Return the curated licenses. return retailers +# === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_south_africa.py b/algorithms/get_licenses_south_africa.py new file mode 100644 index 0000000000000000000000000000000000000000..8590ae589bb63dfa3b8deedb9c34065679e9ee99 --- /dev/null +++ b/algorithms/get_licenses_south_africa.py @@ -0,0 +1,134 @@ +""" +Get South Africa cannabis license data. +Copyright (c) 2023 Cannlytics + +Authors: Keegan Skeate +Created: 5/10/2023 +Updated: 8/13/2023 +License: MIT License + +Data Source: + + - [South Africa Cannabis Licenses](https://www.sahpra.org.za/approved-licences/) + +Resources: + + - [South Africa Cannabis Licensing Press Release](https://www.sahpra.org.za/press-releases/cannabis-licensing/) + - [First-level Administrative Divisions, South Africa, 2015](https://earthworks.stanford.edu/catalog/stanford-js788dt6134) + +""" +# Standard imports: +from datetime import datetime +from time import sleep +from typing import Optional + +# External imports: +import pandas as pd +from selenium import webdriver +from selenium.webdriver.common.by import By + + +# Specify where your data lives. +DATA_DIR = '../data/south-africa' +ENV_FILE = '../../../.env' + + +def get_licenses_south_africa( + data_dir: Optional[str] = None, + env_file: Optional[str] = '.env', + ): + """Get South Africa cannabis license data.""" + + # Open the licenses webpage. + url = 'http://www.sahpra.org.za/approved-licences/' + driver = webdriver.Edge() + driver.get(url) + + # Click on the cultivations tab. + sleep(3) + link = driver.find_element(By.ID, 'ui-id-5') + link.click() + + # Iterate over all of the pages. + data = [] + iterate = True + while iterate: + + # Find the table. + table = driver.find_element(By.CSS_SELECTOR, '[aria-label="Cannabis Cultivation licences"]') + + # Get all the rows from the table. + rows = table.find_elements(By.TAG_NAME, 'tr') + + # Extract the data from each cell. + for row in rows[3:]: + cells = row.find_elements(By.TAG_NAME, 'td') + row_data = { + 'business_legal_name': cells[0].text, + 'license_number': cells[1].text, + 'business_owner_name': cells[2].text, + 'premise_state': cells[3].text, + 'issue_date': cells[4].text, + 'expiration_date': cells[5].text, + } + data.append(row_data) + + # Click the next button, if not disabled. + li = driver.find_element(By.CSS_SELECTOR, '[aria-label="next"]') + action = li.find_element(By.TAG_NAME, 'a') + style = li.get_attribute('class') + if 'disabled' in style.split(): + iterate = False + action.click() + sleep(3) + + # Standardize the license data. + df = pd.DataFrame(data) + df['id'] = df['license_number'] + df['licensing_authority_id'] = 'SAHPRA' + df['licensing_authority'] = 'South African Health Products Regulatory Authority' + df['license_type'] = 'Medical - Cultivator' + df['license_status'] = 'Active' + df['license_status_date'] = None + df['license_term'] = None + df['business_structure'] = None + df['business_email'] = None + df['activity'] = None + df['parcel_number'] = None + df['business_image_url'] = None + + # TODO: Get `data_refreshed_at` from the webpage. + + # TODO: Geocode licenses. + + # Close the browser. + driver.close() + + # Save the data. + date = datetime.now().strftime('%Y-%m-%d') + df.to_csv(f'{data_dir}/licenses-south-africa-{date}.csv', index=False) + df.to_csv(f'{data_dir}/licenses-south-africa-latest.csv', index=False) + + # Return the licenses. + return df + + +# === Test === +# [ ] Tested: +if __name__ == '__main__': + + # Support command line usage. + import argparse + try: + arg_parser = argparse.ArgumentParser() + arg_parser.add_argument('--d', dest='data_dir', type=str) + arg_parser.add_argument('--data_dir', dest='data_dir', type=str) + arg_parser.add_argument('--env', dest='env_file', type=str) + args = arg_parser.parse_args() + except SystemExit: + args = {'d': DATA_DIR, 'env_file': ENV_FILE} + + # Get licenses, saving them to the specified directory. + data_dir = args.get('d', args.get('data_dir')) + env_file = args.get('env_file') + data = get_licenses_south_africa(data_dir, env_file=env_file) diff --git a/algorithms/get_licenses_vt.py b/algorithms/get_licenses_vt.py index 71e3142cb61270c123f0017a778208b031074706..ea823c070ab8009bec0f4fd22f230e0a38561805 100644 --- a/algorithms/get_licenses_vt.py +++ b/algorithms/get_licenses_vt.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get Vermont Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/7/2022 +Updated: 8/13/2023 License: Description: @@ -34,7 +34,7 @@ import requests # Specify where your data lives. DATA_DIR = '../data/vt' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'VT' @@ -118,6 +118,10 @@ def get_licenses_vt( ): """Get Vermont cannabis license data.""" + # Load the environment variables. + config = dotenv_values(env_file) + google_maps_api_key = config['GOOGLE_MAPS_API_KEY'] + # Get the licenses from the webpage. url = VERMONT['licenses_url'] response = requests.get(url) @@ -160,46 +164,47 @@ def get_licenses_vt( licenses['business_website'] = None # Separate the `license_designation` from `license_type` if (Tier x). - criterion = licenses['license_type'].str.contains('Tier ') - licenses.loc[criterion, 'license_designation'] = licenses.loc[criterion]['license_type'].apply( - lambda x: 'Tier ' + x.split('(Tier ')[1].rstrip(')') - ) - licenses.loc[criterion, 'license_type'] = licenses.loc[criterion]['license_type'].apply( - lambda x: x.split('(Tier ')[0].strip() - ) + # FIXME: The data has changed and this is no longer relevant. + # criterion = licenses['license_type'].str.contains('Tier ') + # licenses.loc[criterion, 'license_designation'] = licenses.loc[criterion]['license_type'].apply( + # lambda x: 'Tier ' + x.split('(Tier ')[1].rstrip(')') + # ) + # licenses.loc[criterion, 'license_type'] = licenses.loc[criterion]['license_type'].apply( + # lambda x: x.split('(Tier ')[0].strip() + # ) # Separate labs' `business_email` and `business_phone` from the `address`. - criterion = licenses['license_type'] == 'Testing Lab' - licenses.loc[criterion, 'business_email'] = licenses.loc[criterion]['address'].apply( - lambda x: x.split('Email: ')[-1].rstrip('\n') if isinstance(x, str) else x - ) - licenses.loc[criterion, 'business_phone'] = licenses.loc[criterion]['address'].apply( - lambda x: x.split('Phone: ')[-1].split('Email: ')[0].rstrip('\n') if isinstance(x, str) else x - ) - licenses.loc[criterion, 'address'] = licenses.loc[criterion]['address'].apply( - lambda x: x.split('Phone: ')[0].replace('\n', ' ').strip() if isinstance(x, str) else x - ) + # FIXME: The data has changed and this is no longer relevant. + # criterion = licenses['license_type'] == 'Testing Lab' + # licenses.loc[criterion, 'business_email'] = licenses.loc[criterion]['address'].apply( + # lambda x: x.split('Email: ')[-1].rstrip('\n') if isinstance(x, str) else x + # ) + # licenses.loc[criterion, 'business_phone'] = licenses.loc[criterion]['address'].apply( + # lambda x: x.split('Phone: ')[-1].split('Email: ')[0].rstrip('\n') if isinstance(x, str) else x + # ) + # licenses.loc[criterion, 'address'] = licenses.loc[criterion]['address'].apply( + # lambda x: x.split('Phone: ')[0].replace('\n', ' ').strip() if isinstance(x, str) else x + # ) # Split any DBA from the legal name. - splits = [';', 'DBA - ', '(DBA)', 'DBA ', 'dba '] - licenses['business_dba_name'] = licenses['business_legal_name'] - for split in splits: - criterion = licenses['business_legal_name'].str.contains(split) - licenses.loc[criterion, 'business_dba_name'] = licenses.loc[criterion]['business_legal_name'].apply( - lambda x: x.split(split)[1].replace(')', '').strip() if split in x else x - ) - licenses.loc[criterion, 'business_legal_name'] = licenses.loc[criterion]['business_legal_name'].apply( - lambda x: x.split(split)[0].replace('(', '').strip() - ) - licenses.loc[licenses['business_legal_name'] == '', 'business_legal_name'] = licenses['business_dba_name'] + # FIXME: The data has changed and this is no longer relevant. + # splits = [';', 'DBA - ', '(DBA)', 'DBA ', 'dba '] + # licenses['business_dba_name'] = licenses['business_legal_name'] + # for split in splits: + # criterion = licenses['business_legal_name'].str.contains(split) + # licenses.loc[criterion, 'business_dba_name'] = licenses.loc[criterion]['business_legal_name'].apply( + # lambda x: x.split(split)[1].replace(')', '').strip() if split in x else x + # ) + # licenses.loc[criterion, 'business_legal_name'] = licenses.loc[criterion]['business_legal_name'].apply( + # lambda x: x.split(split)[0].replace('(', '').strip() + # ) + # licenses.loc[licenses['business_legal_name'] == '', 'business_legal_name'] = licenses['business_dba_name'] # Get the refreshed date. licenses['data_refreshed_date'] = datetime.now().isoformat() # Geocode the licenses. # FIXME: There are some wonky addresses that are output! - config = dotenv_values(env_file) - google_maps_api_key = config['GOOGLE_MAPS_API_KEY'] licenses = geocode_addresses( licenses, api_key=google_maps_api_key, @@ -229,11 +234,15 @@ def get_licenses_vt( timestamp = datetime.now().isoformat()[:19].replace(':', '-') retailers = licenses.loc[licenses['license_type'] == 'Retail'] licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) + + # Return the curated licenses. return licenses # === Test === +# [✓] Tested: 2023-08-13 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/get_licenses_wa.py b/algorithms/get_licenses_wa.py index 4ba2e75fb0111768c5e9b20f7ad720983d2cf716..ecbe6656f3fe73c306bfbefc172309d4db7d32ad 100644 --- a/algorithms/get_licenses_wa.py +++ b/algorithms/get_licenses_wa.py @@ -1,12 +1,12 @@ """ Cannabis Licenses | Get Washington Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/7/2022 +Updated: 8/9/2023 License: Description: @@ -34,7 +34,7 @@ import requests # Specify where your data lives. DATA_DIR = '../data/wa' -ENV_FILE = '../.env' +ENV_FILE = '../../../.env' # Specify state-specific constants. STATE = 'WA' @@ -245,6 +245,7 @@ def get_licenses_wa( if data_dir is not None: timestamp = datetime.now().isoformat()[:19].replace(':', '-') licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False) + licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-latest.csv', index=False) retailers = licenses.loc[licenses['license_type'] == 'Adult-Use Retailer'] retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False) labs = licenses.loc[licenses['license_type'] == 'Lab'] @@ -252,6 +253,8 @@ def get_licenses_wa( return retailers +# === Test === +# [✓] Tested: 2023-08-09 by Keegan Skeate if __name__ == '__main__': # Support command line usage. diff --git a/algorithms/main.py b/algorithms/main.py index bada08779537690854f37596f69e3eacc6a8cbbb..d0d887e0b84f738f58dafc6c9407d3ecd6052a7c 100644 --- a/algorithms/main.py +++ b/algorithms/main.py @@ -1,31 +1,36 @@ """ Cannabis Licenses | Get All Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/7/2022 +Updated: 9/20/2023 License: Description: Collect all cannabis license data from states with permitted adult-use: - ✓ Alaska (Selenium) - ✓ Arizona (Selenium) + ✓ Alaska (Requires Selenium) + ✓ Arizona (Requires Selenium) ✓ California ✓ Colorado ✓ Connecticut - ✓ Illinois + ✓ Delaware + ✓ Illinois (FIXME) ✓ Maine + ✓ Maryland ✓ Massachusetts - ✓ Michigan (Selenium) + ✓ Michigan (Requires Selenium) + ✓ Minnesota + ✓ Missouri ✓ Montana ✓ Nevada ✓ New Jersey - x New Mexico (Selenium) (FIXME) + ✓ New York + ✓ New Mexico (Requires Selenium) (FIXME) ✓ Oregon ✓ Rhode Island ✓ Vermont @@ -35,8 +40,10 @@ Description: from datetime import datetime import importlib import os +import sys # External imports. +from cannlytics import Cannlytics import pandas as pd @@ -47,47 +54,124 @@ ALGORITHMS = { 'ca': 'get_licenses_ca', 'co': 'get_licenses_co', 'ct': 'get_licenses_ct', + 'de': 'get_licenses_de', 'il': 'get_licenses_il', 'ma': 'get_licenses_ma', + 'md': 'get_licenses_md', 'me': 'get_licenses_me', 'mi': 'get_licenses_mi', + 'mo': 'get_licenses_mo', 'mt': 'get_licenses_mt', 'nj': 'get_licenses_nj', - # 'nm': 'get_licenses_nm', + 'nm': 'get_licenses_nm', 'nv': 'get_licenses_nv', + 'ny': 'get_licenses_ny', 'or': 'get_licenses_or', 'ri': 'get_licenses_ri', 'vt': 'get_licenses_vt', 'wa': 'get_licenses_wa', + # Future: + # 'va': 'get_licenses_va', + # 'mn': 'get_licenses_mn', + # Medical: + # 'al': 'get_licenses_al', + # 'ar': 'get_licenses_ar', + # 'fl': 'get_licenses_fl', + # 'ky': 'get_licenses_ky', + # 'la': 'get_licenses_la', + # 'ms': 'get_licenses_ms', + # 'nd': 'get_licenses_nd', + # 'nh': 'get_licenses_nh', + # 'oh': 'get_licenses_oh', + # 'ok': 'get_licenses_ok', + # 'pa': 'get_licenses_pa', + # 'sd': 'get_licenses_sd', + # 'tx': 'get_licenses_tx', + # 'ut': 'get_licenses_ut', + # 'wv': 'get_licenses_wv' } -DATA_DIR = '../data' - def main(data_dir, env_file): """Collect all cannabis license data from states with permitted adult-use, dynamically importing modules and finding the entry point for each of the `ALGORITHMS`.""" + + # Initialize. licenses = pd.DataFrame() + date = datetime.now().isoformat()[:10] + manager = Cannlytics() + + # Add the state_modules directory to sys.path for dynamic imports + sys.path.append(os.getcwd()) + + # Collect licenses for each state. for state, algorithm in ALGORITHMS.items(): - module = importlib.import_module(f'{algorithm}') + + # Import the module and get the entry point. + module = importlib.import_module(algorithm) entry_point = getattr(module, algorithm) - try: - print(f'Getting license data for {state.upper()}.') - data = entry_point(data_dir, env_file=env_file) - if not os.path.exists(f'{DATA_DIR}/{state}'): os.makedirs(f'{DATA_DIR}/{state}') - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - data.to_csv(f'{DATA_DIR}/{state}/licenses-{state}-{timestamp}.csv', index=False) - licenses = pd.concat([licenses, data]) - except: - print(f'Failed to collect {state.upper()} licenses.') + + # Collect licenses for the state. + # try: + manager.create_log(f'Getting license data for {state.upper()}.') + data = entry_point(data_dir, env_file=env_file) + + state_data_dir = os.path.join(data_dir, state) + if not os.path.exists(state_data_dir): + os.makedirs(state_data_dir) + + state_data_file = os.path.join(state_data_dir, f'licenses-{state}-{date}.csv') + data.to_csv(state_data_file, index=False) + manager.create_log(f'Collected {state.upper()} licenses.') + licenses = pd.concat([licenses, data]) + # except: + # manager.create_log(f'Failed to aggregate {state.upper()} licenses.') + + # Save all of the licenses. + all_data_dir = os.path.join(data_dir, 'all') + if not os.path.exists(all_data_dir): + os.makedirs(all_data_dir) + + - # Save all of the retailers. - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - licenses.to_csv(f'{DATA_DIR}/all/licenses-{timestamp}.csv', index=False) + all_data_file = os.path.join(all_data_dir, f'licenses-{date}.csv') + licenses.to_csv(all_data_file, index=False) + manager.create_log(f'Finished collecting licenses data.') return licenses +def save_all_licenses(data_dir, version='latest'): + """Save all of the licenses to a single CSV file.""" + + # Read all of the latest license data. + all_licenses = [] + states = ALGORITHMS.keys() + for state in states: + state_data_dir = os.path.join(data_dir, state) + state_data_file = os.path.join(state_data_dir, f'licenses-{state}-{version}.csv') + if os.path.exists(state_data_file): + state_data = pd.read_csv(state_data_file) + all_licenses.append(state_data) + print('Aggregated data for', state.upper()) + else: + print(f'No data for {state.upper()}.') + + # Save all of the licenses. + if all_licenses: + licenses = pd.concat(all_licenses) + all_data_file = os.path.join(data_dir, f'all/licenses-all-{version}.csv') + licenses.to_csv(all_data_file, index=False) + print('Saved all licenses to', all_data_file) + return licenses + + # No datafiles found. + else: + print('No licenses to save.') + return None + + # === Test === +# [✓] Tested: 2023-09-20 by Keegan Skeate if __name__ == '__main__': # Support command line usage. @@ -99,11 +183,19 @@ if __name__ == '__main__': arg_parser.add_argument('--env', dest='env_file', type=str) args = arg_parser.parse_args() except SystemExit: - args = {'d': '../data/all', 'env_file': '../.env'} - + args = {'d': '../data', 'env_file': '../../../.env'} + # Get arguments. data_dir = args.get('d', args.get('data_dir')) env_file = args.get('env_file') # Get licenses for each state. - all_licenses = main(data_dir, env_file) + # all_licenses = main(data_dir, env_file) + + # Save all licenses. + data_dir = '../data' + all_licenses = save_all_licenses(data_dir) + print('Saved %i licenses.' % len(all_licenses)) + + # TODO: Upload all CSVs to Firebase Storage. + diff --git a/analysis/figures/cannabis-licenses-map.html b/analysis/figures/cannabis-licenses-map.html index 47bef60a28582300934dca01c07be65c65b0df9d..4720775a0b1d2e77661fecb039ab75ce67508947 100644 --- a/analysis/figures/cannabis-licenses-map.html +++ b/analysis/figures/cannabis-licenses-map.html @@ -1,5 +1,7 @@ - + + + + - + - - - - + + + + - + + -
+
- \ No newline at end of file + + \ No newline at end of file diff --git a/analysis/figures/cannabis-licenses-map.png b/analysis/figures/cannabis-licenses-map.png deleted file mode 100644 index 2019b85c44c7a1eb9bd1eb747089a9985dac3bde..0000000000000000000000000000000000000000 --- a/analysis/figures/cannabis-licenses-map.png +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:b2664e0dd4284155fd74655fe94cd1e5eca805da1231276398887b8ac8f2811a -size 470396 diff --git a/analysis/license_map.py b/analysis/license_map.py index 916a319c5d491a27ed88e583644cb5f66b7d44d3..70e6648e402f3e50d536ba744f6747b07a5026e7 100644 --- a/analysis/license_map.py +++ b/analysis/license_map.py @@ -1,70 +1,46 @@ """ Cannabis Licenses | License Mao -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/22/2022 -Updated: 10/8/2022 +Updated: 9/19/2023 License: Description: Map the adult-use cannabis retailers permitted in the United States: - ✓ Alaska - ✓ Arizona - ✓ California - ✓ Colorado - ✓ Connecticut - ✓ Illinois - ✓ Maine - ✓ Massachusetts - ✓ Michigan - ✓ Montana - ✓ Nevada - ✓ New Jersey - x New Mexico (FIXME) - ✓ Oregon - ✓ Rhode Island - ✓ Vermont - ✓ Washington + ✓ Alaska + ✓ Arizona + ✓ California + ✓ Colorado + ✓ Connecticut + ✓ Delaware + ✓ Illinois + ✓ Maine + ✓ Massachusetts + ✓ Michigan + ✓ Missouri + ✓ Montana + ✓ Nevada + ✓ New Jersey + X New York (Under development) + ✓ New Mexico + ✓ Oregon + ✓ Rhode Island + ✓ Vermont + X Virginia (Expected 2024) + ✓ Washington """ -# Standard imports. -from datetime import datetime -import json -import os - # External imports. import folium import pandas as pd -# Specify where your data lives. -DATA_DIR = '../' - -# Read data subsets. -with open('../subsets.json', 'r') as f: - SUBSETS = json.loads(f.read()) - - -def aggregate_retailers( - datafiles, - index_col=0, - lat='premise_latitude', - long='premise_longitude', - ): - """Aggregate retailer license data files, - keeping only those with latitude and longitude.""" - data = [] - for filename in datafiles: - data.append(pd.read_csv(filename, index_col=index_col)) - data = pd.concat(data) - return data.loc[(~data[lat].isnull()) & (~data[long].isnull())] - - def create_retailer_map( df, color='crimson', @@ -92,15 +68,22 @@ def create_retailer_map( # === Test === if __name__ == '__main__': - # Aggregate retailers. - subsets = list(SUBSETS.values()) - datafiles = [DATA_DIR + x['data_url'] for x in subsets] - retailers = aggregate_retailers(datafiles) + # Read all licenses. + data = pd.read_csv('../data/all/licenses-all-latest.csv') + data = data.loc[ + (~data['premise_latitude'].isnull()) & + (~data['premise_longitude'].isnull()) + ] - # Create the retailers map. + # Create a map of all licenses. map_file = '../analysis/figures/cannabis-licenses-map.html' - m = create_retailer_map(retailers, filename=map_file) + m = create_retailer_map(data, filename=map_file) + print('Saved map to', map_file) + + # FIXME: Create a PNG image of the map. + # import io + # from PIL import Image - # Save all of the retailers. - timestamp = datetime.now().isoformat()[:19].replace(':', '-') - retailers.to_csv(f'{DATA_DIR}/data/all/licenses-{timestamp}.csv', index=False) + # img_data = m._to_png(30) + # img = Image.open(io.BytesIO(img_data)) + # img.save('../analysis/figures/cannabis-licenses-map.png') diff --git a/cannabis_licenses.py b/cannabis_licenses.py index 779424b3744750012a43d6c900771467069bfe87..fea53a8f77727fd72e27d6769f6c22ac47cd8ea4 100644 --- a/cannabis_licenses.py +++ b/cannabis_licenses.py @@ -1,17 +1,14 @@ """ Cannabis Licenses -Copyright (c) 2022 Cannlytics +Copyright (c) 2022-2023 Cannlytics Authors: Keegan Skeate Candace O'Sullivan-Sutherland Created: 9/29/2022 -Updated: 10/8/2022 +Updated: 9/19/2023 License: """ -# Standard imports. -import json - # External imports. import datasets import pandas as pd @@ -19,27 +16,51 @@ import pandas as pd # Constants. _SCRIPT = 'cannabis_licenses.py' -_VERSION = '1.0.0' +_VERSION = '1.0.1' _HOMEPAGE = 'https://huggingface.co/datasets/cannlytics/cannabis_licenses' _LICENSE = "https://opendatacommons.org/licenses/by/4-0/" _DESCRIPTION = """\ -Cannabis Licenses (https://cannlytics.com/data/licenses) is a -dataset of curated cannabis license data. The dataset consists of 18 -sub-datasets for each state with permitted adult-use cannabis, as well -as a sub-dataset that includes all licenses. +Cannabis Licenses is a dataset of curated cannabis license data. The dataset consists of sub-datasets for each state with permitted adult-use cannabis, as well as a sub-dataset that includes all licenses. """ _CITATION = """\ -@inproceedings{cannlytics2022cannabis_licenses, +@inproceedings{cannlytics2023cannabis_licenses, author = {Skeate, Keegan and O'Sullivan-Sutherland, Candace}, title = {Cannabis Licenses}, booktitle = {Cannabis Data Science}, - month = {October}, - year = {2022}, + month = {August}, + year = {2023}, address = {United States of America}, publisher = {Cannlytics} } """ + +# Read subsets from local source. +SUBSETS = [ + 'all', + 'ak', + 'az', + 'ca', + 'co', + 'ct', + 'il', + 'ma', + 'md', + 'me', + 'mi', + 'mo', + 'mt', + 'nj', + 'nm', + # 'ny', + 'nv', + 'or', + 'ri', + 'vt', + 'wa', +] + + # Dataset fields. FIELDS = datasets.Features({ 'id': datasets.Value(dtype='string'), @@ -68,20 +89,11 @@ FIELDS = datasets.Features({ 'business_email': datasets.Value(dtype='string'), 'business_phone': datasets.Value(dtype='string'), 'parcel_number': datasets.Value(dtype='string'), - 'premise_latitude': datasets.Value(dtype='float'), - 'premise_longitude': datasets.Value(dtype='float'), + 'premise_latitude': datasets.Value(dtype='string'), + 'premise_longitude': datasets.Value(dtype='string'), 'data_refreshed_date': datasets.Value(dtype='string'), }) -# DEV: Read subsets from local source. -# with open('subsets.json', 'r') as f: -# SUBSETS = json.loads(f.read()) - -# PRODUCTION: Read subsets from the official source. -import urllib.request -with urllib.request.urlopen('https://huggingface.co/datasets/cannlytics/cannabis_licenses/raw/main/subsets.json') as url: - SUBSETS = json.load(url) - class CannabisLicensesConfig(datasets.BuilderConfig): """BuilderConfig for Cannabis Licenses.""" @@ -94,7 +106,12 @@ class CannabisLicensesConfig(datasets.BuilderConfig): """ description = _DESCRIPTION description += f'This configuration is for the `{name}` subset.' - super().__init__(name=name, description=description, **kwargs) + super().__init__( + data_dir='./data', + description=description, + name=name, + **kwargs, + ) class CannabisLicenses(datasets.GeneratorBasedBuilder): @@ -102,8 +119,8 @@ class CannabisLicenses(datasets.GeneratorBasedBuilder): VERSION = datasets.Version(_VERSION) BUILDER_CONFIG_CLASS = CannabisLicensesConfig - BUILDER_CONFIGS = [CannabisLicensesConfig(s) for s in SUBSETS.keys()] - DEFAULT_CONFIG_NAME = 'ca' + BUILDER_CONFIGS = [CannabisLicensesConfig(s) for s in SUBSETS] + DEFAULT_CONFIG_NAME = 'all' def _info(self): """Returns the dataset metadata.""" @@ -119,33 +136,47 @@ class CannabisLicenses(datasets.GeneratorBasedBuilder): def _split_generators(self, dl_manager): """Returns SplitGenerators.""" - config_name = self.config.name - data_url = SUBSETS[config_name]['data_url'] - urls = {config_name: data_url} + subset = self.config.name + # Deprecated: Use the data from the Cannlytics Hugging Face repository. + # https://huggingface.co/datasets/cannlytics/cannabis_licenses/raw/main/ + # data_url = SUBSETS[config_name]['data_url'] + # TEST: Use local data. + data_url = f'./data/{subset}/licenses-{subset}-latest.csv' + urls = {subset: data_url} downloaded_files = dl_manager.download_and_extract(urls) - filepath = downloaded_files[config_name] - params = {'filepath': filepath} + params = {'filepath': downloaded_files[subset]} return [datasets.SplitGenerator(name='data', gen_kwargs=params)] def _generate_examples(self, filepath): """Returns the examples in raw text form.""" - with open(filepath) as f: - df = pd.read_csv(filepath) - for index, row in df.iterrows(): - obs = row.to_dict() - yield index, obs + # Read the data. + df = pd.read_csv(filepath) + + # Add missing columns. + for col in FIELDS.keys(): + if col not in df.columns: + df[col] = '' + + # Keep only the feature columns. + df = df[list(FIELDS.keys())] + + # Fill missing values. + df.fillna('', inplace=True) + + # Return the data as a dictionary. + for index, row in df.iterrows(): + obs = row.to_dict() + yield index, obs # === Test === +# [✓] Tested: 2023-09-19 by Keegan Skeate if __name__ == '__main__': from datasets import load_dataset - # Define all of the dataset subsets. - subsets = list(SUBSETS.keys()) - # Load each dataset subset. - for subset in subsets: + for subset in SUBSETS: dataset = load_dataset(_SCRIPT, subset) data = dataset['data'] assert len(data) > 0 diff --git a/data/ak/licenses-ak-2023-04-24T18-17-38.csv b/data/ak/licenses-ak-2023-04-24T18-17-38.csv new file mode 100644 index 0000000000000000000000000000000000000000..defd2324534baa839a7c50b2b17727cf91be2769 --- /dev/null +++ b/data/ak/licenses-ak-2023-04-24T18-17-38.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:012304c4a47fb7892f975f7a3d919c1a7b916292158cb1bd9940b95190b221cf +size 161682 diff --git a/data/ak/licenses-ak-2023-08-12T10-49-50.csv b/data/ak/licenses-ak-2023-08-12T10-49-50.csv new file mode 100644 index 0000000000000000000000000000000000000000..809f2b6609f5e64c268e7b750ee23e032f9218c9 --- /dev/null +++ b/data/ak/licenses-ak-2023-08-12T10-49-50.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e55a69856ba6089420c370da65cca67976bc1cf0497f925dc2f749f7ed3cf28f +size 168605 diff --git a/data/ak/licenses-ak-latest.csv b/data/ak/licenses-ak-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..809f2b6609f5e64c268e7b750ee23e032f9218c9 --- /dev/null +++ b/data/ak/licenses-ak-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e55a69856ba6089420c370da65cca67976bc1cf0497f925dc2f749f7ed3cf28f +size 168605 diff --git a/data/ak/retailers-ak-2023-04-24T18-17-38.csv b/data/ak/retailers-ak-2023-04-24T18-17-38.csv new file mode 100644 index 0000000000000000000000000000000000000000..6d5627d4c00e9afdb67f981b2e5b4338caa649f9 --- /dev/null +++ b/data/ak/retailers-ak-2023-04-24T18-17-38.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f13a0a812d048712dba30fe1e373e07cfd47e596dff03b174f0797112252ec29 +size 59171 diff --git a/data/ak/retailers-ak-2023-08-12T10-49-50.csv b/data/ak/retailers-ak-2023-08-12T10-49-50.csv new file mode 100644 index 0000000000000000000000000000000000000000..835ab341aca20236e75865bf61ad5a303f694db6 --- /dev/null +++ b/data/ak/retailers-ak-2023-08-12T10-49-50.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1b6b7d7f82dc8aadfaa1ad017f3c91f534b253a43175f18f8d9b587334436b1f +size 63901 diff --git a/data/all/licenses-2022-10-06.csv b/data/all/licenses-2022-10-06.csv new file mode 100644 index 0000000000000000000000000000000000000000..dc8d0df1a20fd658a183e52dcd59f43614a2c895 --- /dev/null +++ b/data/all/licenses-2022-10-06.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:091d343ceee078d47fa9a8c235060f8ee20a500bb3844f752cd243237aeaea0c +size 6961305 diff --git a/data/all/licenses-all-latest.csv b/data/all/licenses-all-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..1ef0d03cb381d82c37942fd0fdb8ae120e7533f5 --- /dev/null +++ b/data/all/licenses-all-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:61bcc6787e2fee35016ee2104d8120041ca3bc654658c4328f5d1e1ed8518dc6 +size 10003641 diff --git a/data/az/cultivators-az-2023-08-13T12-34-02.csv b/data/az/cultivators-az-2023-08-13T12-34-02.csv new file mode 100644 index 0000000000000000000000000000000000000000..b0bc2738fc4b6598c9a9539a87a5e080510f4f19 --- /dev/null +++ b/data/az/cultivators-az-2023-08-13T12-34-02.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:177471253cc20dcdf224a07fc64d28d3f243228ac73debb024b5b9d2818a12c2 +size 25530 diff --git a/data/az/licenses-az-2023-04-25T13-29-54.csv b/data/az/licenses-az-2023-04-25T13-29-54.csv new file mode 100644 index 0000000000000000000000000000000000000000..5bbc2c2e83c433bf847136a816f13ca5a84fcbca --- /dev/null +++ b/data/az/licenses-az-2023-04-25T13-29-54.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e79bfb2d2cd4540f1322a52ddcbc63d13a188200d18cb926ea85b4747a434039 +size 54294 diff --git a/data/az/licenses-az-2023-08-13T12-34-02.csv b/data/az/licenses-az-2023-08-13T12-34-02.csv new file mode 100644 index 0000000000000000000000000000000000000000..64451b8c4b0808f19b0e658c60b9f1fdab875512 --- /dev/null +++ b/data/az/licenses-az-2023-08-13T12-34-02.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7957d849efc48b293f93ac325313f0fe08eaabcde019c2b3a23726ad6159a82 +size 109205 diff --git a/data/az/licenses-az-latest.csv b/data/az/licenses-az-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..64451b8c4b0808f19b0e658c60b9f1fdab875512 --- /dev/null +++ b/data/az/licenses-az-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e7957d849efc48b293f93ac325313f0fe08eaabcde019c2b3a23726ad6159a82 +size 109205 diff --git a/data/az/manufacturers-az-2023-08-13T12-34-02.csv b/data/az/manufacturers-az-2023-08-13T12-34-02.csv new file mode 100644 index 0000000000000000000000000000000000000000..0a4d38b9e19dd33cae89fb781bc2d2124e580ac7 --- /dev/null +++ b/data/az/manufacturers-az-2023-08-13T12-34-02.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdae174af4d56de3840fffa007fc64365390620cad6ec8e22399fe1c8fb25a2b +size 8231 diff --git a/data/az/retailers-az-2023-04-25T13-29-54.csv b/data/az/retailers-az-2023-04-25T13-29-54.csv new file mode 100644 index 0000000000000000000000000000000000000000..7f81e942e5eae4ce2f12a4dca0ae23d16a017669 --- /dev/null +++ b/data/az/retailers-az-2023-04-25T13-29-54.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:912bc0ba36c244f5d7856270d76d28354dc1c5c0b9ead3d664f0980cb1eade20 +size 53936 diff --git a/data/az/retailers-az-2023-08-13T12-34-02.csv b/data/az/retailers-az-2023-08-13T12-34-02.csv new file mode 100644 index 0000000000000000000000000000000000000000..57b35e25d6ee9fbbe8af7831d72948831297b969 --- /dev/null +++ b/data/az/retailers-az-2023-08-13T12-34-02.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d77b68a1fb0c44a3e33e6f373a8d02081ca86ac83e221da860d9a0185f31eb49 +size 76016 diff --git a/data/ca/licenses-ca-2023-04-24T16-09-51.csv b/data/ca/licenses-ca-2023-04-24T16-09-51.csv new file mode 100644 index 0000000000000000000000000000000000000000..74a1c0adb4afdd115fa55123615b9a3152b0060b --- /dev/null +++ b/data/ca/licenses-ca-2023-04-24T16-09-51.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c3d26ddde407bd2da255f50e6b2d20de6d383e8b8ff621049664b09d60cf7997 +size 5001203 diff --git a/data/ca/licenses-ca-2023-05-09.csv b/data/ca/licenses-ca-2023-05-09.csv new file mode 100644 index 0000000000000000000000000000000000000000..691f01aab4767558e3cca031d6d695ec452e1279 --- /dev/null +++ b/data/ca/licenses-ca-2023-05-09.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cbfb7d4fa78dcd0eff29ff681a26d27a12da871507e29394b9ffb275cf2a7a84 +size 4876316 diff --git a/data/ca/licenses-ca-2023-06-06.csv b/data/ca/licenses-ca-2023-06-06.csv new file mode 100644 index 0000000000000000000000000000000000000000..213646c437021a067e2a4866a13e68ec6aeee7d5 --- /dev/null +++ b/data/ca/licenses-ca-2023-06-06.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ae26e710056fb93d3bdbe0d17c094bbba7220902db275c3663e9900732e420fb +size 4741926 diff --git a/data/ca/licenses-ca-2023-08-13T15-49-47.csv b/data/ca/licenses-ca-2023-08-13T15-49-47.csv new file mode 100644 index 0000000000000000000000000000000000000000..9b26067fdb2bb459bf81e822fe0564387d958c26 --- /dev/null +++ b/data/ca/licenses-ca-2023-08-13T15-49-47.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:65e7de95f3aa916fdc180c7c34db53b41d7fa20978f4678e58f17ceafc031c08 +size 4683044 diff --git a/data/ca/licenses-ca-latest.csv b/data/ca/licenses-ca-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..9b26067fdb2bb459bf81e822fe0564387d958c26 --- /dev/null +++ b/data/ca/licenses-ca-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:65e7de95f3aa916fdc180c7c34db53b41d7fa20978f4678e58f17ceafc031c08 +size 4683044 diff --git a/data/co/licenses-co-2023-04-24T18-47-58.csv b/data/co/licenses-co-2023-04-24T18-47-58.csv new file mode 100644 index 0000000000000000000000000000000000000000..6ecbe939528e5ab50a663fc2b1ecafbe075a312e --- /dev/null +++ b/data/co/licenses-co-2023-04-24T18-47-58.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:982b8aeb74b51bef20452c6dd129d8ac9296acbe9510c80900cc1d73a4bdc861 +size 537944 diff --git a/data/co/licenses-co-2023-08-13T12-47-32.csv b/data/co/licenses-co-2023-08-13T12-47-32.csv new file mode 100644 index 0000000000000000000000000000000000000000..c4047c81429dabec912eb9bb09bc8a652ceed814 --- /dev/null +++ b/data/co/licenses-co-2023-08-13T12-47-32.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8dbbd8e0b4fa9429f531d3ba1a855a4fcad30f60714e73da024c93ad5de6bdf8 +size 537375 diff --git a/data/co/licenses-co-2023-09-20T08-09-13.csv b/data/co/licenses-co-2023-09-20T08-09-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..ff101407f3ad298001412fceb902bbe5dd908c22 --- /dev/null +++ b/data/co/licenses-co-2023-09-20T08-09-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8843db838fef0a1bcab74266dd92f087348ecce51f1eb0cb6555fc2fb36ed238 +size 655517 diff --git a/data/co/licenses-co-2023-09-20T08-09-26.csv b/data/co/licenses-co-2023-09-20T08-09-26.csv new file mode 100644 index 0000000000000000000000000000000000000000..ff101407f3ad298001412fceb902bbe5dd908c22 --- /dev/null +++ b/data/co/licenses-co-2023-09-20T08-09-26.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8843db838fef0a1bcab74266dd92f087348ecce51f1eb0cb6555fc2fb36ed238 +size 655517 diff --git a/data/co/licenses-co-latest.csv b/data/co/licenses-co-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..ff101407f3ad298001412fceb902bbe5dd908c22 --- /dev/null +++ b/data/co/licenses-co-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8843db838fef0a1bcab74266dd92f087348ecce51f1eb0cb6555fc2fb36ed238 +size 655517 diff --git a/data/co/retailers-co-2023-04-24T18-47-58.csv b/data/co/retailers-co-2023-04-24T18-47-58.csv new file mode 100644 index 0000000000000000000000000000000000000000..5506b37252a49c8277a38bd4567616e0a1a34f5f --- /dev/null +++ b/data/co/retailers-co-2023-04-24T18-47-58.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62194074dae2f31228b7fa49203e6690c21469ede1fe7925cf25a647bada49b7 +size 316843 diff --git a/data/co/retailers-co-2023-08-13T12-47-32.csv b/data/co/retailers-co-2023-08-13T12-47-32.csv new file mode 100644 index 0000000000000000000000000000000000000000..9a51f7053b541ad049cc40cd49d58e2367160c0b --- /dev/null +++ b/data/co/retailers-co-2023-08-13T12-47-32.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fff441f0cdb6e7ec7818c2398d333a6ac2630e8fdf43b52706402eb1b93fef92 +size 325088 diff --git a/data/co/retailers-co-2023-09-20T08-09-26.csv b/data/co/retailers-co-2023-09-20T08-09-26.csv new file mode 100644 index 0000000000000000000000000000000000000000..f33dda6cae3405bc000865f3d6aae0cc9f963e35 --- /dev/null +++ b/data/co/retailers-co-2023-09-20T08-09-26.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9bdd89f668b7d5ea6b5fc09ee170749ec38710c875ff2ee0649b28351024c350 +size 321650 diff --git a/data/ct/licenses-ct-2023-08-13T12-36-03.csv b/data/ct/licenses-ct-2023-08-13T12-36-03.csv new file mode 100644 index 0000000000000000000000000000000000000000..f40f357b60e133f997cb9d7b072049d9623bcb25 --- /dev/null +++ b/data/ct/licenses-ct-2023-08-13T12-36-03.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51f060d42334c341bae4e7056608fb2d3a7616add55106ea15c4e04fec920699 +size 6389 diff --git a/data/ct/licenses-ct-latest.csv b/data/ct/licenses-ct-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..f40f357b60e133f997cb9d7b072049d9623bcb25 --- /dev/null +++ b/data/ct/licenses-ct-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51f060d42334c341bae4e7056608fb2d3a7616add55106ea15c4e04fec920699 +size 6389 diff --git a/data/ct/retailers-ct-2023-04-24T20-43-56 - Copy.csv b/data/ct/retailers-ct-2023-04-24T20-43-56 - Copy.csv new file mode 100644 index 0000000000000000000000000000000000000000..86bf388aae233901d431be0d1668af8c218b4c85 --- /dev/null +++ b/data/ct/retailers-ct-2023-04-24T20-43-56 - Copy.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0968f03fce45c26f14fdfa9abbed8b40f3d69ad9166afa5f9d91be2738bdd9b +size 6068 diff --git a/data/ct/retailers-ct-2023-04-24T20-43-56.csv b/data/ct/retailers-ct-2023-04-24T20-43-56.csv new file mode 100644 index 0000000000000000000000000000000000000000..86bf388aae233901d431be0d1668af8c218b4c85 --- /dev/null +++ b/data/ct/retailers-ct-2023-04-24T20-43-56.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0968f03fce45c26f14fdfa9abbed8b40f3d69ad9166afa5f9d91be2738bdd9b +size 6068 diff --git a/data/ct/retailers-ct-2023-08-13T12-36-03.csv b/data/ct/retailers-ct-2023-08-13T12-36-03.csv new file mode 100644 index 0000000000000000000000000000000000000000..f40f357b60e133f997cb9d7b072049d9623bcb25 --- /dev/null +++ b/data/ct/retailers-ct-2023-08-13T12-36-03.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51f060d42334c341bae4e7056608fb2d3a7616add55106ea15c4e04fec920699 +size 6389 diff --git a/data/de/licenses-de-2023-04-30.csv b/data/de/licenses-de-2023-04-30.csv new file mode 100644 index 0000000000000000000000000000000000000000..8123fce00e2c9f2f96d59a0df3a9cc2739e56a15 --- /dev/null +++ b/data/de/licenses-de-2023-04-30.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:42a4563e4657e35bca4addae6be5d6407c981905a73caa40097aa86f163c8cbc +size 2824 diff --git a/data/de/licenses-de-2023-05-09 - Copy.csv b/data/de/licenses-de-2023-05-09 - Copy.csv new file mode 100644 index 0000000000000000000000000000000000000000..470df1095b5c448fc97487304d1c95ec2d1c15a3 --- /dev/null +++ b/data/de/licenses-de-2023-05-09 - Copy.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d0feb129d90530da212dac9969e4f380169d84769a67a3ea6957242607eb61d +size 2751 diff --git a/data/de/licenses-de-2023-05-09.csv b/data/de/licenses-de-2023-05-09.csv new file mode 100644 index 0000000000000000000000000000000000000000..470df1095b5c448fc97487304d1c95ec2d1c15a3 --- /dev/null +++ b/data/de/licenses-de-2023-05-09.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d0feb129d90530da212dac9969e4f380169d84769a67a3ea6957242607eb61d +size 2751 diff --git a/data/de/licenses-de-2023-06-06.csv b/data/de/licenses-de-2023-06-06.csv new file mode 100644 index 0000000000000000000000000000000000000000..08dd8cacf9988d94a8e367366032b54c0d6d67f7 --- /dev/null +++ b/data/de/licenses-de-2023-06-06.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8310e384031ba4af013da02eee3ed00ba33f0b5c15133f6605f14be308abf6d +size 2751 diff --git a/data/de/licenses-de-2023-08-13.csv b/data/de/licenses-de-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..f7763c269040ab4c84bc42023d84f6668b070ab5 --- /dev/null +++ b/data/de/licenses-de-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e16be3f25452f3b41f0738d11c5f3286776a39d326f2236b4554c45968c0763 +size 3050 diff --git a/data/de/licenses-de-latest.csv b/data/de/licenses-de-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..f7763c269040ab4c84bc42023d84f6668b070ab5 --- /dev/null +++ b/data/de/licenses-de-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0e16be3f25452f3b41f0738d11c5f3286776a39d326f2236b4554c45968c0763 +size 3050 diff --git a/data/fl/labs-fl-latest.csv b/data/fl/labs-fl-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..d562ed3b5218208bf65bebad7df624355c745863 --- /dev/null +++ b/data/fl/labs-fl-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:03a3b0c77236a31fc02184848b4ad8b8b956586d411c75f05f31ac8376bf609a +size 3378 diff --git a/data/il/licenses-il-2023-08-13T15-38-36.csv b/data/il/licenses-il-2023-08-13T15-38-36.csv new file mode 100644 index 0000000000000000000000000000000000000000..2202c029e89eb0552149c45272cf2a320dda3e62 --- /dev/null +++ b/data/il/licenses-il-2023-08-13T15-38-36.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:839f60a90704dec906a8d6243141244c613a74062ef9dfff5cf0fef80d72b3b8 +size 44464 diff --git a/data/il/licenses-il-latest.csv b/data/il/licenses-il-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..2202c029e89eb0552149c45272cf2a320dda3e62 --- /dev/null +++ b/data/il/licenses-il-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:839f60a90704dec906a8d6243141244c613a74062ef9dfff5cf0fef80d72b3b8 +size 44464 diff --git a/data/il/retailers-il-2023-04-24T20-59-24.csv b/data/il/retailers-il-2023-04-24T20-59-24.csv new file mode 100644 index 0000000000000000000000000000000000000000..0fcdc92332d19dcc53870133c59da491faefe227 --- /dev/null +++ b/data/il/retailers-il-2023-04-24T20-59-24.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:403f2ea05a1629b9e5681c902ce66d8fb0ab1fd43e1a53796d30f786c8bf6f1b +size 40211 diff --git a/data/il/retailers-il-2023-04-24T21-11-07 - Copy.csv b/data/il/retailers-il-2023-04-24T21-11-07 - Copy.csv new file mode 100644 index 0000000000000000000000000000000000000000..0fcdc92332d19dcc53870133c59da491faefe227 --- /dev/null +++ b/data/il/retailers-il-2023-04-24T21-11-07 - Copy.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:403f2ea05a1629b9e5681c902ce66d8fb0ab1fd43e1a53796d30f786c8bf6f1b +size 40211 diff --git a/data/il/retailers-il-2023-04-24T21-11-07.csv b/data/il/retailers-il-2023-04-24T21-11-07.csv new file mode 100644 index 0000000000000000000000000000000000000000..0fcdc92332d19dcc53870133c59da491faefe227 --- /dev/null +++ b/data/il/retailers-il-2023-04-24T21-11-07.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:403f2ea05a1629b9e5681c902ce66d8fb0ab1fd43e1a53796d30f786c8bf6f1b +size 40211 diff --git a/data/il/retailers-il-2023-08-13T15-38-36.csv b/data/il/retailers-il-2023-08-13T15-38-36.csv new file mode 100644 index 0000000000000000000000000000000000000000..2202c029e89eb0552149c45272cf2a320dda3e62 --- /dev/null +++ b/data/il/retailers-il-2023-08-13T15-38-36.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:839f60a90704dec906a8d6243141244c613a74062ef9dfff5cf0fef80d72b3b8 +size 44464 diff --git a/data/ma/licenses-ma-2023-04-24T21-11-12.csv b/data/ma/licenses-ma-2023-04-24T21-11-12.csv new file mode 100644 index 0000000000000000000000000000000000000000..488712031881cecbe19d023718cdfb2aa673dee1 --- /dev/null +++ b/data/ma/licenses-ma-2023-04-24T21-11-12.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:22be7274404af9a21b689c18279bbcdeb88d32a779812032f2a2b813b36e8b61 +size 1078479 diff --git a/data/ma/licenses-ma-2023-05-09 - Copy.csv b/data/ma/licenses-ma-2023-05-09 - Copy.csv new file mode 100644 index 0000000000000000000000000000000000000000..e0191d93e4563001ae9c63cfee9530e9957f6cd1 --- /dev/null +++ b/data/ma/licenses-ma-2023-05-09 - Copy.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a15b2cbde4fd62f1b050b5c82dcee7bfc4bc587298424f5eac34ff5892fed309 +size 1087031 diff --git a/data/ma/licenses-ma-2023-05-09.csv b/data/ma/licenses-ma-2023-05-09.csv new file mode 100644 index 0000000000000000000000000000000000000000..e0191d93e4563001ae9c63cfee9530e9957f6cd1 --- /dev/null +++ b/data/ma/licenses-ma-2023-05-09.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a15b2cbde4fd62f1b050b5c82dcee7bfc4bc587298424f5eac34ff5892fed309 +size 1087031 diff --git a/data/ma/licenses-ma-2023-06-06.csv b/data/ma/licenses-ma-2023-06-06.csv new file mode 100644 index 0000000000000000000000000000000000000000..62b2ac86b29c591a741fb076117a667daeac4a28 --- /dev/null +++ b/data/ma/licenses-ma-2023-06-06.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ea83754e0ec041392766bbd868c94e1dc366c8dd114917549b1dee374d2fee97 +size 1094409 diff --git a/data/ma/licenses-ma-2023-08-13T13-35-31.csv b/data/ma/licenses-ma-2023-08-13T13-35-31.csv new file mode 100644 index 0000000000000000000000000000000000000000..220be32ef9fb4252f04085dfba24e5d07bbce1f0 --- /dev/null +++ b/data/ma/licenses-ma-2023-08-13T13-35-31.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:76eaa15b04a29c26bb60754d728e54cfe87ac15a605234cc62de3cdb3ec33b42 +size 1438124 diff --git a/data/ma/licenses-ma-2023-09-19.csv b/data/ma/licenses-ma-2023-09-19.csv new file mode 100644 index 0000000000000000000000000000000000000000..49127099cf5c524e3f4b95b9619db2e49bc1f695 --- /dev/null +++ b/data/ma/licenses-ma-2023-09-19.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1932a2411e05dbcffe190f98ac2733d9e3c1a370698571dcc7472ce7ada044d1 +size 1346042 diff --git a/data/ma/licenses-ma-latest.csv b/data/ma/licenses-ma-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..cee94a47b6aeb2dbbad73a20f349a756ea2df4c5 --- /dev/null +++ b/data/ma/licenses-ma-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:618265af52773ed07494c54fa857555ba4bda7177754da28dd7f71126ed7f44e +size 1541459 diff --git a/data/ma/retailers-ma-2023-04-24T21-11-12.csv b/data/ma/retailers-ma-2023-04-24T21-11-12.csv new file mode 100644 index 0000000000000000000000000000000000000000..a56f8063d4bdeb3027402cec85dc527c46029143 --- /dev/null +++ b/data/ma/retailers-ma-2023-04-24T21-11-12.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81e296103a55302af22413b19c50d8d5c939b8374641579ad97b8d6a83c88396 +size 364886 diff --git a/data/ma/retailers-ma-2023-08-13T13-35-31.csv b/data/ma/retailers-ma-2023-08-13T13-35-31.csv new file mode 100644 index 0000000000000000000000000000000000000000..29a21b0676c6c960b467bd2fbb47dfd719de8c49 --- /dev/null +++ b/data/ma/retailers-ma-2023-08-13T13-35-31.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:006bc5b663d481b88ca03aef8a615fa70b02b92956574dddc01c0e77be2f3fb8 +size 488451 diff --git a/data/ma/retailers-ma-2023-09-19.csv b/data/ma/retailers-ma-2023-09-19.csv new file mode 100644 index 0000000000000000000000000000000000000000..40d9b27a097e996b321b50a6acb2b3ad41f1c9e5 --- /dev/null +++ b/data/ma/retailers-ma-2023-09-19.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e9332602e5d0295eae2148abf0ba5e4c40398eafc0f00cea2646da9ebbfb9701 +size 465714 diff --git a/data/md/licenses-md-2023-05-09.csv b/data/md/licenses-md-2023-05-09.csv new file mode 100644 index 0000000000000000000000000000000000000000..b188f3df4935907a92eb5540f559520eb91cbae7 --- /dev/null +++ b/data/md/licenses-md-2023-05-09.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2b61c4b6bc1b1eda3966bc9d01664517e40627dff38a00371bb10cca1db293bd +size 21922 diff --git a/data/md/licenses-md-2023-06-06.csv b/data/md/licenses-md-2023-06-06.csv new file mode 100644 index 0000000000000000000000000000000000000000..95b20c1a292ce67f5fc93b0e9d68e556c529add8 --- /dev/null +++ b/data/md/licenses-md-2023-06-06.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4a2dd05c68b60fa526d50b772ae1309e93a0cc99b08d1e8b93ee8b33bbe99e8 +size 21922 diff --git a/data/md/licenses-md-2023-08-13.csv b/data/md/licenses-md-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..3b862b308f653aafff6a4b54a69feef261938ec4 --- /dev/null +++ b/data/md/licenses-md-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3524d179fa02ab5d30d6e5696678728bc18459d8f796645d6e6f78ac4b1a0a34 +size 18486 diff --git a/data/md/licenses-md-latest.csv b/data/md/licenses-md-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..3b862b308f653aafff6a4b54a69feef261938ec4 --- /dev/null +++ b/data/md/licenses-md-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3524d179fa02ab5d30d6e5696678728bc18459d8f796645d6e6f78ac4b1a0a34 +size 18486 diff --git a/data/md/retailers-md-2023-04-25T18-02-02.csv b/data/md/retailers-md-2023-04-25T18-02-02.csv new file mode 100644 index 0000000000000000000000000000000000000000..49d405c352a904d74230ffbf63ac510d2f0f1bbd --- /dev/null +++ b/data/md/retailers-md-2023-04-25T18-02-02.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e1b7900e0c3f6a3dfbefb212d06c058ce53aeb36cc40a99be6f118a9219d7fb +size 19231 diff --git a/data/md/retailers-md-2023-04-30.csv b/data/md/retailers-md-2023-04-30.csv new file mode 100644 index 0000000000000000000000000000000000000000..00e3a237ff1d2de5ad606159c69135c4d32485d1 --- /dev/null +++ b/data/md/retailers-md-2023-04-30.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2d1c8a3b113a090272a5fd94f108fca38d3e42a9aee0447cd3c90416d389aa29 +size 24298 diff --git a/data/md/retailers-md-2023-04-30T14-28-18.csv b/data/md/retailers-md-2023-04-30T14-28-18.csv new file mode 100644 index 0000000000000000000000000000000000000000..500a6b699af76ce94577c3cfbdfa3a67aa377775 --- /dev/null +++ b/data/md/retailers-md-2023-04-30T14-28-18.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7dc6223da8a582593b4574e5227584d8e9bd45e3e0be0b7708178a67b37346db +size 19231 diff --git a/data/md/retailers-md-2023-08-13.csv b/data/md/retailers-md-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..3b862b308f653aafff6a4b54a69feef261938ec4 --- /dev/null +++ b/data/md/retailers-md-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3524d179fa02ab5d30d6e5696678728bc18459d8f796645d6e6f78ac4b1a0a34 +size 18486 diff --git a/data/me/licenses-me-2023-04-25T10-10-41.csv b/data/me/licenses-me-2023-04-25T10-10-41.csv new file mode 100644 index 0000000000000000000000000000000000000000..209d210bf4c0d0203e286500983f41a55360c5d7 --- /dev/null +++ b/data/me/licenses-me-2023-04-25T10-10-41.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1262fe1e7a03bfe254b1d459e0309b051a0d737f300d5e2227c7b419628c0541 +size 117126 diff --git a/data/me/licenses-me-2023-08-13T13-36-36.csv b/data/me/licenses-me-2023-08-13T13-36-36.csv new file mode 100644 index 0000000000000000000000000000000000000000..09d313314df613eb7874930c7f988672f3adc501 --- /dev/null +++ b/data/me/licenses-me-2023-08-13T13-36-36.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d7a00813eff4164145812d691b56fd3da83690b78511d349ae839d973b949b14 +size 121897 diff --git a/data/me/licenses-me-latest.csv b/data/me/licenses-me-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..09d313314df613eb7874930c7f988672f3adc501 --- /dev/null +++ b/data/me/licenses-me-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d7a00813eff4164145812d691b56fd3da83690b78511d349ae839d973b949b14 +size 121897 diff --git a/data/mi/licenses-mi-2023-04-25T10-18-37.csv b/data/mi/licenses-mi-2023-04-25T10-18-37.csv new file mode 100644 index 0000000000000000000000000000000000000000..e013d70b41fab18816d52cd305c1453d617d3e24 --- /dev/null +++ b/data/mi/licenses-mi-2023-04-25T10-18-37.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f445a510ec88c28178cdab73058aa9e6451d20d20dc23568f103cd1985b24e30 +size 52532 diff --git a/data/mi/licenses-mi-2023-08-13T13-37-51.csv b/data/mi/licenses-mi-2023-08-13T13-37-51.csv new file mode 100644 index 0000000000000000000000000000000000000000..c0d772269860c55e6e3e9c3862a58e1d1e00798d --- /dev/null +++ b/data/mi/licenses-mi-2023-08-13T13-37-51.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0123594d67ff10fdca1e00e5b86ba7253d05f2a34270dcce575b0f176517c88d +size 55509 diff --git a/data/mi/licenses-mi-latest.csv b/data/mi/licenses-mi-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..c0d772269860c55e6e3e9c3862a58e1d1e00798d --- /dev/null +++ b/data/mi/licenses-mi-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0123594d67ff10fdca1e00e5b86ba7253d05f2a34270dcce575b0f176517c88d +size 55509 diff --git a/data/mo/cultivation-mo-2023-04-26T16-27-41.csv b/data/mo/cultivation-mo-2023-04-26T16-27-41.csv new file mode 100644 index 0000000000000000000000000000000000000000..14339cf576f8fa44a9d5b775fd66ab28adbf85af --- /dev/null +++ b/data/mo/cultivation-mo-2023-04-26T16-27-41.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7597eae0c51de16dfde8f85db1494186c6f3a4c77e5c9299f0cb5e0e737f2f12 +size 13144 diff --git a/data/mo/cultivation-mo-2023-04-27.csv b/data/mo/cultivation-mo-2023-04-27.csv new file mode 100644 index 0000000000000000000000000000000000000000..c81f721b9aec1c9a29ff84bb5040a27aa2f2a515 --- /dev/null +++ b/data/mo/cultivation-mo-2023-04-27.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:060c18aadd867fe56f6b7ba36e57dc9dc1be37246af7ed1246aa8c11dc5d9a16 +size 16680 diff --git a/data/mo/cultivation-mo-2023-08-13.csv b/data/mo/cultivation-mo-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..9d5e77b9552d207fa7c47cc19b0f2ace03984018 --- /dev/null +++ b/data/mo/cultivation-mo-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a2608c1ca4ba34652abbf0f79cf8c3148e0fa8f6e5fbff5c6b6a84b10b2ca042 +size 19628 diff --git a/data/mo/dispensary-mo-2023-04-27.csv b/data/mo/dispensary-mo-2023-04-27.csv new file mode 100644 index 0000000000000000000000000000000000000000..f7acf9459f73efea8eb5ccf89e654751d77af22e --- /dev/null +++ b/data/mo/dispensary-mo-2023-04-27.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29821b67d275178df0615905024409a00877c47b854715cf8c3fdff8fad5ba60 +size 54224 diff --git a/data/mo/dispensary-mo-2023-08-13.csv b/data/mo/dispensary-mo-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..84bd06f61da44584dffa90141e26e5b3f99c85c8 --- /dev/null +++ b/data/mo/dispensary-mo-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47264b006c6ee15125a8ea72e415463360f44a9f06afc78aa9c153b5f2ab2a6c +size 64000 diff --git a/data/mo/infused-product-manufacturing-mo-2023-04-27.csv b/data/mo/infused-product-manufacturing-mo-2023-04-27.csv new file mode 100644 index 0000000000000000000000000000000000000000..87ed288e16379de9b7c379d24992b2cb71531b63 --- /dev/null +++ b/data/mo/infused-product-manufacturing-mo-2023-04-27.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:117ed182b9a5476cf94c65c23b1880dded9a6493846c5722e704201ff062b2c0 +size 22947 diff --git a/data/mo/infused-product-manufacturing-mo-2023-08-13.csv b/data/mo/infused-product-manufacturing-mo-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..b163ab2894622528a41798c21976911eb939d802 --- /dev/null +++ b/data/mo/infused-product-manufacturing-mo-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5da5cf748ebc73038f1a54fe9e112b67f8ce18f92c202a214d491d43fd3b3bc3 +size 28580 diff --git a/data/mo/laboratory-testing-mo-2023-04-27.csv b/data/mo/laboratory-testing-mo-2023-04-27.csv new file mode 100644 index 0000000000000000000000000000000000000000..9a013f3170f7c2321c861d1a8bdb9836f1c05240 --- /dev/null +++ b/data/mo/laboratory-testing-mo-2023-04-27.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:014cfb447975bdb8b9d7dbc969b6e566c52172c4d470dda95c08fd2f5ebb9807 +size 2892 diff --git a/data/mo/laboratory-testing-mo-2023-08-13.csv b/data/mo/laboratory-testing-mo-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..8f9a5e68d5d2329464a6f9adbd439731aa92fe23 --- /dev/null +++ b/data/mo/laboratory-testing-mo-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb3225ef7288bdb69c264bea2d522e19687dca377f8958eae9a801519c462337 +size 3429 diff --git a/data/mo/licenses-mo-2023-04-27.csv b/data/mo/licenses-mo-2023-04-27.csv new file mode 100644 index 0000000000000000000000000000000000000000..65471df2a4a8574cc9d802bcdce26ac9f6625248 --- /dev/null +++ b/data/mo/licenses-mo-2023-04-27.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70eecd39b478ce9f19ef97fe239559e9e3f423e6fae4029761889d659df97c0a +size 7808 diff --git a/data/mo/licenses-mo-2023-05-09.csv b/data/mo/licenses-mo-2023-05-09.csv new file mode 100644 index 0000000000000000000000000000000000000000..7405fa37d4cdfccc0babc61b4ca9fde737bca449 --- /dev/null +++ b/data/mo/licenses-mo-2023-05-09.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96413b122323dfa59dab2894c7369f13a0aac3ab8158ef199a75d9741effe4ea +size 123121 diff --git a/data/mo/licenses-mo-2023-08-13.csv b/data/mo/licenses-mo-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..148e7d16d334bfce6b36f10479134f09762ed3e5 --- /dev/null +++ b/data/mo/licenses-mo-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7219a356eca3d1041de27a03ed2ee148bd51a72845d0133038e241b613992488 +size 123711 diff --git a/data/mo/licenses-mo-latest.csv b/data/mo/licenses-mo-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..148e7d16d334bfce6b36f10479134f09762ed3e5 --- /dev/null +++ b/data/mo/licenses-mo-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7219a356eca3d1041de27a03ed2ee148bd51a72845d0133038e241b613992488 +size 123711 diff --git a/data/mo/transportation-mo-2023-04-27.csv b/data/mo/transportation-mo-2023-04-27.csv new file mode 100644 index 0000000000000000000000000000000000000000..65471df2a4a8574cc9d802bcdce26ac9f6625248 --- /dev/null +++ b/data/mo/transportation-mo-2023-04-27.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:70eecd39b478ce9f19ef97fe239559e9e3f423e6fae4029761889d659df97c0a +size 7808 diff --git a/data/mo/transportation-mo-2023-08-13.csv b/data/mo/transportation-mo-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..669c37414cea598381c46d5df83989b6a7914918 --- /dev/null +++ b/data/mo/transportation-mo-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f371762183d44d2731ed0aef23442fe26c07b33e0bd740159e1cc4f517e30e1d +size 9311 diff --git a/data/mt/licenses-mt-2023-08-13T17-29-48.csv b/data/mt/licenses-mt-2023-08-13T17-29-48.csv new file mode 100644 index 0000000000000000000000000000000000000000..e71ca3d97bac05f770334ddd68902815841d2f84 --- /dev/null +++ b/data/mt/licenses-mt-2023-08-13T17-29-48.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:681869f9c8aac70a109f6d6887d3a54ba53b4faf6d9df3b0171381a1565d9961 +size 117919 diff --git a/data/mt/licenses-mt-latest.csv b/data/mt/licenses-mt-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..e71ca3d97bac05f770334ddd68902815841d2f84 --- /dev/null +++ b/data/mt/licenses-mt-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:681869f9c8aac70a109f6d6887d3a54ba53b4faf6d9df3b0171381a1565d9961 +size 117919 diff --git a/data/mt/retailers-mt-2023-04-24T21-19-46.csv b/data/mt/retailers-mt-2023-04-24T21-19-46.csv new file mode 100644 index 0000000000000000000000000000000000000000..dffe21465dbdff09e2826f48b5ead4b928193db0 --- /dev/null +++ b/data/mt/retailers-mt-2023-04-24T21-19-46.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d9f7a7991363fe5b9f68490c58bfe2dacaca4a26d2041aebc823132e00a09e53 +size 116062 diff --git a/data/mt/retailers-mt-2023-08-13T17-29-48.csv b/data/mt/retailers-mt-2023-08-13T17-29-48.csv new file mode 100644 index 0000000000000000000000000000000000000000..e71ca3d97bac05f770334ddd68902815841d2f84 --- /dev/null +++ b/data/mt/retailers-mt-2023-08-13T17-29-48.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:681869f9c8aac70a109f6d6887d3a54ba53b4faf6d9df3b0171381a1565d9961 +size 117919 diff --git a/data/nj/licenses-nj-2023-04-24T16-35-40.csv b/data/nj/licenses-nj-2023-04-24T16-35-40.csv new file mode 100644 index 0000000000000000000000000000000000000000..a40359d1647d747048e4ae8fd5b0d2a3451428ef --- /dev/null +++ b/data/nj/licenses-nj-2023-04-24T16-35-40.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c152308b0a5d06a624df9303cb16e9408ba5a1ff9b5ec21cff52f3980459257e +size 7405 diff --git a/data/nj/licenses-nj-2023-05-09.csv b/data/nj/licenses-nj-2023-05-09.csv new file mode 100644 index 0000000000000000000000000000000000000000..4c7ca6e1e40977fa39db01dbc90506bccab75fc1 --- /dev/null +++ b/data/nj/licenses-nj-2023-05-09.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a81f02b0a81e79ca573f2cf2ca6e6aad4125191b73839987b92120c192256de +size 8204 diff --git a/data/nj/licenses-nj-2023-06-06.csv b/data/nj/licenses-nj-2023-06-06.csv new file mode 100644 index 0000000000000000000000000000000000000000..2405c31f531502ebe6829345ce64ea6f79ac979a --- /dev/null +++ b/data/nj/licenses-nj-2023-06-06.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5fa78e250174eea08a46ba47eb7d3f757d90807c0e0c3f1a4bb6f5b0b04cc96b +size 9033 diff --git a/data/nj/licenses-nj-2023-08-13T15-41-40.csv b/data/nj/licenses-nj-2023-08-13T15-41-40.csv new file mode 100644 index 0000000000000000000000000000000000000000..dddf511af1353a475073b52f9a02b43bedea85f3 --- /dev/null +++ b/data/nj/licenses-nj-2023-08-13T15-41-40.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc4b8604d76f8c9de588cde8869048b474373fa1e2d259220c9ab4936ea6c581 +size 10511 diff --git a/data/nj/licenses-nj-latest.csv b/data/nj/licenses-nj-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..dddf511af1353a475073b52f9a02b43bedea85f3 --- /dev/null +++ b/data/nj/licenses-nj-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc4b8604d76f8c9de588cde8869048b474373fa1e2d259220c9ab4936ea6c581 +size 10511 diff --git a/data/nm/licenses-nm-latest.csv b/data/nm/licenses-nm-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..e14bee9ad6a468b830d8f49f386fc161a980c35d --- /dev/null +++ b/data/nm/licenses-nm-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cbab0d3f6d748128672ad9573998e0e44af0e1b8954962fc126544c8655ca27f +size 143840 diff --git a/data/nm/retailers-nm-2023-04-30.csv b/data/nm/retailers-nm-2023-04-30.csv new file mode 100644 index 0000000000000000000000000000000000000000..e14bee9ad6a468b830d8f49f386fc161a980c35d --- /dev/null +++ b/data/nm/retailers-nm-2023-04-30.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cbab0d3f6d748128672ad9573998e0e44af0e1b8954962fc126544c8655ca27f +size 143840 diff --git a/data/nv/licenses-nv-2023-04-24T21-23-39.csv b/data/nv/licenses-nv-2023-04-24T21-23-39.csv new file mode 100644 index 0000000000000000000000000000000000000000..332d74dbd5040350f5008e82672f909bb1031d52 --- /dev/null +++ b/data/nv/licenses-nv-2023-04-24T21-23-39.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3dd9863d3f2cfbee2178b44156c72b1ea5ee6466b2220508b0245d7e9d25efd9 +size 149484 diff --git a/data/nv/licenses-nv-2023-04-25T08-03-44.csv b/data/nv/licenses-nv-2023-04-25T08-03-44.csv new file mode 100644 index 0000000000000000000000000000000000000000..332d74dbd5040350f5008e82672f909bb1031d52 --- /dev/null +++ b/data/nv/licenses-nv-2023-04-25T08-03-44.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3dd9863d3f2cfbee2178b44156c72b1ea5ee6466b2220508b0245d7e9d25efd9 +size 149484 diff --git a/data/nv/licenses-nv-2023-04-25T08-18-17.csv b/data/nv/licenses-nv-2023-04-25T08-18-17.csv new file mode 100644 index 0000000000000000000000000000000000000000..332d74dbd5040350f5008e82672f909bb1031d52 --- /dev/null +++ b/data/nv/licenses-nv-2023-04-25T08-18-17.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3dd9863d3f2cfbee2178b44156c72b1ea5ee6466b2220508b0245d7e9d25efd9 +size 149484 diff --git a/data/nv/licenses-nv-2023-08-13T12-36-41.csv b/data/nv/licenses-nv-2023-08-13T12-36-41.csv new file mode 100644 index 0000000000000000000000000000000000000000..48b5fd464443d96f25751a1132e3dbc94a87a410 --- /dev/null +++ b/data/nv/licenses-nv-2023-08-13T12-36-41.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8b7c6576ba2dd43fc86db0c468eb949eb75e9ceacf101e93c3a94add5225bb1 +size 146517 diff --git a/data/nv/licenses-nv-latest.csv b/data/nv/licenses-nv-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..48b5fd464443d96f25751a1132e3dbc94a87a410 --- /dev/null +++ b/data/nv/licenses-nv-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8b7c6576ba2dd43fc86db0c468eb949eb75e9ceacf101e93c3a94add5225bb1 +size 146517 diff --git a/data/nv/retailers-nv-2023-04-25T08-16-36.csv b/data/nv/retailers-nv-2023-04-25T08-16-36.csv new file mode 100644 index 0000000000000000000000000000000000000000..e8cbdd8b1347b35c119647e1a8366216f4697e60 --- /dev/null +++ b/data/nv/retailers-nv-2023-04-25T08-16-36.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b48aaa046a965201e9efa11b1810cbb094f7f18a1ded17798c120b05667f5fc8 +size 48796 diff --git a/data/nv/retailers-nv-2023-04-25T08-18-35.csv b/data/nv/retailers-nv-2023-04-25T08-18-35.csv new file mode 100644 index 0000000000000000000000000000000000000000..1268d90115b8d9270ccd1803fbd08ac795b4bd37 --- /dev/null +++ b/data/nv/retailers-nv-2023-04-25T08-18-35.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c83c634bc10b147a06635662dec788068b855b3d5525cb35a557d05d69cea816 +size 48796 diff --git a/data/nv/retailers-nv-2023-08-13T12-36-51.csv b/data/nv/retailers-nv-2023-08-13T12-36-51.csv new file mode 100644 index 0000000000000000000000000000000000000000..8e7b9f84cba550303d4cd2ea78679b92a83694ac --- /dev/null +++ b/data/nv/retailers-nv-2023-08-13T12-36-51.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fcf1918b8ca1f7f7bb997408819f208aafdff2a9f129471e4aee3982883f0b6b +size 49816 diff --git a/data/nv/retailers-nv-latest.csv b/data/nv/retailers-nv-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..8e7b9f84cba550303d4cd2ea78679b92a83694ac --- /dev/null +++ b/data/nv/retailers-nv-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fcf1918b8ca1f7f7bb997408819f208aafdff2a9f129471e4aee3982883f0b6b +size 49816 diff --git a/data/ny/labs-ny-2023-05-01.csv b/data/ny/labs-ny-2023-05-01.csv new file mode 100644 index 0000000000000000000000000000000000000000..8de149dabed0e46c4894570bd02a07f7678550d0 --- /dev/null +++ b/data/ny/labs-ny-2023-05-01.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2025c570aa6a7f5a2924a63c13091961bc25a2b9ae0a888446c35d852f895abf +size 4455 diff --git a/data/ny/labs-ny-2023-08-13.csv b/data/ny/labs-ny-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..8fa01c0a09ce3057acb66deccee45bce968fe575 --- /dev/null +++ b/data/ny/labs-ny-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0373df737e671f8b7c79b4c96c740f0697556a9a2a06556e95960cf423094a0e +size 4357 diff --git a/data/ny/labs-ny-2023-09-20.csv b/data/ny/labs-ny-2023-09-20.csv new file mode 100644 index 0000000000000000000000000000000000000000..5e75d9c34229c5377a7ead8a603735511c02aa16 --- /dev/null +++ b/data/ny/labs-ny-2023-09-20.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e2627001dff6b118141f0e0dd1e1aa87164799a2366738f044a62d330676b32 +size 5437 diff --git a/data/ny/licenses-ny-2023-08-13.csv b/data/ny/licenses-ny-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..37eaff70bd878cd59e9afc665516b4313085b9b7 --- /dev/null +++ b/data/ny/licenses-ny-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:762993d9198b51b4f28089cd478d855a1cab01205e27b69feaa10621a3c1b468 +size 96818 diff --git a/data/ny/licenses-ny-2023-09-20.csv b/data/ny/licenses-ny-2023-09-20.csv new file mode 100644 index 0000000000000000000000000000000000000000..35eceb02a289e495aed5f3137513b0cb21255d5e --- /dev/null +++ b/data/ny/licenses-ny-2023-09-20.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b379c14bf566a200ce4ed541aa09e7803a783ad3c4285cb6c412c401d1d26970 +size 101993 diff --git a/data/ny/licenses-ny-latest.csv b/data/ny/licenses-ny-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..35eceb02a289e495aed5f3137513b0cb21255d5e --- /dev/null +++ b/data/ny/licenses-ny-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b379c14bf566a200ce4ed541aa09e7803a783ad3c4285cb6c412c401d1d26970 +size 101993 diff --git a/data/ny/retailers-ny-2023-08-13.csv b/data/ny/retailers-ny-2023-08-13.csv new file mode 100644 index 0000000000000000000000000000000000000000..c5c6e272e905dc34640ab3ac2cc798b4ac497208 --- /dev/null +++ b/data/ny/retailers-ny-2023-08-13.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c5416fdc6d0203a395eaa1de6b21200ca6c3bdd464f92803f91fb24598a8cd2 +size 81560 diff --git a/data/ny/retailers-ny-2023-09-20.csv b/data/ny/retailers-ny-2023-09-20.csv new file mode 100644 index 0000000000000000000000000000000000000000..1fefa8aa15b8a8f42a39e22bc379d6a6232c4c66 --- /dev/null +++ b/data/ny/retailers-ny-2023-09-20.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6a162b63b564c3088ca35198a237274e463e7be806121ec7d11eb764e6422ca8 +size 83620 diff --git a/data/or/licenses-or-2023-04-24T21-23-17.csv b/data/or/licenses-or-2023-04-24T21-23-17.csv new file mode 100644 index 0000000000000000000000000000000000000000..9d6f0927bfdde298370e7bd3bd876341b911773b --- /dev/null +++ b/data/or/licenses-or-2023-04-24T21-23-17.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:370d9bf8dbd18e8ac747f41bf4634147d859a085d0af45347dc57dbce6066e23 +size 211830 diff --git a/data/or/licenses-or-2023-08-13T15-57-04.csv b/data/or/licenses-or-2023-08-13T15-57-04.csv new file mode 100644 index 0000000000000000000000000000000000000000..bc2ab9bf44b9115ba17a169de2fca691574054a9 --- /dev/null +++ b/data/or/licenses-or-2023-08-13T15-57-04.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9353ebfa04396054fcb861ec558aed25f96247070ae2d847d521d7e711f56071 +size 212553 diff --git a/data/or/licenses-or-latest.csv b/data/or/licenses-or-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..bc2ab9bf44b9115ba17a169de2fca691574054a9 --- /dev/null +++ b/data/or/licenses-or-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9353ebfa04396054fcb861ec558aed25f96247070ae2d847d521d7e711f56071 +size 212553 diff --git a/data/ri/licenses-ri-2023-04-25T08-38-11.csv b/data/ri/licenses-ri-2023-04-25T08-38-11.csv new file mode 100644 index 0000000000000000000000000000000000000000..f469620bfe6679c90ec496ec0e77350b062778c4 --- /dev/null +++ b/data/ri/licenses-ri-2023-04-25T08-38-11.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7cc991a473d002607953989df6abdb4b1cdbdf23a0d93b534bc8f402d1bf5119 +size 2928 diff --git a/data/ri/licenses-ri-2023-08-13T13-38-29.csv b/data/ri/licenses-ri-2023-08-13T13-38-29.csv new file mode 100644 index 0000000000000000000000000000000000000000..560c6732e88bb236918bb0852d41d39fe8fc6faa --- /dev/null +++ b/data/ri/licenses-ri-2023-08-13T13-38-29.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:77841014e4aad20ea8e33707c3869e6866a6772b85e6376f29a6da6e8a107b1c +size 2928 diff --git a/data/ri/licenses-ri-latest.csv b/data/ri/licenses-ri-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..560c6732e88bb236918bb0852d41d39fe8fc6faa --- /dev/null +++ b/data/ri/licenses-ri-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:77841014e4aad20ea8e33707c3869e6866a6772b85e6376f29a6da6e8a107b1c +size 2928 diff --git a/data/vt/licenses-vt-2023-04-25T08-25-46.csv b/data/vt/licenses-vt-2023-04-25T08-25-46.csv new file mode 100644 index 0000000000000000000000000000000000000000..1e8e47ebddb0489732fca2ad22fe3aa2cdad41f1 --- /dev/null +++ b/data/vt/licenses-vt-2023-04-25T08-25-46.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:442590296234ba2ad6bd60a95bda862b23cc15ed1f01181cc1d9e65b088e2e88 +size 76064 diff --git a/data/vt/licenses-vt-2023-08-13T13-39-14.csv b/data/vt/licenses-vt-2023-08-13T13-39-14.csv new file mode 100644 index 0000000000000000000000000000000000000000..79426704a598887c80034ec0c88e4b19857d1114 --- /dev/null +++ b/data/vt/licenses-vt-2023-08-13T13-39-14.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad8d7887bdfc6a2f4b4c8ce7ee51c8f1e29fd044a511d481a9a84c44361ff91d +size 85569 diff --git a/data/vt/licenses-vt-2023-08-13T15-35-18.csv b/data/vt/licenses-vt-2023-08-13T15-35-18.csv new file mode 100644 index 0000000000000000000000000000000000000000..0e6acac1e3bcc76070668ae32f4ac7fcc7d29569 --- /dev/null +++ b/data/vt/licenses-vt-2023-08-13T15-35-18.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a13c7dcc75138aeec1ce2ace4c60852445c51f4338e408bbd20f1afda87eb2a9 +size 85569 diff --git a/data/vt/licenses-vt-latest.csv b/data/vt/licenses-vt-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..0e6acac1e3bcc76070668ae32f4ac7fcc7d29569 --- /dev/null +++ b/data/vt/licenses-vt-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a13c7dcc75138aeec1ce2ace4c60852445c51f4338e408bbd20f1afda87eb2a9 +size 85569 diff --git a/data/vt/retailers-vt-2023-04-25T08-25-46.csv b/data/vt/retailers-vt-2023-04-25T08-25-46.csv new file mode 100644 index 0000000000000000000000000000000000000000..4ef1042b7a5a49bddb61fcee92b7ee5bb541a7b7 --- /dev/null +++ b/data/vt/retailers-vt-2023-04-25T08-25-46.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:84554163b9dae0f48e128303a0a658b57f1217b4b0e187921ec414e9a6e80384 +size 473 diff --git a/data/vt/retailers-vt-2023-08-13T13-39-14.csv b/data/vt/retailers-vt-2023-08-13T13-39-14.csv new file mode 100644 index 0000000000000000000000000000000000000000..6942fa91aeb6a66cb0bba59e1331c9e88b8a7839 --- /dev/null +++ b/data/vt/retailers-vt-2023-08-13T13-39-14.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f1902ab96d32dc32aa77d3829102927ccd80d08129d08ac026e481d59fa287f +size 455 diff --git a/data/vt/retailers-vt-2023-08-13T15-35-18.csv b/data/vt/retailers-vt-2023-08-13T15-35-18.csv new file mode 100644 index 0000000000000000000000000000000000000000..6942fa91aeb6a66cb0bba59e1331c9e88b8a7839 --- /dev/null +++ b/data/vt/retailers-vt-2023-08-13T15-35-18.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5f1902ab96d32dc32aa77d3829102927ccd80d08129d08ac026e481d59fa287f +size 455 diff --git a/data/wa/labs-wa-2023-04-24T21-21-31.csv b/data/wa/labs-wa-2023-04-24T21-21-31.csv new file mode 100644 index 0000000000000000000000000000000000000000..b631711a4ca275b77171086afacb75f9907c76b9 --- /dev/null +++ b/data/wa/labs-wa-2023-04-24T21-21-31.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf38d84ab6bf45c532de9cf96cc44ed2383bba7150f4b131858c552e8576cd48 +size 735 diff --git a/data/wa/labs-wa-2023-08-09T06-49-02.csv b/data/wa/labs-wa-2023-08-09T06-49-02.csv new file mode 100644 index 0000000000000000000000000000000000000000..7ef97c13455b99a1a29c3eb8a09a03c6eefeb7c0 --- /dev/null +++ b/data/wa/labs-wa-2023-08-09T06-49-02.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad0cc9d525a29a46cd79d88f06ddcc751ce6c5a321e921abe7d3b4fb35f78c0c +size 735 diff --git a/data/wa/licenses-wa-2023-04-24T21-21-31.csv b/data/wa/licenses-wa-2023-04-24T21-21-31.csv new file mode 100644 index 0000000000000000000000000000000000000000..bf1fb1b761d194178ea1015bc8ce2c3f83d140e5 --- /dev/null +++ b/data/wa/licenses-wa-2023-04-24T21-21-31.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b6f136f9f96c1ca93baaf0ade26c237a0a6749bfc6133c497956a2b3fd9d8aa +size 223305 diff --git a/data/wa/licenses-wa-2023-08-09T06-49-02.csv b/data/wa/licenses-wa-2023-08-09T06-49-02.csv new file mode 100644 index 0000000000000000000000000000000000000000..30e01c867abbc7b1ad788ca41019d2c2ea1ddff3 --- /dev/null +++ b/data/wa/licenses-wa-2023-08-09T06-49-02.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14c6759ad628ad1d37e099696a775b5cf105b34812e42e642ac0d6075116122d +size 223221 diff --git a/data/wa/licenses-wa-latest.csv b/data/wa/licenses-wa-latest.csv new file mode 100644 index 0000000000000000000000000000000000000000..30e01c867abbc7b1ad788ca41019d2c2ea1ddff3 --- /dev/null +++ b/data/wa/licenses-wa-latest.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14c6759ad628ad1d37e099696a775b5cf105b34812e42e642ac0d6075116122d +size 223221 diff --git a/data/wa/retailers-wa-2023-04-24T21-21-31.csv b/data/wa/retailers-wa-2023-04-24T21-21-31.csv new file mode 100644 index 0000000000000000000000000000000000000000..9ec694cd10433220e1fceefa1d77cdeffe938ea5 --- /dev/null +++ b/data/wa/retailers-wa-2023-04-24T21-21-31.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:19a5a17e20c55c9bd9106599dc0eb225d29fe67a31b85a94487f5398966ae7b0 +size 148477 diff --git a/data/wa/retailers-wa-2023-08-09T06-49-02.csv b/data/wa/retailers-wa-2023-08-09T06-49-02.csv new file mode 100644 index 0000000000000000000000000000000000000000..b9e0c07fce13774fbd8819d1901940c12061c2b1 --- /dev/null +++ b/data/wa/retailers-wa-2023-08-09T06-49-02.csv @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0503f579896491de8e3776d0775bc9959a3e4ef9ab0e3fa387ce3f57ba066a65 +size 149724 diff --git a/subsets.json b/subsets.json deleted file mode 100644 index d481a252981645b082595359518bbbf257d9ee1c..0000000000000000000000000000000000000000 --- a/subsets.json +++ /dev/null @@ -1,110 +0,0 @@ -{ - "all": { - "name": "all", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/main.py", - "data_source": "", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/all/licenses-2022-10-08T14-03-08.csv" - }, - "ak": { - "name": "ak", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_ak.py", - "data_source": "https://www.commerce.alaska.gov/abc/marijuana/Home/licensesearch", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/ak/retailers-ak-2022-10-06T17-46-29.csv" - }, - "az": { - "name": "az", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_az.py", - "data_source": "https://azcarecheck.azdhs.gov/s/?licenseType=null", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/az/retailers-az-2022-10-07T10-12-07.csv" - }, - "ca": { - "name": "ca", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_ca.py", - "data_source": "https://search.cannabis.ca.gov/", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/ca/licenses-ca-2022-10-06T18-10-15.csv" - }, - "co": { - "name": "co", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_co.py", - "data_source": "https://sbg.colorado.gov/med/licensed-facilities", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/co/retailers-co-2022-10-06T18-28-29.csv" - }, - "ct": { - "name": "ct", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_ct.py", - "data_source": "https://portal.ct.gov/DCP/Medical-Marijuana-Program/Connecticut-Medical-Marijuana-Dispensary-Facilities", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/ct/retailers-ct-2022-10-06T18-28-33.csv" - }, - "il": { - "name": "il", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_il.py", - "data_source": "https://www.idfpr.com/LicenseLookup/AdultUseDispensaries.pdf", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/il/retailers-il-2022-10-06T18-28-55.csv" - }, - "ma": { - "name": "ma", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_ma.py", - "data_source": "https://masscannabiscontrol.com/open-data/data-catalog/", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/ma/retailers-ma-2022-10-07T14-45-39.csv" - }, - "me": { - "name": "me", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_me.py", - "data_source": "https://www.maine.gov/dafs/ocp/open-https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/adult-use", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/me/licenses-me-2022-10-07T15-26-01.csv" - }, - "mi": { - "name": "mi", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_mi.py", - "data_source": "https://michigan.maps.arcgis.com/apps/webappviewer/index.html?id=cd5a1a76daaf470b823a382691c0ff60", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/mi/licenses-mi-2022-10-08T13-49-04.csv" - }, - "mt": { - "name": "mt", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_mt.py", - "data_source": "https://mtrevenue.gov/cannabis/#CannabisLicenses", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/mt/retailers-mt-2022-10-07T16-28-10.csv" - }, - "nj": { - "name": "nj", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_nj.py", - "data_source": "https://data.nj.gov/stories/s/ggm4-mprw", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/nj/licenses-nj-2022-10-06T18-39-17.csv" - }, - "nm": { - "name": "nm", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_nm.py", - "data_source": "https://nmrldlpi.force.com/bcd/s/public-search-license?division=CCD&language=en_US", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/nm/retailers-nm-2022-10-05T15-09-21.csv" - }, - "nv": { - "name": "nv", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_nv.py", - "data_source": "https://ccb.nv.gov/list-of-licensees/", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/nv/retailers-nv-2022-10-06T18-43-01.csv" - }, - "or": { - "name": "or", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_ca.py", - "data_source": "https://www.oregon.gov/olcc/marijuana/pages/recreational-marijuana-licensing.aspx", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/or/licenses-or-2022-10-07T14-47-55.csv" - }, - "ri": { - "name": "ri", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_ri.py", - "data_source": "https://dbr.ri.gov/office-cannabis-regulation/compassion-centers/licensed-compassion-centers", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/ri/licenses-ri-2022-10-06T18-45-41.csv" - }, - "vt": { - "name": "vt", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_vt.py", - "data_source": "https://ccb.vermont.gov/licenses", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/vt/retailers-vt-2022-10-06T18-46-08.csv" - }, - "wa": { - "name": "wa", - "url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/algorithms/get_licenses_wa.py", - "data_source": "https://lcb.wa.gov/records/frequently-requested-lists", - "data_url": "https://huggingface.co/datasets/cannlytics/cannabis_licenses/resolve/main/data/wa/retailers-wa-2022-10-07T09-06-02.csv" - } -} diff --git a/upload_licenses.py b/upload_licenses.py new file mode 100644 index 0000000000000000000000000000000000000000..c8901f96319d1519ca9f6267061ccc36b82e12e7 --- /dev/null +++ b/upload_licenses.py @@ -0,0 +1,192 @@ +""" +Upload Cannabis License Data +Copyright (c) 2023 Cannlytics +Copyright (c) 2022-2023 Cannabis Data + +Authors: + Keegan Skeate +Created: 11/29/2022 +Updated: 5/15/2023 +License: + +Original author: Cannabis Data +Original license: MIT + +Data Source: + + - Cannabis Licenses + URL: + +Command-line Usage: + + python data/archive/upload_licenses.py all + +""" +# Standard imports: +import math +import os +from typing import Dict, List, Union + +import pandas as pd + +# External imports: +from cannlytics.data import create_hash +from cannlytics import firebase +from cannlytics.utils.constants import states +from datasets import load_dataset +from dotenv import dotenv_values + + +def replace_nan_with_none(data: Union[Dict, List[Dict], pd.DataFrame]) -> Union[Dict, List[Dict], pd.DataFrame]: + """Replace NaN values with None values in a dictionary, list of dictionaries, or DataFrame.""" + + # If data is a dictionary + if isinstance(data, dict): + return {k: (v if not (isinstance(v, float) and math.isnan(v)) else None) for k, v in data.items()} + + # If data is a list of dictionaries + elif isinstance(data, list) and all(isinstance(item, dict) for item in data): + return [{k: (v if not (isinstance(v, float) and math.isnan(v)) else None) for k, v in item.items()} for item in data] + + # If data is a pandas DataFrame + elif isinstance(data, pd.DataFrame): + return data.where(pd.notnull(data), None) + + else: + raise TypeError("Input should be a dictionary, a list of dictionaries, or a pandas DataFrame") + + + + +def upload_cannabis_licenses_datafiles( + bucket_name, + storage_ref: str = 'data/licenses', + verbose: bool = True, + ) -> List[str]: + """Upload cannabis license datafiles to Firebase Storage. + Args: + storage_ref (str): The Firebase Storage reference for the datafiles. + """ + + # Initialize Firebase. + firebase.initialize_firebase() + + # Get datafiles. + datafiles = [] + for root, _, files in os.walk('./cannabis_licenses/'): + for file in files: + if file.endswith('latest.csv'): + datafiles.append(os.path.join(root, file)) + + # Format the storage references. + refs = [storage_ref + x.split('./cannabis_licenses/data')[-1] for x in datafiles] + refs = [x.replace('\\', '/') for x in refs] + + # Upload datafiles to Firebase Storage. + for i, datafile in enumerate(datafiles): + ref = refs[i] + firebase.upload_file(ref, datafile, bucket_name=bucket_name) + if verbose: + print(f'Uploaded latest: {ref}') + + # Return the references. + return refs + + +def upload_cannabis_licenses( + subset: str = 'all', + col: str = 'data/licenses', + repo: str = 'cannlytics/cannabis_licenses', + verbose: bool = True, + ): + """Get cannabis license data from Hugging Face and upload the data + to Firestore. + Args: + subset (str): The subset of the Hugging Face data, `all` by default. + col (str): The Firestore base document where the data should be saved. + repo (str): The Hugging Face dataset repository. + doc_id (str): How to create a document ID, a `hex`, `uuid`, or + the field of the document to use. + verbose (bool): Whether to print out progress. + """ + + # Initialize Firebase. + db = firebase.initialize_firebase() + + # Get the data from local storage. + try: + data = pd.read_csv('./cannabis_licenses/data/all/licenses-all-latest.csv') + + # Otherwise get the data from Hugging Face. + except: + dataset = load_dataset(repo, subset) + data = dataset['data'].to_pandas() + + # Compile the references and documents. + refs, docs = [], [] + data['id'] = data['license_number'].fillna(data['id']).apply(str) + data = data.loc[data['id'].notnull()] + state_names = [x.lower() for x in states.keys()] + for index, row in data.iterrows(): + + # Format the document and collection IDs + doc_id = row['id'] + collection_id = row['premise_state'].lower() + + # FIXME: Not all states are parsed correctly. + if collection_id not in state_names: + print('Invalid state:', index, row.to_dict()) + continue + + # Handle NaN values. + obs = replace_nan_with_none(row.to_dict()) + + # Create an entry for each state. + refs.append(f'{col}/{collection_id}/{doc_id}') + docs.append(obs) + + # Create a second entry for aggregate queries. + uid = create_hash(doc_id, collection_id) + refs.append(f'{col}/all/{uid}') + docs.append(obs) + + # Upload the data to Firestore. + firebase.update_documents(refs, docs, database=db) + return docs + + +# === Test === +if __name__ == '__main__': + + # Set Firebase credentials. + try: + config = dotenv_values('../../.env') + credentials = config['GOOGLE_APPLICATION_CREDENTIALS'] + except KeyError: + config = dotenv_values('./.env') + credentials = config['GOOGLE_APPLICATION_CREDENTIALS'] + os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials + + # Get any subset specified from the command line. + import sys + try: + subset = sys.argv[1] + if subset.startswith('--ip'): + subset = 'all' + except KeyError: + subset = 'all' + + # Upload Firestore with cannabis license data. + try: + all_licenses = upload_cannabis_licenses(subset=subset) + print('Uploaded %i license data to Firestore.' % len(all_licenses)) + except: + print('Failed to upload license data to Firestore.') + + # Upload datafiles to Firebase Storage. + # try: + # bucket_name = config['FIREBASE_STORAGE_BUCKET'] + # upload_cannabis_licenses_datafiles(bucket_name) + # print('Uploaded license datafiles to Firebase Storage.') + # except: + # print('Failed to upload datafiles to Firebase Storage.')