parquet-converter
commited on
Commit
•
a64b489
1
Parent(s):
ee3a127
Update parquet files
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +0 -53
- .gitignore +0 -17
- LICENSE +0 -395
- README.md +0 -281
- data/az/retailers-az-2022-10-07T10-12-07.csv → ak/cannabis_licenses-data.parquet +2 -2
- algorithms/__init__.py +0 -0
- algorithms/get_licenses_ak.py +0 -244
- algorithms/get_licenses_az.py +0 -333
- algorithms/get_licenses_ca.py +0 -112
- algorithms/get_licenses_co.py +0 -221
- algorithms/get_licenses_ct.py +0 -163
- algorithms/get_licenses_il.py +0 -194
- algorithms/get_licenses_ma.py +0 -146
- algorithms/get_licenses_me.py +0 -187
- algorithms/get_licenses_mi.py +0 -259
- algorithms/get_licenses_mt.py +0 -278
- algorithms/get_licenses_nj.py +0 -128
- algorithms/get_licenses_nm.py +0 -309
- algorithms/get_licenses_nv.py +0 -235
- algorithms/get_licenses_or.py +0 -213
- algorithms/get_licenses_ri.py +0 -179
- algorithms/get_licenses_vt.py +0 -253
- algorithms/get_licenses_wa.py +0 -271
- algorithms/main.py +0 -109
- analysis/figures/cannabis-licenses-map.png → all/cannabis_licenses-data.parquet +2 -2
- analysis/figures/cannabis-licenses-map.html +0 -0
- analysis/license_map.py +0 -106
- data/ct/retailers-ct-2022-10-06T18-28-33.csv → az/cannabis_licenses-data.parquet +2 -2
- data/ak/licenses-ak-2022-10-06T17-46-29.csv → ca/cannabis_licenses-data.parquet +2 -2
- cannabis_licenses.py +0 -152
- data/ak/retailers-ak-2022-10-06T17-46-29.csv → co/cannabis_licenses-data.parquet +2 -2
- data/az/licenses-az-2022-10-07T10-12-07.csv → ct/cannabis_licenses-data.parquet +2 -2
- data/all/licenses-2022-10-06T18-46-11.csv +0 -3
- data/all/licenses-2022-10-08T14-03-08.csv +0 -3
- data/all/retailers-2022-10-07T10-20-55.csv +0 -3
- data/ca/licenses-ca-2022-10-06T18-10-15.csv +0 -3
- data/co/licenses-co-2022-10-06T18-28-29.csv +0 -3
- data/co/retailers-co-2022-10-06T18-28-29.csv +0 -3
- data/il/retailers-il-2022-10-06T18-28-55.csv +0 -3
- data/ma/licenses-ma-2022-10-07T14-45-39.csv +0 -3
- data/ma/retailers-ma-2022-10-07T14-45-39.csv +0 -3
- data/me/licenses-me-2022-10-07T15-26-01.csv +0 -3
- data/mi/licenses-mi-2022-10-08T13-49-04.csv +0 -3
- data/mt/retailers-mt-2022-10-07T16-28-10.csv +0 -3
- data/nj/licenses-nj-2022-10-06T18-39-17.csv +0 -3
- data/nm/retailers-nm-2022-10-05T15-09-21.csv +0 -3
- data/nv/licenses-nv-2022-10-06T18-42-39.csv +0 -3
- data/nv/retailers-nv-2022-10-06T18-43-01.csv +0 -3
- data/or/licenses-or-2022-10-07T14-47-55.csv +0 -3
- data/ri/licenses-ri-2022-10-06T18-45-41.csv +0 -3
.gitattributes
DELETED
@@ -1,53 +0,0 @@
|
|
1 |
-
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
-
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
-
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
-
*.lz4 filter=lfs diff=lfs merge=lfs -text
|
11 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
14 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
15 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
16 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
17 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
18 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
19 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
20 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
21 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
22 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
23 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
24 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
25 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
26 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
27 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
28 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
29 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
30 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
31 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
32 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
33 |
-
# Audio files - uncompressed
|
34 |
-
*.pcm filter=lfs diff=lfs merge=lfs -text
|
35 |
-
*.sam filter=lfs diff=lfs merge=lfs -text
|
36 |
-
*.raw filter=lfs diff=lfs merge=lfs -text
|
37 |
-
# Audio files - compressed
|
38 |
-
*.aac filter=lfs diff=lfs merge=lfs -text
|
39 |
-
*.flac filter=lfs diff=lfs merge=lfs -text
|
40 |
-
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
41 |
-
*.ogg filter=lfs diff=lfs merge=lfs -text
|
42 |
-
*.wav filter=lfs diff=lfs merge=lfs -text
|
43 |
-
# Image files - uncompressed
|
44 |
-
*.bmp filter=lfs diff=lfs merge=lfs -text
|
45 |
-
*.gif filter=lfs diff=lfs merge=lfs -text
|
46 |
-
*.png filter=lfs diff=lfs merge=lfs -text
|
47 |
-
*.tiff filter=lfs diff=lfs merge=lfs -text
|
48 |
-
# Image files - compressed
|
49 |
-
*.jpg filter=lfs diff=lfs merge=lfs -text
|
50 |
-
*.jpeg filter=lfs diff=lfs merge=lfs -text
|
51 |
-
*.webp filter=lfs diff=lfs merge=lfs -text
|
52 |
-
*.xlsx filter=lfs diff=lfs merge=lfs -text
|
53 |
-
*.csv filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.gitignore
DELETED
@@ -1,17 +0,0 @@
|
|
1 |
-
# Ignore environment variables.
|
2 |
-
*.env
|
3 |
-
|
4 |
-
# Ignore temporary files.
|
5 |
-
*tmp
|
6 |
-
|
7 |
-
# Ignore PDFs.
|
8 |
-
*pdfs
|
9 |
-
|
10 |
-
# Ignore external datasets.
|
11 |
-
*.datasets
|
12 |
-
|
13 |
-
# Ignore VS Code settings.
|
14 |
-
*.vscode
|
15 |
-
|
16 |
-
# Ignore PyCache
|
17 |
-
*__pycache__
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LICENSE
DELETED
@@ -1,395 +0,0 @@
|
|
1 |
-
Attribution 4.0 International
|
2 |
-
|
3 |
-
=======================================================================
|
4 |
-
|
5 |
-
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
6 |
-
does not provide legal services or legal advice. Distribution of
|
7 |
-
Creative Commons public licenses does not create a lawyer-client or
|
8 |
-
other relationship. Creative Commons makes its licenses and related
|
9 |
-
information available on an "as-is" basis. Creative Commons gives no
|
10 |
-
warranties regarding its licenses, any material licensed under their
|
11 |
-
terms and conditions, or any related information. Creative Commons
|
12 |
-
disclaims all liability for damages resulting from their use to the
|
13 |
-
fullest extent possible.
|
14 |
-
|
15 |
-
Using Creative Commons Public Licenses
|
16 |
-
|
17 |
-
Creative Commons public licenses provide a standard set of terms and
|
18 |
-
conditions that creators and other rights holders may use to share
|
19 |
-
original works of authorship and other material subject to copyright
|
20 |
-
and certain other rights specified in the public license below. The
|
21 |
-
following considerations are for informational purposes only, are not
|
22 |
-
exhaustive, and do not form part of our licenses.
|
23 |
-
|
24 |
-
Considerations for licensors: Our public licenses are
|
25 |
-
intended for use by those authorized to give the public
|
26 |
-
permission to use material in ways otherwise restricted by
|
27 |
-
copyright and certain other rights. Our licenses are
|
28 |
-
irrevocable. Licensors should read and understand the terms
|
29 |
-
and conditions of the license they choose before applying it.
|
30 |
-
Licensors should also secure all rights necessary before
|
31 |
-
applying our licenses so that the public can reuse the
|
32 |
-
material as expected. Licensors should clearly mark any
|
33 |
-
material not subject to the license. This includes other CC-
|
34 |
-
licensed material, or material used under an exception or
|
35 |
-
limitation to copyright. More considerations for licensors:
|
36 |
-
wiki.creativecommons.org/Considerations_for_licensors
|
37 |
-
|
38 |
-
Considerations for the public: By using one of our public
|
39 |
-
licenses, a licensor grants the public permission to use the
|
40 |
-
licensed material under specified terms and conditions. If
|
41 |
-
the licensor's permission is not necessary for any reason--for
|
42 |
-
example, because of any applicable exception or limitation to
|
43 |
-
copyright--then that use is not regulated by the license. Our
|
44 |
-
licenses grant only permissions under copyright and certain
|
45 |
-
other rights that a licensor has authority to grant. Use of
|
46 |
-
the licensed material may still be restricted for other
|
47 |
-
reasons, including because others have copyright or other
|
48 |
-
rights in the material. A licensor may make special requests,
|
49 |
-
such as asking that all changes be marked or described.
|
50 |
-
Although not required by our licenses, you are encouraged to
|
51 |
-
respect those requests where reasonable. More considerations
|
52 |
-
for the public:
|
53 |
-
wiki.creativecommons.org/Considerations_for_licensees
|
54 |
-
|
55 |
-
=======================================================================
|
56 |
-
|
57 |
-
Creative Commons Attribution 4.0 International Public License
|
58 |
-
|
59 |
-
By exercising the Licensed Rights (defined below), You accept and agree
|
60 |
-
to be bound by the terms and conditions of this Creative Commons
|
61 |
-
Attribution 4.0 International Public License ("Public License"). To the
|
62 |
-
extent this Public License may be interpreted as a contract, You are
|
63 |
-
granted the Licensed Rights in consideration of Your acceptance of
|
64 |
-
these terms and conditions, and the Licensor grants You such rights in
|
65 |
-
consideration of benefits the Licensor receives from making the
|
66 |
-
Licensed Material available under these terms and conditions.
|
67 |
-
|
68 |
-
|
69 |
-
Section 1 -- Definitions.
|
70 |
-
|
71 |
-
a. Adapted Material means material subject to Copyright and Similar
|
72 |
-
Rights that is derived from or based upon the Licensed Material
|
73 |
-
and in which the Licensed Material is translated, altered,
|
74 |
-
arranged, transformed, or otherwise modified in a manner requiring
|
75 |
-
permission under the Copyright and Similar Rights held by the
|
76 |
-
Licensor. For purposes of this Public License, where the Licensed
|
77 |
-
Material is a musical work, performance, or sound recording,
|
78 |
-
Adapted Material is always produced where the Licensed Material is
|
79 |
-
synched in timed relation with a moving image.
|
80 |
-
|
81 |
-
b. Adapter's License means the license You apply to Your Copyright
|
82 |
-
and Similar Rights in Your contributions to Adapted Material in
|
83 |
-
accordance with the terms and conditions of this Public License.
|
84 |
-
|
85 |
-
c. Copyright and Similar Rights means copyright and/or similar rights
|
86 |
-
closely related to copyright including, without limitation,
|
87 |
-
performance, broadcast, sound recording, and Sui Generis Database
|
88 |
-
Rights, without regard to how the rights are labeled or
|
89 |
-
categorized. For purposes of this Public License, the rights
|
90 |
-
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
91 |
-
Rights.
|
92 |
-
|
93 |
-
d. Effective Technological Measures means those measures that, in the
|
94 |
-
absence of proper authority, may not be circumvented under laws
|
95 |
-
fulfilling obligations under Article 11 of the WIPO Copyright
|
96 |
-
Treaty adopted on December 20, 1996, and/or similar international
|
97 |
-
agreements.
|
98 |
-
|
99 |
-
e. Exceptions and Limitations means fair use, fair dealing, and/or
|
100 |
-
any other exception or limitation to Copyright and Similar Rights
|
101 |
-
that applies to Your use of the Licensed Material.
|
102 |
-
|
103 |
-
f. Licensed Material means the artistic or literary work, database,
|
104 |
-
or other material to which the Licensor applied this Public
|
105 |
-
License.
|
106 |
-
|
107 |
-
g. Licensed Rights means the rights granted to You subject to the
|
108 |
-
terms and conditions of this Public License, which are limited to
|
109 |
-
all Copyright and Similar Rights that apply to Your use of the
|
110 |
-
Licensed Material and that the Licensor has authority to license.
|
111 |
-
|
112 |
-
h. Licensor means the individual(s) or entity(ies) granting rights
|
113 |
-
under this Public License.
|
114 |
-
|
115 |
-
i. Share means to provide material to the public by any means or
|
116 |
-
process that requires permission under the Licensed Rights, such
|
117 |
-
as reproduction, public display, public performance, distribution,
|
118 |
-
dissemination, communication, or importation, and to make material
|
119 |
-
available to the public including in ways that members of the
|
120 |
-
public may access the material from a place and at a time
|
121 |
-
individually chosen by them.
|
122 |
-
|
123 |
-
j. Sui Generis Database Rights means rights other than copyright
|
124 |
-
resulting from Directive 96/9/EC of the European Parliament and of
|
125 |
-
the Council of 11 March 1996 on the legal protection of databases,
|
126 |
-
as amended and/or succeeded, as well as other essentially
|
127 |
-
equivalent rights anywhere in the world.
|
128 |
-
|
129 |
-
k. You means the individual or entity exercising the Licensed Rights
|
130 |
-
under this Public License. Your has a corresponding meaning.
|
131 |
-
|
132 |
-
|
133 |
-
Section 2 -- Scope.
|
134 |
-
|
135 |
-
a. License grant.
|
136 |
-
|
137 |
-
1. Subject to the terms and conditions of this Public License,
|
138 |
-
the Licensor hereby grants You a worldwide, royalty-free,
|
139 |
-
non-sublicensable, non-exclusive, irrevocable license to
|
140 |
-
exercise the Licensed Rights in the Licensed Material to:
|
141 |
-
|
142 |
-
a. reproduce and Share the Licensed Material, in whole or
|
143 |
-
in part; and
|
144 |
-
|
145 |
-
b. produce, reproduce, and Share Adapted Material.
|
146 |
-
|
147 |
-
2. Exceptions and Limitations. For the avoidance of doubt, where
|
148 |
-
Exceptions and Limitations apply to Your use, this Public
|
149 |
-
License does not apply, and You do not need to comply with
|
150 |
-
its terms and conditions.
|
151 |
-
|
152 |
-
3. Term. The term of this Public License is specified in Section
|
153 |
-
6(a).
|
154 |
-
|
155 |
-
4. Media and formats; technical modifications allowed. The
|
156 |
-
Licensor authorizes You to exercise the Licensed Rights in
|
157 |
-
all media and formats whether now known or hereafter created,
|
158 |
-
and to make technical modifications necessary to do so. The
|
159 |
-
Licensor waives and/or agrees not to assert any right or
|
160 |
-
authority to forbid You from making technical modifications
|
161 |
-
necessary to exercise the Licensed Rights, including
|
162 |
-
technical modifications necessary to circumvent Effective
|
163 |
-
Technological Measures. For purposes of this Public License,
|
164 |
-
simply making modifications authorized by this Section 2(a)
|
165 |
-
(4) never produces Adapted Material.
|
166 |
-
|
167 |
-
5. Downstream recipients.
|
168 |
-
|
169 |
-
a. Offer from the Licensor -- Licensed Material. Every
|
170 |
-
recipient of the Licensed Material automatically
|
171 |
-
receives an offer from the Licensor to exercise the
|
172 |
-
Licensed Rights under the terms and conditions of this
|
173 |
-
Public License.
|
174 |
-
|
175 |
-
b. No downstream restrictions. You may not offer or impose
|
176 |
-
any additional or different terms or conditions on, or
|
177 |
-
apply any Effective Technological Measures to, the
|
178 |
-
Licensed Material if doing so restricts exercise of the
|
179 |
-
Licensed Rights by any recipient of the Licensed
|
180 |
-
Material.
|
181 |
-
|
182 |
-
6. No endorsement. Nothing in this Public License constitutes or
|
183 |
-
may be construed as permission to assert or imply that You
|
184 |
-
are, or that Your use of the Licensed Material is, connected
|
185 |
-
with, or sponsored, endorsed, or granted official status by,
|
186 |
-
the Licensor or others designated to receive attribution as
|
187 |
-
provided in Section 3(a)(1)(A)(i).
|
188 |
-
|
189 |
-
b. Other rights.
|
190 |
-
|
191 |
-
1. Moral rights, such as the right of integrity, are not
|
192 |
-
licensed under this Public License, nor are publicity,
|
193 |
-
privacy, and/or other similar personality rights; however, to
|
194 |
-
the extent possible, the Licensor waives and/or agrees not to
|
195 |
-
assert any such rights held by the Licensor to the limited
|
196 |
-
extent necessary to allow You to exercise the Licensed
|
197 |
-
Rights, but not otherwise.
|
198 |
-
|
199 |
-
2. Patent and trademark rights are not licensed under this
|
200 |
-
Public License.
|
201 |
-
|
202 |
-
3. To the extent possible, the Licensor waives any right to
|
203 |
-
collect royalties from You for the exercise of the Licensed
|
204 |
-
Rights, whether directly or through a collecting society
|
205 |
-
under any voluntary or waivable statutory or compulsory
|
206 |
-
licensing scheme. In all other cases the Licensor expressly
|
207 |
-
reserves any right to collect such royalties.
|
208 |
-
|
209 |
-
|
210 |
-
Section 3 -- License Conditions.
|
211 |
-
|
212 |
-
Your exercise of the Licensed Rights is expressly made subject to the
|
213 |
-
following conditions.
|
214 |
-
|
215 |
-
a. Attribution.
|
216 |
-
|
217 |
-
1. If You Share the Licensed Material (including in modified
|
218 |
-
form), You must:
|
219 |
-
|
220 |
-
a. retain the following if it is supplied by the Licensor
|
221 |
-
with the Licensed Material:
|
222 |
-
|
223 |
-
i. identification of the creator(s) of the Licensed
|
224 |
-
Material and any others designated to receive
|
225 |
-
attribution, in any reasonable manner requested by
|
226 |
-
the Licensor (including by pseudonym if
|
227 |
-
designated);
|
228 |
-
|
229 |
-
ii. a copyright notice;
|
230 |
-
|
231 |
-
iii. a notice that refers to this Public License;
|
232 |
-
|
233 |
-
iv. a notice that refers to the disclaimer of
|
234 |
-
warranties;
|
235 |
-
|
236 |
-
v. a URI or hyperlink to the Licensed Material to the
|
237 |
-
extent reasonably practicable;
|
238 |
-
|
239 |
-
b. indicate if You modified the Licensed Material and
|
240 |
-
retain an indication of any previous modifications; and
|
241 |
-
|
242 |
-
c. indicate the Licensed Material is licensed under this
|
243 |
-
Public License, and include the text of, or the URI or
|
244 |
-
hyperlink to, this Public License.
|
245 |
-
|
246 |
-
2. You may satisfy the conditions in Section 3(a)(1) in any
|
247 |
-
reasonable manner based on the medium, means, and context in
|
248 |
-
which You Share the Licensed Material. For example, it may be
|
249 |
-
reasonable to satisfy the conditions by providing a URI or
|
250 |
-
hyperlink to a resource that includes the required
|
251 |
-
information.
|
252 |
-
|
253 |
-
3. If requested by the Licensor, You must remove any of the
|
254 |
-
information required by Section 3(a)(1)(A) to the extent
|
255 |
-
reasonably practicable.
|
256 |
-
|
257 |
-
4. If You Share Adapted Material You produce, the Adapter's
|
258 |
-
License You apply must not prevent recipients of the Adapted
|
259 |
-
Material from complying with this Public License.
|
260 |
-
|
261 |
-
|
262 |
-
Section 4 -- Sui Generis Database Rights.
|
263 |
-
|
264 |
-
Where the Licensed Rights include Sui Generis Database Rights that
|
265 |
-
apply to Your use of the Licensed Material:
|
266 |
-
|
267 |
-
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
268 |
-
to extract, reuse, reproduce, and Share all or a substantial
|
269 |
-
portion of the contents of the database;
|
270 |
-
|
271 |
-
b. if You include all or a substantial portion of the database
|
272 |
-
contents in a database in which You have Sui Generis Database
|
273 |
-
Rights, then the database in which You have Sui Generis Database
|
274 |
-
Rights (but not its individual contents) is Adapted Material; and
|
275 |
-
|
276 |
-
c. You must comply with the conditions in Section 3(a) if You Share
|
277 |
-
all or a substantial portion of the contents of the database.
|
278 |
-
|
279 |
-
For the avoidance of doubt, this Section 4 supplements and does not
|
280 |
-
replace Your obligations under this Public License where the Licensed
|
281 |
-
Rights include other Copyright and Similar Rights.
|
282 |
-
|
283 |
-
|
284 |
-
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
285 |
-
|
286 |
-
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
287 |
-
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
288 |
-
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
289 |
-
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
290 |
-
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
291 |
-
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
292 |
-
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
293 |
-
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
294 |
-
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
295 |
-
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
296 |
-
|
297 |
-
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
298 |
-
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
299 |
-
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
300 |
-
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
301 |
-
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
302 |
-
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
303 |
-
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
304 |
-
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
305 |
-
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
306 |
-
|
307 |
-
c. The disclaimer of warranties and limitation of liability provided
|
308 |
-
above shall be interpreted in a manner that, to the extent
|
309 |
-
possible, most closely approximates an absolute disclaimer and
|
310 |
-
waiver of all liability.
|
311 |
-
|
312 |
-
|
313 |
-
Section 6 -- Term and Termination.
|
314 |
-
|
315 |
-
a. This Public License applies for the term of the Copyright and
|
316 |
-
Similar Rights licensed here. However, if You fail to comply with
|
317 |
-
this Public License, then Your rights under this Public License
|
318 |
-
terminate automatically.
|
319 |
-
|
320 |
-
b. Where Your right to use the Licensed Material has terminated under
|
321 |
-
Section 6(a), it reinstates:
|
322 |
-
|
323 |
-
1. automatically as of the date the violation is cured, provided
|
324 |
-
it is cured within 30 days of Your discovery of the
|
325 |
-
violation; or
|
326 |
-
|
327 |
-
2. upon express reinstatement by the Licensor.
|
328 |
-
|
329 |
-
For the avoidance of doubt, this Section 6(b) does not affect any
|
330 |
-
right the Licensor may have to seek remedies for Your violations
|
331 |
-
of this Public License.
|
332 |
-
|
333 |
-
c. For the avoidance of doubt, the Licensor may also offer the
|
334 |
-
Licensed Material under separate terms or conditions or stop
|
335 |
-
distributing the Licensed Material at any time; however, doing so
|
336 |
-
will not terminate this Public License.
|
337 |
-
|
338 |
-
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
339 |
-
License.
|
340 |
-
|
341 |
-
|
342 |
-
Section 7 -- Other Terms and Conditions.
|
343 |
-
|
344 |
-
a. The Licensor shall not be bound by any additional or different
|
345 |
-
terms or conditions communicated by You unless expressly agreed.
|
346 |
-
|
347 |
-
b. Any arrangements, understandings, or agreements regarding the
|
348 |
-
Licensed Material not stated herein are separate from and
|
349 |
-
independent of the terms and conditions of this Public License.
|
350 |
-
|
351 |
-
|
352 |
-
Section 8 -- Interpretation.
|
353 |
-
|
354 |
-
a. For the avoidance of doubt, this Public License does not, and
|
355 |
-
shall not be interpreted to, reduce, limit, restrict, or impose
|
356 |
-
conditions on any use of the Licensed Material that could lawfully
|
357 |
-
be made without permission under this Public License.
|
358 |
-
|
359 |
-
b. To the extent possible, if any provision of this Public License is
|
360 |
-
deemed unenforceable, it shall be automatically reformed to the
|
361 |
-
minimum extent necessary to make it enforceable. If the provision
|
362 |
-
cannot be reformed, it shall be severed from this Public License
|
363 |
-
without affecting the enforceability of the remaining terms and
|
364 |
-
conditions.
|
365 |
-
|
366 |
-
c. No term or condition of this Public License will be waived and no
|
367 |
-
failure to comply consented to unless expressly agreed to by the
|
368 |
-
Licensor.
|
369 |
-
|
370 |
-
d. Nothing in this Public License constitutes or may be interpreted
|
371 |
-
as a limitation upon, or waiver of, any privileges and immunities
|
372 |
-
that apply to the Licensor or You, including from the legal
|
373 |
-
processes of any jurisdiction or authority.
|
374 |
-
|
375 |
-
|
376 |
-
=======================================================================
|
377 |
-
|
378 |
-
Creative Commons is not a party to its public
|
379 |
-
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
380 |
-
its public licenses to material it publishes and in those instances
|
381 |
-
will be considered the “Licensor.” The text of the Creative Commons
|
382 |
-
public licenses is dedicated to the public domain under the CC0 Public
|
383 |
-
Domain Dedication. Except for the limited purpose of indicating that
|
384 |
-
material is shared under a Creative Commons public license or as
|
385 |
-
otherwise permitted by the Creative Commons policies published at
|
386 |
-
creativecommons.org/policies, Creative Commons does not authorize the
|
387 |
-
use of the trademark "Creative Commons" or any other trademark or logo
|
388 |
-
of Creative Commons without its prior written consent including,
|
389 |
-
without limitation, in connection with any unauthorized modifications
|
390 |
-
to any of its public licenses or any other arrangements,
|
391 |
-
understandings, or agreements concerning use of licensed material. For
|
392 |
-
the avoidance of doubt, this paragraph does not form part of the
|
393 |
-
public licenses.
|
394 |
-
|
395 |
-
Creative Commons may be contacted at creativecommons.org.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
DELETED
@@ -1,281 +0,0 @@
|
|
1 |
-
---
|
2 |
-
annotations_creators:
|
3 |
-
- expert-generated
|
4 |
-
language_creators:
|
5 |
-
- expert-generated
|
6 |
-
license:
|
7 |
-
- cc-by-4.0
|
8 |
-
pretty_name: cannabis_licenses
|
9 |
-
size_categories:
|
10 |
-
- 10K<n<100K
|
11 |
-
source_datasets:
|
12 |
-
- original
|
13 |
-
tags:
|
14 |
-
- cannabis
|
15 |
-
- licenses
|
16 |
-
- licensees
|
17 |
-
- retail
|
18 |
-
---
|
19 |
-
|
20 |
-
# Cannabis Licenses, Curated by Cannlytics
|
21 |
-
|
22 |
-
<div align="center" style="text-align:center; margin-top:1rem; margin-bottom: 1rem;">
|
23 |
-
<img style="max-height:365px;width:100%;max-width:720px;" alt="" src="analysis/figures/cannabis-licenses-map.png">
|
24 |
-
</div>
|
25 |
-
|
26 |
-
## Table of Contents
|
27 |
-
- [Table of Contents](#table-of-contents)
|
28 |
-
- [Dataset Description](#dataset-description)
|
29 |
-
- [Dataset Summary](#dataset-summary)
|
30 |
-
- [Dataset Structure](#dataset-structure)
|
31 |
-
- [Data Instances](#data-instances)
|
32 |
-
- [Data Fields](#data-fields)
|
33 |
-
- [Data Splits](#data-splits)
|
34 |
-
- [Dataset Creation](#dataset-creation)
|
35 |
-
- [Curation Rationale](#curation-rationale)
|
36 |
-
- [Source Data](#source-data)
|
37 |
-
- [Data Collection and Normalization](#data-collection-and-normalization)
|
38 |
-
- [Personal and Sensitive Information](#personal-and-sensitive-information)
|
39 |
-
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
40 |
-
- [Social Impact of Dataset](#social-impact-of-dataset)
|
41 |
-
- [Discussion of Biases](#discussion-of-biases)
|
42 |
-
- [Other Known Limitations](#other-known-limitations)
|
43 |
-
- [Additional Information](#additional-information)
|
44 |
-
- [Dataset Curators](#dataset-curators)
|
45 |
-
- [License](#license)
|
46 |
-
- [Citation](#citation)
|
47 |
-
- [Contributions](#contributions)
|
48 |
-
|
49 |
-
## Dataset Description
|
50 |
-
|
51 |
-
- **Homepage:** <https://github.com/cannlytics/cannlytics>
|
52 |
-
- **Repository:** <https://huggingface.co/datasets/cannlytics/cannabis_licenses>
|
53 |
-
- **Point of Contact:** <dev@cannlytics.com>
|
54 |
-
|
55 |
-
### Dataset Summary
|
56 |
-
|
57 |
-
**Cannabis Licenses** is a collection of cannabis license data for each state with permitted adult-use cannabis. The dataset also includes a sub-dataset, `all`, that includes all licenses.
|
58 |
-
|
59 |
-
## Dataset Structure
|
60 |
-
|
61 |
-
The dataset is partitioned into 18 subsets for each state and the aggregate.
|
62 |
-
|
63 |
-
| State | Code | Status |
|
64 |
-
|-------|------|--------|
|
65 |
-
| [All](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/all) | `all` | ✅ |
|
66 |
-
| [Alaska](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/ak) | `ak` | ✅ |
|
67 |
-
| [Arizona](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/az) | `az` | ✅ |
|
68 |
-
| [California](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/ca) | `ca` | ✅ |
|
69 |
-
| [Colorado](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/co) | `co` | ✅ |
|
70 |
-
| [Connecticut](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/ct) | `ct` | ✅ |
|
71 |
-
| [Illinois](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/il) | `il` | ✅ |
|
72 |
-
| [Maine](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/me) | `me` | ✅ |
|
73 |
-
| [Massachusetts](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/ma) | `ma` | ✅ |
|
74 |
-
| [Michigan](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/mi) | `mi` | ✅ |
|
75 |
-
| [Montana](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/mt) | `mt` | ✅ |
|
76 |
-
| [Nevada](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/nv) | `nv` | ✅ |
|
77 |
-
| [New Jersey](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/nj) | `nj` | ✅ |
|
78 |
-
| New York | `ny` | ⏳ Expected 2022 Q4 |
|
79 |
-
| [New Mexico](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/nm) | `nm` | ⚠️ Under development |
|
80 |
-
| [Oregon](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/or) | `or` | ✅ |
|
81 |
-
| [Rhode Island](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/ri) | `ri` | ✅ |
|
82 |
-
| [Vermont](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/vt) | `vt` | ✅ |
|
83 |
-
| Virginia | `va` | ⏳ Expected 2024 |
|
84 |
-
| [Washington](https://huggingface.co/datasets/cannlytics/cannabis_licenses/tree/main/data/wa) | `wa` | ✅ |
|
85 |
-
|
86 |
-
The following (18) states have issued medical cannabis licenses, but are not (yet) included in the dataset:
|
87 |
-
|
88 |
-
- Alabama
|
89 |
-
- Arkansas
|
90 |
-
- Delaware
|
91 |
-
- District of Columbia (D.C.)
|
92 |
-
- Florida
|
93 |
-
- Louisiana
|
94 |
-
- Maryland
|
95 |
-
- Minnesota
|
96 |
-
- Mississippi
|
97 |
-
- Missouri
|
98 |
-
- New Hampshire
|
99 |
-
- North Dakota
|
100 |
-
- Ohio
|
101 |
-
- Oklahoma
|
102 |
-
- Pennsylvania
|
103 |
-
- South Dakota
|
104 |
-
- Utah
|
105 |
-
- West Virginia
|
106 |
-
|
107 |
-
### Data Instances
|
108 |
-
|
109 |
-
You can load the licenses for each state. For example:
|
110 |
-
|
111 |
-
```py
|
112 |
-
from datasets import load_dataset
|
113 |
-
|
114 |
-
# Get the licenses for a specific state.
|
115 |
-
dataset = load_dataset('cannlytics/cannabis_licenses', 'ca')
|
116 |
-
data = dataset['data']
|
117 |
-
assert len(data) > 0
|
118 |
-
print('%i licenses.' % len(data))
|
119 |
-
```
|
120 |
-
|
121 |
-
### Data Fields
|
122 |
-
|
123 |
-
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.
|
124 |
-
|
125 |
-
| Field | Example | Description |
|
126 |
-
|-------|-----|-------------|
|
127 |
-
| `id` | `"1046"` | A state-unique ID for the license. |
|
128 |
-
| `license_number` | `"C10-0000423-LIC"` | A unique license number. |
|
129 |
-
| `license_status` | `"Active"` | The status of the license. Only licenses that are active are included. |
|
130 |
-
| `license_status_date` | `"2022-04-20T00:00"` | The date the status was assigned, an ISO-formatted date if present. |
|
131 |
-
| `license_term` | `"Provisional"` | The term for the license. |
|
132 |
-
| `license_type` | `"Commercial - Retailer"` | The type of business license. |
|
133 |
-
| `license_designation` | `"Adult-Use and Medicinal"` | A state-specific classification for the license. |
|
134 |
-
| `issue_date` | `"2019-07-15T00:00:00"` | An issue date for the license, an ISO-formatted date if present. |
|
135 |
-
| `expiration_date` | `"2023-07-14T00:00:00"` | An expiration date for the license, an ISO-formatted date if present. |
|
136 |
-
| `licensing_authority_id` | `"BCC"` | A unique ID for the state licensing authority. |
|
137 |
-
| `licensing_authority` | `"Bureau of Cannabis Control (BCC)"` | The state licensing authority. |
|
138 |
-
| `business_legal_name` | `"Movocan"` | The legal name of the business that owns the license. |
|
139 |
-
| `business_dba_name` | `"Movocan"` | The name the license is doing business as. |
|
140 |
-
| `business_owner_name` | `"redacted"` | The name of the owner of the license. |
|
141 |
-
| `business_structure` | `"Corporation"` | The structure of the business that owns the license. |
|
142 |
-
| `activity` | `"Pending Inspection"` | Any relevant license activity. |
|
143 |
-
| `premise_street_address` | `"1632 Gateway Rd"` | The street address of the business. |
|
144 |
-
| `premise_city` | `"Calexico"` | The city of the business. |
|
145 |
-
| `premise_state` | `"CA"` | The state abbreviation of the business. |
|
146 |
-
| `premise_county` | `"Imperial"` | The county of the business. |
|
147 |
-
| `premise_zip_code` | `"92231"` | The zip code of the business. |
|
148 |
-
| `business_email` | `"redacted@gmail.com"` | The business email of the license. |
|
149 |
-
| `business_phone` | `"(555) 555-5555"` | The business phone of the license. |
|
150 |
-
| `business_website` | `"cannlytics.com"` | The business website of the license. |
|
151 |
-
| `parcel_number` | `"A42"` | An ID for the business location. |
|
152 |
-
| `premise_latitude` | `32.69035693` | The latitude of the business. |
|
153 |
-
| `premise_longitude` | `-115.38987552` | The longitude of the business. |
|
154 |
-
| `data_refreshed_date` | `"2022-09-21T12:16:33.3866667"` | An ISO-formatted time when the license data was updated. |
|
155 |
-
|
156 |
-
### Data Splits
|
157 |
-
|
158 |
-
The data is split into subsets by state. You can retrieve all licenses by requesting the `all` subset.
|
159 |
-
|
160 |
-
```py
|
161 |
-
from datasets import load_dataset
|
162 |
-
|
163 |
-
# Get all cannabis licenses.
|
164 |
-
repo = 'cannlytics/cannabis_licenses'
|
165 |
-
dataset = load_dataset(repo, 'all')
|
166 |
-
data = dataset['data']
|
167 |
-
```
|
168 |
-
|
169 |
-
## Dataset Creation
|
170 |
-
|
171 |
-
### Curation Rationale
|
172 |
-
|
173 |
-
Data about organizations operating in the cannabis industry for each state is valuable for research.
|
174 |
-
|
175 |
-
### Source Data
|
176 |
-
|
177 |
-
| State | Data Source URL |
|
178 |
-
|-------|-----------------|
|
179 |
-
| Alaska | <https://www.commerce.alaska.gov/abc/marijuana/Home/licensesearch> |
|
180 |
-
| Arizona | <https://azcarecheck.azdhs.gov/s/?licenseType=null> |
|
181 |
-
| California | <https://search.cannabis.ca.gov/> |
|
182 |
-
| Colorado | <https://sbg.colorado.gov/med/licensed-facilities> |
|
183 |
-
| Connecticut | <https://portal.ct.gov/DCP/Medical-Marijuana-Program/Connecticut-Medical-Marijuana-Dispensary-Facilities> |
|
184 |
-
| Illinois | <https://www.idfpr.com/LicenseLookup/AdultUseDispensaries.pdf> |
|
185 |
-
| Maine | <https://www.maine.gov/dafs/ocp/open-data/adult-use> |
|
186 |
-
| Massachusetts | <https://masscannabiscontrol.com/open-data/data-catalog/> |
|
187 |
-
| Michigan | <https://michigan.maps.arcgis.com/apps/webappviewer/index.html?id=cd5a1a76daaf470b823a382691c0ff60> |
|
188 |
-
| Montana | <https://mtrevenue.gov/cannabis/#CannabisLicenses> |
|
189 |
-
| Nevada | <https://ccb.nv.gov/list-of-licensees/> |
|
190 |
-
| New Jersey | <https://data.nj.gov/stories/s/ggm4-mprw> |
|
191 |
-
| New Mexico | <https://nmrldlpi.force.com/bcd/s/public-search-license?division=CCD&language=en_US> |
|
192 |
-
| Oregon | <https://www.oregon.gov/olcc/marijuana/pages/recreational-marijuana-licensing.aspx> |
|
193 |
-
| Rhode Island | <https://dbr.ri.gov/office-cannabis-regulation/compassion-centers/licensed-compassion-centers> |
|
194 |
-
| Vermont | <https://ccb.vermont.gov/licenses> |
|
195 |
-
| Washington | <https://lcb.wa.gov/records/frequently-requested-lists> |
|
196 |
-
|
197 |
-
### Data Collection and Normalization
|
198 |
-
|
199 |
-
In the `algorithms` directory, you can find the algorithms used for data collection. You can use these algorithms to recreate the dataset. First, you will need to clone the repository:
|
200 |
-
|
201 |
-
```
|
202 |
-
git clone https://huggingface.co/datasets/cannlytics/cannabis_licenses
|
203 |
-
```
|
204 |
-
|
205 |
-
You can then install the algorithm Python (3.9+) requirements:
|
206 |
-
|
207 |
-
```
|
208 |
-
cd cannabis_licenses
|
209 |
-
pip install -r requirements.txt
|
210 |
-
```
|
211 |
-
|
212 |
-
Then you can run all of the data-collection algorithms:
|
213 |
-
|
214 |
-
```
|
215 |
-
python algorithms/main.py
|
216 |
-
```
|
217 |
-
|
218 |
-
Or you can run each algorithm individually. For example:
|
219 |
-
|
220 |
-
```
|
221 |
-
python algorithms/get_licenses_ca.py
|
222 |
-
```
|
223 |
-
|
224 |
-
### Personal and Sensitive Information
|
225 |
-
|
226 |
-
This dataset includes names of individuals, public addresses, and contact information for cannabis licensees. It is important to take care to use these data points in a legal manner.
|
227 |
-
|
228 |
-
## Considerations for Using the Data
|
229 |
-
|
230 |
-
### Social Impact of Dataset
|
231 |
-
|
232 |
-
Arguably, there is substantial social impact that could result from the study of permitted adult-use cannabis, therefore, researchers and data consumers alike should take the utmost care in the use of this dataset.
|
233 |
-
|
234 |
-
### Discussion of Biases
|
235 |
-
|
236 |
-
Cannlytics is a for-profit data and analytics company that primarily serves cannabis businesses. The data are not randomly collected and thus sampling bias should be taken into consideration.
|
237 |
-
|
238 |
-
### Other Known Limitations
|
239 |
-
|
240 |
-
The data is for adult-use cannabis licenses. It would be valuable to include medical cannabis licenses too.
|
241 |
-
|
242 |
-
## Additional Information
|
243 |
-
|
244 |
-
### Dataset Curators
|
245 |
-
|
246 |
-
Curated by [🔥Cannlytics](https://cannlytics.com)<br>
|
247 |
-
<contact@cannlytics.com>
|
248 |
-
|
249 |
-
### License
|
250 |
-
|
251 |
-
```
|
252 |
-
Copyright (c) 2022 Cannlytics and the Cannabis Data Science Team
|
253 |
-
|
254 |
-
The files associated with this dataset are licensed under a
|
255 |
-
Creative Commons Attribution 4.0 International license.
|
256 |
-
|
257 |
-
You can share, copy and modify this dataset so long as you give
|
258 |
-
appropriate credit, provide a link to the CC BY license, and
|
259 |
-
indicate if changes were made, but you may not do so in a way
|
260 |
-
that suggests the rights holder has endorsed you or your use of
|
261 |
-
the dataset. Note that further permission may be required for
|
262 |
-
any content within the dataset that is identified as belonging
|
263 |
-
to a third party.
|
264 |
-
```
|
265 |
-
|
266 |
-
### Citation
|
267 |
-
|
268 |
-
Please cite the following if you use the code examples in your research:
|
269 |
-
|
270 |
-
```bibtex
|
271 |
-
@misc{cannlytics2022,
|
272 |
-
title={Cannabis Data Science},
|
273 |
-
author={Skeate, Keegan and O'Sullivan-Sutherland, Candace},
|
274 |
-
journal={https://github.com/cannlytics/cannabis-data-science},
|
275 |
-
year={2022}
|
276 |
-
}
|
277 |
-
```
|
278 |
-
|
279 |
-
### Contributions
|
280 |
-
|
281 |
-
Thanks to [🔥Cannlytics](https://cannlytics.com), [@candy-o](https://github.com/candy-o), [@hcadeaux](https://huggingface.co/hcadeaux), [@keeganskeate](https://github.com/keeganskeate), and the entire [Cannabis Data Science Team](https://meetup.com/cannabis-data-science/members) for their contributions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data/az/retailers-az-2022-10-07T10-12-07.csv → ak/cannabis_licenses-data.parquet
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9b0f1da9b170ad51f59abbe6e00799b484a37dc66c655dcc9014841bf87c7792
|
3 |
+
size 33684
|
algorithms/__init__.py
DELETED
File without changes
|
algorithms/get_licenses_ak.py
DELETED
@@ -1,244 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Alaska Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/6/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Alaska cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Department of Commerce, Community, and Economic Development
|
19 |
-
Alcohol and Marijuana Control Office
|
20 |
-
URL: <https://www.commerce.alaska.gov/abc/marijuana/Home/licensesearch>
|
21 |
-
|
22 |
-
"""
|
23 |
-
# Standard imports.
|
24 |
-
from datetime import datetime
|
25 |
-
import os
|
26 |
-
from time import sleep
|
27 |
-
from typing import Optional
|
28 |
-
|
29 |
-
# External imports.
|
30 |
-
from cannlytics.data.gis import search_for_address
|
31 |
-
from dotenv import dotenv_values
|
32 |
-
import pandas as pd
|
33 |
-
|
34 |
-
# Selenium imports.
|
35 |
-
from selenium import webdriver
|
36 |
-
from selenium.webdriver.chrome.options import Options
|
37 |
-
from selenium.webdriver.common.by import By
|
38 |
-
from selenium.webdriver.chrome.service import Service
|
39 |
-
try:
|
40 |
-
import chromedriver_binary # Adds chromedriver binary to path.
|
41 |
-
except ImportError:
|
42 |
-
pass # Otherwise, ChromeDriver should be in your path.
|
43 |
-
|
44 |
-
|
45 |
-
# Specify where your data lives.
|
46 |
-
DATA_DIR = '../data/ak'
|
47 |
-
ENV_FILE = '../.env'
|
48 |
-
|
49 |
-
# Specify state-specific constants.
|
50 |
-
STATE = 'AK'
|
51 |
-
ALASKA = {
|
52 |
-
'licensing_authority_id': 'AAMCO',
|
53 |
-
'licensing_authority': 'Alaska Alcohol and Marijuana Control Office',
|
54 |
-
'licenses_url': 'https://www.commerce.alaska.gov/abc/marijuana/Home/licensesearch',
|
55 |
-
'licenses': {
|
56 |
-
'columns': {
|
57 |
-
'License #': 'license_number',
|
58 |
-
'Business License #': 'id',
|
59 |
-
'Doing Business As': 'business_dba_name',
|
60 |
-
'License Type': 'license_type',
|
61 |
-
'License Status': 'license_status',
|
62 |
-
'Physical Address': 'address',
|
63 |
-
},
|
64 |
-
},
|
65 |
-
}
|
66 |
-
|
67 |
-
|
68 |
-
def get_licenses_ak(
|
69 |
-
data_dir: Optional[str] = None,
|
70 |
-
env_file: Optional[str] = '.env',
|
71 |
-
):
|
72 |
-
"""Get Alaska cannabis license data."""
|
73 |
-
|
74 |
-
# Initialize Selenium and specify options.
|
75 |
-
service = Service()
|
76 |
-
options = Options()
|
77 |
-
options.add_argument('--window-size=1920,1200')
|
78 |
-
|
79 |
-
# DEV: Run with the browser open.
|
80 |
-
# options.headless = False
|
81 |
-
|
82 |
-
# PRODUCTION: Run with the browser closed.
|
83 |
-
options.add_argument('--headless')
|
84 |
-
options.add_argument('--disable-gpu')
|
85 |
-
options.add_argument('--no-sandbox')
|
86 |
-
|
87 |
-
# Initiate a Selenium driver.
|
88 |
-
driver = webdriver.Chrome(options=options, service=service)
|
89 |
-
|
90 |
-
# Load the license page.
|
91 |
-
driver.get(ALASKA['licenses_url'])
|
92 |
-
|
93 |
-
# Get the license type select.
|
94 |
-
license_types = []
|
95 |
-
options = driver.find_elements(by=By.TAG_NAME, value='option')
|
96 |
-
for option in options:
|
97 |
-
text = option.text
|
98 |
-
if text:
|
99 |
-
license_types.append(text)
|
100 |
-
|
101 |
-
# Iterate over all of the license types.
|
102 |
-
data = []
|
103 |
-
columns = list(ALASKA['licenses']['columns'].values())
|
104 |
-
for license_type in license_types:
|
105 |
-
|
106 |
-
# Set the text into the select.
|
107 |
-
select = driver.find_element(by=By.ID, value='SearchLicenseTypeID')
|
108 |
-
select.send_keys(license_type)
|
109 |
-
|
110 |
-
# Click search.
|
111 |
-
# TODO: There is probably an elegant way to wait for the table to load.
|
112 |
-
search_button = driver.find_element(by=By.ID, value='mariSearchBtn')
|
113 |
-
search_button.click()
|
114 |
-
sleep(2)
|
115 |
-
|
116 |
-
# Extract the table data.
|
117 |
-
table = driver.find_element(by=By.TAG_NAME, value='tbody')
|
118 |
-
rows = table.find_elements(by=By.TAG_NAME, value='tr')
|
119 |
-
for row in rows:
|
120 |
-
obs = {}
|
121 |
-
cells = row.find_elements(by=By.TAG_NAME, value='td')
|
122 |
-
for i, cell in enumerate(cells):
|
123 |
-
column = columns[i]
|
124 |
-
obs[column] = cell.text.replace('\n', ', ')
|
125 |
-
data.append(obs)
|
126 |
-
|
127 |
-
# End the browser session.
|
128 |
-
service.stop()
|
129 |
-
|
130 |
-
# Standardize the license data.
|
131 |
-
licenses = pd.DataFrame(data)
|
132 |
-
licenses = licenses.assign(
|
133 |
-
business_legal_name=licenses['business_dba_name'],
|
134 |
-
business_owner_name=None,
|
135 |
-
business_structure=None,
|
136 |
-
licensing_authority_id=ALASKA['licensing_authority_id'],
|
137 |
-
licensing_authority=ALASKA['licensing_authority'],
|
138 |
-
license_designation='Adult-Use',
|
139 |
-
license_status_date=None,
|
140 |
-
license_term=None,
|
141 |
-
premise_state=STATE,
|
142 |
-
parcel_number=None,
|
143 |
-
activity=None,
|
144 |
-
issue_date=None,
|
145 |
-
expiration_date=None,
|
146 |
-
)
|
147 |
-
|
148 |
-
# Restrict the license status to active.
|
149 |
-
active_license_types = [
|
150 |
-
'Active-Operating',
|
151 |
-
'Active-Pending Inspection',
|
152 |
-
'Delegated',
|
153 |
-
'Complete',
|
154 |
-
]
|
155 |
-
licenses = licenses.loc[licenses['license_status'].isin(active_license_types)]
|
156 |
-
|
157 |
-
# Assign the city and zip code.
|
158 |
-
licenses['premise_city'] = licenses['address'].apply(
|
159 |
-
lambda x: x.split(', ')[1]
|
160 |
-
)
|
161 |
-
licenses['premise_zip_code'] = licenses['address'].apply(
|
162 |
-
lambda x: x.split(', ')[2].replace(STATE, '').strip()
|
163 |
-
)
|
164 |
-
|
165 |
-
# Search for address for each retail license.
|
166 |
-
# Only search for a query once, then re-use the response.
|
167 |
-
# Note: There is probably a much, much more efficient way to do this!!!
|
168 |
-
config = dotenv_values(env_file)
|
169 |
-
api_key = config['GOOGLE_MAPS_API_KEY']
|
170 |
-
queries = {}
|
171 |
-
fields = [
|
172 |
-
'formatted_address',
|
173 |
-
'formatted_phone_number',
|
174 |
-
'geometry/location/lat',
|
175 |
-
'geometry/location/lng',
|
176 |
-
'website',
|
177 |
-
]
|
178 |
-
licenses = licenses.reset_index(drop=True)
|
179 |
-
licenses = licenses.assign(
|
180 |
-
premise_street_address=None,
|
181 |
-
premise_county=None,
|
182 |
-
premise_latitude=None,
|
183 |
-
premise_longitude=None,
|
184 |
-
business_phone=None,
|
185 |
-
business_website=None,
|
186 |
-
)
|
187 |
-
for index, row in licenses.iterrows():
|
188 |
-
|
189 |
-
# Query Google Place API, if necessary.
|
190 |
-
query = ', '.join([row['business_dba_name'], row['address']])
|
191 |
-
gis_data = queries.get(query)
|
192 |
-
if gis_data is None:
|
193 |
-
try:
|
194 |
-
gis_data = search_for_address(query, api_key=api_key, fields=fields)
|
195 |
-
except:
|
196 |
-
gis_data = {}
|
197 |
-
queries[query] = gis_data
|
198 |
-
|
199 |
-
# Record the query.
|
200 |
-
licenses.iat[index, licenses.columns.get_loc('premise_street_address')] = gis_data.get('street')
|
201 |
-
licenses.iat[index, licenses.columns.get_loc('premise_county')] = gis_data.get('county')
|
202 |
-
licenses.iat[index, licenses.columns.get_loc('premise_latitude')] = gis_data.get('latitude')
|
203 |
-
licenses.iat[index, licenses.columns.get_loc('premise_longitude')] = gis_data.get('longitude')
|
204 |
-
licenses.iat[index, licenses.columns.get_loc('business_phone')] = gis_data.get('formatted_phone_number')
|
205 |
-
licenses.iat[index, licenses.columns.get_loc('business_website')] = gis_data.get('website')
|
206 |
-
|
207 |
-
# Clean-up after GIS.
|
208 |
-
licenses.drop(columns=['address'], inplace=True)
|
209 |
-
|
210 |
-
# Optional: Search for business website for email and a photo.
|
211 |
-
licenses['business_email'] = None
|
212 |
-
licenses['business_image_url'] = None
|
213 |
-
|
214 |
-
# Get the refreshed date.
|
215 |
-
licenses['data_refreshed_date'] = datetime.now().isoformat()
|
216 |
-
|
217 |
-
# Save and return the data.
|
218 |
-
if data_dir is not None:
|
219 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
220 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
221 |
-
retailers = licenses.loc[licenses['license_type'] == 'Retail Marijuana Store']
|
222 |
-
licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
223 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
224 |
-
return licenses
|
225 |
-
|
226 |
-
|
227 |
-
# === Test ===
|
228 |
-
if __name__ == '__main__':
|
229 |
-
|
230 |
-
# Support command line usage.
|
231 |
-
import argparse
|
232 |
-
try:
|
233 |
-
arg_parser = argparse.ArgumentParser()
|
234 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
235 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
236 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
237 |
-
args = arg_parser.parse_args()
|
238 |
-
except SystemExit:
|
239 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
240 |
-
|
241 |
-
# Get licenses, saving them to the specified directory.
|
242 |
-
data_dir = args.get('d', args.get('data_dir'))
|
243 |
-
env_file = args.get('env_file')
|
244 |
-
data = get_licenses_ak(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_az.py
DELETED
@@ -1,333 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Arizona Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/27/2022
|
9 |
-
Updated: 10/7/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Arizona cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Arizona Department of Health Services | Division of Licensing
|
19 |
-
URL: <https://azcarecheck.azdhs.gov/s/?licenseType=null>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
from dotenv import dotenv_values
|
25 |
-
import os
|
26 |
-
from time import sleep
|
27 |
-
from typing import Optional
|
28 |
-
|
29 |
-
# External imports.
|
30 |
-
from cannlytics.data.gis import geocode_addresses
|
31 |
-
import pandas as pd
|
32 |
-
import zipcodes
|
33 |
-
|
34 |
-
# Selenium imports.
|
35 |
-
from selenium import webdriver
|
36 |
-
from selenium.webdriver.chrome.options import Options
|
37 |
-
from selenium.webdriver.common.by import By
|
38 |
-
from selenium.webdriver.chrome.service import Service
|
39 |
-
from selenium.webdriver.support import expected_conditions as EC
|
40 |
-
from selenium.webdriver.support.ui import WebDriverWait
|
41 |
-
try:
|
42 |
-
import chromedriver_binary # Adds chromedriver binary to path.
|
43 |
-
except ImportError:
|
44 |
-
pass # Otherwise, ChromeDriver should be in your path.
|
45 |
-
|
46 |
-
|
47 |
-
# Specify where your data lives.
|
48 |
-
DATA_DIR = '../data/az'
|
49 |
-
ENV_FILE = '../.env'
|
50 |
-
|
51 |
-
# Specify state-specific constants.
|
52 |
-
STATE = 'AZ'
|
53 |
-
ARIZONA = {
|
54 |
-
'licensing_authority_id': 'ADHS',
|
55 |
-
'licensing_authority': 'Arizona Department of Health Services',
|
56 |
-
'licenses_url': 'https://azcarecheck.azdhs.gov/s/?licenseType=null',
|
57 |
-
}
|
58 |
-
|
59 |
-
|
60 |
-
def county_from_zip(x):
|
61 |
-
"""Find a county given a zip code. Returns `None` if no match."""
|
62 |
-
try:
|
63 |
-
return zipcodes.matching(x)[0]['county']
|
64 |
-
except KeyError:
|
65 |
-
return None
|
66 |
-
|
67 |
-
|
68 |
-
def get_licenses_az(
|
69 |
-
data_dir: Optional[str] = None,
|
70 |
-
env_file: Optional[str] = '.env',
|
71 |
-
):
|
72 |
-
"""Get Arizona cannabis license data."""
|
73 |
-
|
74 |
-
# Create directories if necessary.
|
75 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
76 |
-
|
77 |
-
# Initialize Selenium and specify options.
|
78 |
-
service = Service()
|
79 |
-
options = Options()
|
80 |
-
options.add_argument('--window-size=1920,1200')
|
81 |
-
|
82 |
-
# DEV: Run with the browser open.
|
83 |
-
# options.headless = False
|
84 |
-
|
85 |
-
# PRODUCTION: Run with the browser closed.
|
86 |
-
options.add_argument('--headless')
|
87 |
-
options.add_argument('--disable-gpu')
|
88 |
-
options.add_argument('--no-sandbox')
|
89 |
-
|
90 |
-
# Initiate a Selenium driver.
|
91 |
-
driver = webdriver.Chrome(options=options, service=service)
|
92 |
-
|
93 |
-
# Load the license page.
|
94 |
-
driver.get(ARIZONA['licenses_url'])
|
95 |
-
detect = (By.CLASS_NAME, 'slds-container_center')
|
96 |
-
WebDriverWait(driver, 30).until(EC.presence_of_element_located(detect))
|
97 |
-
|
98 |
-
# Get the map container.
|
99 |
-
container = driver.find_element(by=By.CLASS_NAME, value='slds-container_center')
|
100 |
-
|
101 |
-
# Click "Load more" until all of the licenses are visible.
|
102 |
-
more = True
|
103 |
-
while(more):
|
104 |
-
button = container.find_element(by=By.TAG_NAME, value='button')
|
105 |
-
driver.execute_script('arguments[0].scrollIntoView(true);', button)
|
106 |
-
button.click()
|
107 |
-
counter = container.find_element(by=By.CLASS_NAME, value='count-text')
|
108 |
-
more = int(counter.text.replace(' more', ''))
|
109 |
-
|
110 |
-
# Get license data for each retailer.
|
111 |
-
data = []
|
112 |
-
els = container.find_elements(by=By.CLASS_NAME, value='map-list__item')
|
113 |
-
for i, el in enumerate(els):
|
114 |
-
|
115 |
-
# Get a retailer's data.
|
116 |
-
count = i + 1
|
117 |
-
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'
|
118 |
-
list_item = el.find_element(by=By.XPATH, value=xpath)
|
119 |
-
body = list_item.find_element(by=By.CLASS_NAME, value='slds-media__body')
|
120 |
-
divs = body.find_elements(by=By.TAG_NAME, value='div')
|
121 |
-
name = divs[0].text
|
122 |
-
legal_name = divs[1].text
|
123 |
-
if not name:
|
124 |
-
name = legal_name
|
125 |
-
address = divs[3].text
|
126 |
-
address_parts = address.split(',')
|
127 |
-
parts = divs[2].text.split(' · ')
|
128 |
-
|
129 |
-
# Get the retailer's link to get more details.
|
130 |
-
link = divs[-1].find_element(by=By.TAG_NAME, value='a')
|
131 |
-
href = link.get_attribute('href')
|
132 |
-
|
133 |
-
# Record the retailer's data.
|
134 |
-
obs = {
|
135 |
-
'address': address,
|
136 |
-
'details_url': href,
|
137 |
-
'business_legal_name': legal_name,
|
138 |
-
'business_dba_name': name,
|
139 |
-
'business_phone': parts[-1],
|
140 |
-
'license_status': parts[0],
|
141 |
-
'license_type': parts[1],
|
142 |
-
'premise_street_address': address_parts[0].strip(),
|
143 |
-
'premise_city': address_parts[1].strip(),
|
144 |
-
'premise_zip_code': address_parts[-1].replace('AZ ', '').strip(),
|
145 |
-
}
|
146 |
-
data.append(obs)
|
147 |
-
|
148 |
-
# Standardize the retailer data.
|
149 |
-
retailers = pd.DataFrame(data)
|
150 |
-
retailers = retailers.assign(
|
151 |
-
business_email=None,
|
152 |
-
business_owner_name=None,
|
153 |
-
business_structure=None,
|
154 |
-
business_image_url=None,
|
155 |
-
business_website=None,
|
156 |
-
id=retailers.index,
|
157 |
-
licensing_authority_id=ARIZONA['licensing_authority_id'],
|
158 |
-
licensing_authority=ARIZONA['licensing_authority'],
|
159 |
-
license_designation='Adult-Use',
|
160 |
-
license_number=None,
|
161 |
-
license_status_date=None,
|
162 |
-
license_term=None,
|
163 |
-
premise_latitude=None,
|
164 |
-
premise_longitude=None,
|
165 |
-
premise_state=STATE,
|
166 |
-
issue_date=None,
|
167 |
-
expiration_date=None,
|
168 |
-
parcel_number=None,
|
169 |
-
activity=None,
|
170 |
-
)
|
171 |
-
|
172 |
-
# Get each retailer's details.
|
173 |
-
cultivators = pd.DataFrame(columns=retailers.columns)
|
174 |
-
manufacturers = pd.DataFrame(columns=retailers.columns)
|
175 |
-
for index, row in retailers.iterrows():
|
176 |
-
|
177 |
-
# Load the licenses's details webpage.
|
178 |
-
driver.get(row['details_url'])
|
179 |
-
detect = (By.CLASS_NAME, 'slds-container_center')
|
180 |
-
WebDriverWait(driver, 30).until(EC.presence_of_element_located(detect))
|
181 |
-
container = driver.find_element(by=By.CLASS_NAME, value='slds-container_center')
|
182 |
-
sleep(4)
|
183 |
-
|
184 |
-
# Get the `business_email`.
|
185 |
-
links = container.find_elements(by=By.TAG_NAME, value='a')
|
186 |
-
for link in links:
|
187 |
-
href = link.get_attribute('href')
|
188 |
-
if href is None: continue
|
189 |
-
if href.startswith('mailto'):
|
190 |
-
business_email = href.replace('mailto:', '')
|
191 |
-
col = retailers.columns.get_loc('business_email')
|
192 |
-
retailers.iat[index, col] = business_email
|
193 |
-
break
|
194 |
-
|
195 |
-
# Get the `license_number`
|
196 |
-
for link in links:
|
197 |
-
href = link.get_attribute('href')
|
198 |
-
if href is None: continue
|
199 |
-
if href.startswith('https://azdhs-licensing'):
|
200 |
-
col = retailers.columns.get_loc('license_number')
|
201 |
-
retailers.iat[index, col] = link.text
|
202 |
-
break
|
203 |
-
|
204 |
-
# Get the `premise_latitude` and `premise_longitude`.
|
205 |
-
for link in links:
|
206 |
-
href = link.get_attribute('href')
|
207 |
-
if href is None: continue
|
208 |
-
if href.startswith('https://maps.google.com/'):
|
209 |
-
coords = href.split('=')[1].split('&')[0].split(',')
|
210 |
-
lat_col = retailers.columns.get_loc('premise_latitude')
|
211 |
-
long_col = retailers.columns.get_loc('premise_longitude')
|
212 |
-
retailers.iat[index, lat_col] = float(coords[0])
|
213 |
-
retailers.iat[index, long_col] = float(coords[1])
|
214 |
-
break
|
215 |
-
|
216 |
-
# Get the `issue_date`.
|
217 |
-
key = 'License Effective'
|
218 |
-
el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text")
|
219 |
-
col = retailers.columns.get_loc('issue_date')
|
220 |
-
retailers.iat[index, col] = el.text
|
221 |
-
|
222 |
-
# Get the `expiration_date`.
|
223 |
-
key = 'License Expires'
|
224 |
-
el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text")
|
225 |
-
col = retailers.columns.get_loc('expiration_date')
|
226 |
-
retailers.iat[index, col] = el.text
|
227 |
-
|
228 |
-
# Get the `business_owner_name`.
|
229 |
-
key = 'Owner / License'
|
230 |
-
el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text")
|
231 |
-
col = retailers.columns.get_loc('expiration_date')
|
232 |
-
retailers.iat[index, col] = el.text
|
233 |
-
|
234 |
-
# Get the `license_designation` ("Services").
|
235 |
-
key = 'Services'
|
236 |
-
el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-rich-text")
|
237 |
-
col = retailers.columns.get_loc('license_designation')
|
238 |
-
retailers.iat[index, col] = el.text
|
239 |
-
|
240 |
-
# Create entries for cultivations.
|
241 |
-
cultivator = retailers.iloc[index].copy()
|
242 |
-
key = 'Offsite Cultivation Address'
|
243 |
-
el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text")
|
244 |
-
address = el.text
|
245 |
-
if address:
|
246 |
-
parts = address.split(',')
|
247 |
-
cultivator['address'] = address
|
248 |
-
cultivator['premise_street_address'] = parts[0]
|
249 |
-
cultivator['premise_city'] = parts[1].strip()
|
250 |
-
cultivator['premise_zip_code'] = parts[-1].replace(STATE, '').strip()
|
251 |
-
cultivator['license_type'] = 'Offsite Cultivation'
|
252 |
-
cultivators.append(cultivator, ignore_index=True)
|
253 |
-
|
254 |
-
# Create entries for manufacturers.
|
255 |
-
manufacturer = retailers.iloc[index].copy()
|
256 |
-
key = 'Manufacture Address'
|
257 |
-
el = container.find_element_by_xpath(f"//p[contains(text(),'{key}')]/following-sibling::lightning-formatted-text")
|
258 |
-
address = el.text
|
259 |
-
if address:
|
260 |
-
parts = address.split(',')
|
261 |
-
manufacturer['address'] = address
|
262 |
-
manufacturer['premise_street_address'] = parts[0]
|
263 |
-
manufacturer['premise_city'] = parts[1].strip()
|
264 |
-
manufacturer['premise_zip_code'] = parts[-1].replace(STATE, '').strip()
|
265 |
-
manufacturer['license_type'] = 'Offsite Cultivation'
|
266 |
-
manufacturers.append(manufacturer, ignore_index=True)
|
267 |
-
|
268 |
-
# End the browser session.
|
269 |
-
service.stop()
|
270 |
-
retailers.drop(column=['address', 'details_url'], inplace=True)
|
271 |
-
|
272 |
-
# Lookup counties by zip code.
|
273 |
-
retailers['premise_county'] = retailers['premise_zip_code'].apply(county_from_zip)
|
274 |
-
cultivators['premise_county'] = cultivators['premise_zip_code'].apply(county_from_zip)
|
275 |
-
manufacturers['premise_county'] = manufacturers['premise_zip_code'].apply(county_from_zip)
|
276 |
-
|
277 |
-
# Setup geocoding
|
278 |
-
config = dotenv_values(env_file)
|
279 |
-
api_key = config['GOOGLE_MAPS_API_KEY']
|
280 |
-
drop_cols = ['state', 'state_name', 'county', 'address', 'formatted_address']
|
281 |
-
gis_cols = {'latitude': 'premise_latitude', 'longitude': 'premise_longitude'}
|
282 |
-
|
283 |
-
# # Geocode cultivators.
|
284 |
-
# cultivators = geocode_addresses(cultivators, api_key=api_key, address_field='address')
|
285 |
-
# cultivators.drop(columns=drop_cols, inplace=True)
|
286 |
-
# cultivators.rename(columns=gis_cols, inplace=True)
|
287 |
-
|
288 |
-
# # Geocode manufacturers.
|
289 |
-
# manufacturers = geocode_addresses(manufacturers, api_key=api_key, address_field='address')
|
290 |
-
# manufacturers.drop(columns=drop_cols, inplace=True)
|
291 |
-
# manufacturers.rename(columns=gis_cols, inplace=True)
|
292 |
-
|
293 |
-
# TODO: Lookup business website and image.
|
294 |
-
|
295 |
-
# Aggregate all licenses.
|
296 |
-
licenses = pd.concat([retailers, cultivators, manufacturers])
|
297 |
-
|
298 |
-
# Get the refreshed date.
|
299 |
-
timestamp = datetime.now().isoformat()
|
300 |
-
licenses['data_refreshed_date'] = timestamp
|
301 |
-
retailers['data_refreshed_date'] = timestamp
|
302 |
-
# cultivators['data_refreshed_date'] = timestamp
|
303 |
-
# manufacturers['data_refreshed_date'] = timestamp
|
304 |
-
|
305 |
-
# Save and return the data.
|
306 |
-
if data_dir is not None:
|
307 |
-
timestamp = timestamp[:19].replace(':', '-')
|
308 |
-
licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
309 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
310 |
-
# cultivators.to_csv(f'{data_dir}/cultivators-{STATE.lower()}-{timestamp}.csv', index=False)
|
311 |
-
# manufacturers.to_csv(f'{data_dir}/manufacturers-{STATE.lower()}-{timestamp}.csv', index=False)
|
312 |
-
return licenses
|
313 |
-
|
314 |
-
|
315 |
-
# === Test ===
|
316 |
-
if __name__ == '__main__':
|
317 |
-
|
318 |
-
# Support command line usage.
|
319 |
-
import argparse
|
320 |
-
try:
|
321 |
-
arg_parser = argparse.ArgumentParser()
|
322 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
323 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
324 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
325 |
-
args = arg_parser.parse_args()
|
326 |
-
except SystemExit:
|
327 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
328 |
-
|
329 |
-
# Get licenses, saving them to the specified directory.
|
330 |
-
data_dir = args.get('d', args.get('data_dir'))
|
331 |
-
env_file = args.get('env_file')
|
332 |
-
data = get_licenses_az(data_dir, env_file=env_file)
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_ca.py
DELETED
@@ -1,112 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get California Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/16/2022
|
9 |
-
Updated: 9/27/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect California cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- California Department of Cannabis Control Cannabis Unified License Search
|
19 |
-
URL: <https://search.cannabis.ca.gov/>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from time import sleep
|
26 |
-
from typing import Optional
|
27 |
-
|
28 |
-
# External imports.
|
29 |
-
from cannlytics.utils import camel_to_snake
|
30 |
-
from cannlytics.utils.constants import DEFAULT_HEADERS
|
31 |
-
import pandas as pd
|
32 |
-
import requests
|
33 |
-
|
34 |
-
|
35 |
-
# Specify where your data lives.
|
36 |
-
DATA_DIR = '../data/ca'
|
37 |
-
|
38 |
-
|
39 |
-
def get_licenses_ca(
|
40 |
-
data_dir: Optional[str] = None,
|
41 |
-
page_size: Optional[int] = 50,
|
42 |
-
pause: Optional[float] = 0.2,
|
43 |
-
starting_page: Optional[int] = 1,
|
44 |
-
ending_page: Optional[int] = None,
|
45 |
-
verbose: Optional[bool] = False,
|
46 |
-
search: Optional[str] = '',
|
47 |
-
**kwargs,
|
48 |
-
):
|
49 |
-
"""Get California cannabis license data."""
|
50 |
-
|
51 |
-
# Define the license data API.
|
52 |
-
base = 'https://as-cdt-pub-vip-cannabis-ww-p-002.azurewebsites.net'
|
53 |
-
endpoint = '/licenses/filteredSearch'
|
54 |
-
query = f'{base}{endpoint}'
|
55 |
-
params = {'pageSize': page_size, 'searchQuery': search}
|
56 |
-
|
57 |
-
# Iterate over all of the pages to get all of the data.
|
58 |
-
page = int(starting_page)
|
59 |
-
licenses = []
|
60 |
-
iterate = True
|
61 |
-
while(iterate):
|
62 |
-
params['pageNumber'] = page
|
63 |
-
response = requests.get(query, headers=DEFAULT_HEADERS, params=params)
|
64 |
-
body = response.json()
|
65 |
-
data = body['data']
|
66 |
-
licenses.extend(data)
|
67 |
-
if not body['metadata']['hasNext']:
|
68 |
-
iterate = False
|
69 |
-
if verbose:
|
70 |
-
print('Recorded %i/%i pages.' % (page, body['metadata']['totalPages']))
|
71 |
-
if ending_page is not None:
|
72 |
-
if page == ending_page:
|
73 |
-
iterate = False
|
74 |
-
page += 1
|
75 |
-
sleep(pause)
|
76 |
-
|
77 |
-
# Standardize the licensee data.
|
78 |
-
license_data = pd.DataFrame(licenses)
|
79 |
-
columns = list(license_data.columns)
|
80 |
-
columns = [camel_to_snake(x) for x in columns]
|
81 |
-
license_data.columns = columns
|
82 |
-
|
83 |
-
# TODO: Lookup business website and image.
|
84 |
-
license_data['business_image_url'] = None
|
85 |
-
license_data['business_website'] = None
|
86 |
-
|
87 |
-
# Restrict to only active licenses.
|
88 |
-
license_data = license_data.loc[license_data['license_status'] == 'Active']
|
89 |
-
|
90 |
-
# Save and return the data.
|
91 |
-
if data_dir is not None:
|
92 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
93 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
94 |
-
license_data.to_csv(f'{data_dir}/licenses-ca-{timestamp}.csv', index=False)
|
95 |
-
return license_data
|
96 |
-
|
97 |
-
if __name__ == '__main__':
|
98 |
-
|
99 |
-
# Support command line usage.
|
100 |
-
import argparse
|
101 |
-
try:
|
102 |
-
arg_parser = argparse.ArgumentParser()
|
103 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
104 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
105 |
-
# Future work: Support the rest of the arguments from the CL.
|
106 |
-
args = arg_parser.parse_args()
|
107 |
-
except SystemExit:
|
108 |
-
args = {'d': DATA_DIR}
|
109 |
-
|
110 |
-
# Get California licenses, saving them to the specified directory.
|
111 |
-
data_dir = args.get('d', args.get('data_dir'))
|
112 |
-
get_licenses_ca(data_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_co.py
DELETED
@@ -1,221 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Colorado Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/4/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Colorado cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Colorado Department of Revenue | Marijuana Enforcement Division
|
19 |
-
URL: <https://sbg.colorado.gov/med/licensed-facilities>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from time import sleep
|
26 |
-
from typing import Optional
|
27 |
-
|
28 |
-
# External imports.
|
29 |
-
from bs4 import BeautifulSoup
|
30 |
-
from cannlytics.data.data import load_google_sheet
|
31 |
-
from cannlytics.data.gis import search_for_address
|
32 |
-
from dotenv import dotenv_values
|
33 |
-
import pandas as pd
|
34 |
-
import requests
|
35 |
-
|
36 |
-
|
37 |
-
# Specify where your data lives.
|
38 |
-
DATA_DIR = '../data/co'
|
39 |
-
ENV_FILE = '../.env'
|
40 |
-
|
41 |
-
# Specify state-specific constants.
|
42 |
-
STATE = 'CO'
|
43 |
-
COLORADO = {
|
44 |
-
'licensing_authority_id': 'MED',
|
45 |
-
'licensing_authority': 'Colorado Marijuana Enforcement Division',
|
46 |
-
'licenses_url': 'https://sbg.colorado.gov/med/licensed-facilities',
|
47 |
-
'licenses': {
|
48 |
-
'columns': {
|
49 |
-
'LicenseNumber': 'license_number',
|
50 |
-
'FacilityName': 'business_legal_name',
|
51 |
-
'DBA': 'business_dba_name',
|
52 |
-
'City': 'premise_city',
|
53 |
-
'ZipCode': 'premise_zip_code',
|
54 |
-
'DateUpdated': 'data_refreshed_date',
|
55 |
-
'Licensee Name ': 'business_legal_name',
|
56 |
-
'License # ': 'license_number',
|
57 |
-
'City ': 'premise_city',
|
58 |
-
'Zip': 'premise_zip_code',
|
59 |
-
},
|
60 |
-
'drop_columns': [
|
61 |
-
'FacilityType', # This causes an error with `license_type`.
|
62 |
-
'Potency',
|
63 |
-
'Solvents',
|
64 |
-
'Microbial',
|
65 |
-
'Pesticides',
|
66 |
-
'Mycotoxin',
|
67 |
-
'Elemental Impurities',
|
68 |
-
'Water Activity'
|
69 |
-
]
|
70 |
-
}
|
71 |
-
}
|
72 |
-
|
73 |
-
|
74 |
-
def get_licenses_co(
|
75 |
-
data_dir: Optional[str] = None,
|
76 |
-
env_file: Optional[str] = '.env',
|
77 |
-
):
|
78 |
-
"""Get Colorado cannabis license data."""
|
79 |
-
|
80 |
-
# Get the licenses webpage.
|
81 |
-
url = COLORADO['licenses_url']
|
82 |
-
response = requests.get(url)
|
83 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
84 |
-
|
85 |
-
# Get the Google Sheets for each license type.
|
86 |
-
docs = {}
|
87 |
-
links = soup.find_all('a')
|
88 |
-
for link in links:
|
89 |
-
try:
|
90 |
-
href = link['href']
|
91 |
-
except KeyError:
|
92 |
-
pass
|
93 |
-
if 'docs.google' in href:
|
94 |
-
docs[link.text] = href
|
95 |
-
|
96 |
-
# Download each "Medical" and "Retail" Google Sheet.
|
97 |
-
licenses = pd.DataFrame()
|
98 |
-
license_designations = ['Medical', 'Retail']
|
99 |
-
columns=COLORADO['licenses']['columns']
|
100 |
-
drop_columns=COLORADO['licenses']['drop_columns']
|
101 |
-
for license_type, doc in docs.items():
|
102 |
-
for license_designation in license_designations:
|
103 |
-
license_data = load_google_sheet(doc, license_designation)
|
104 |
-
license_data['license_type'] = license_type
|
105 |
-
license_data['license_designation'] = license_designation
|
106 |
-
license_data.rename(columns=columns, inplace=True)
|
107 |
-
license_data.drop(columns=drop_columns, inplace=True, errors='ignore')
|
108 |
-
licenses = pd.concat([licenses, license_data])
|
109 |
-
sleep(0.22)
|
110 |
-
|
111 |
-
# Standardize the license data.
|
112 |
-
licenses = licenses.assign(
|
113 |
-
id=licenses['license_number'],
|
114 |
-
license_status=None,
|
115 |
-
licensing_authority_id=COLORADO['licensing_authority_id'],
|
116 |
-
licensing_authority=COLORADO['licensing_authority'],
|
117 |
-
license_designation='Adult-Use',
|
118 |
-
premise_state=STATE,
|
119 |
-
license_status_date=None,
|
120 |
-
license_term=None,
|
121 |
-
issue_date=None,
|
122 |
-
expiration_date=None,
|
123 |
-
business_owner_name=None,
|
124 |
-
business_structure=None,
|
125 |
-
activity=None,
|
126 |
-
parcel_number=None,
|
127 |
-
business_phone=None,
|
128 |
-
business_email=None,
|
129 |
-
business_image_url=None,
|
130 |
-
)
|
131 |
-
|
132 |
-
# Fill empty DBA names and strip trailing whitespace.
|
133 |
-
licenses.loc[licenses['business_dba_name'] == '', 'business_dba_name'] = licenses['business_legal_name']
|
134 |
-
licenses.business_dba_name.fillna(licenses.business_legal_name, inplace=True)
|
135 |
-
licenses.business_legal_name.fillna(licenses.business_dba_name, inplace=True)
|
136 |
-
licenses = licenses.loc[~licenses.business_dba_name.isna()]
|
137 |
-
licenses.business_dba_name = licenses.business_dba_name.apply(lambda x: x.strip())
|
138 |
-
licenses.business_legal_name = licenses.business_legal_name.apply(lambda x: x.strip())
|
139 |
-
|
140 |
-
# Optional: Turn all capital case to title case.
|
141 |
-
|
142 |
-
# Clean zip code column.
|
143 |
-
licenses['premise_zip_code'] = licenses['premise_zip_code'].apply(
|
144 |
-
lambda x: str(round(x)) if pd.notnull(x) else x
|
145 |
-
)
|
146 |
-
licenses.loc[licenses['premise_zip_code'].isnull(), 'premise_zip_code'] = ''
|
147 |
-
|
148 |
-
# Search for address for each retail license.
|
149 |
-
# Only search for a query once, then re-use the response.
|
150 |
-
# Note: There is probably a much, much more efficient way to do this!!!
|
151 |
-
config = dotenv_values(env_file)
|
152 |
-
api_key = config['GOOGLE_MAPS_API_KEY']
|
153 |
-
cols = ['business_dba_name', 'premise_city', 'premise_state', 'premise_zip_code']
|
154 |
-
retailers = licenses.loc[licenses['license_type'] == 'Stores']
|
155 |
-
retailers['query'] = retailers[cols].apply(
|
156 |
-
lambda row: ', '.join(row.values.astype(str)),
|
157 |
-
axis=1,
|
158 |
-
)
|
159 |
-
queries = {}
|
160 |
-
fields = [
|
161 |
-
'formatted_address',
|
162 |
-
'formatted_phone_number',
|
163 |
-
'geometry/location/lat',
|
164 |
-
'geometry/location/lng',
|
165 |
-
'website',
|
166 |
-
]
|
167 |
-
retailers = retailers.reset_index(drop=True)
|
168 |
-
retailers = retailers.assign(
|
169 |
-
premise_street_address=None,
|
170 |
-
premise_county=None,
|
171 |
-
premise_latitude=None,
|
172 |
-
premise_longitude=None,
|
173 |
-
business_website=None,
|
174 |
-
business_phone=None,
|
175 |
-
)
|
176 |
-
for index, row in retailers.iterrows():
|
177 |
-
query = row['query']
|
178 |
-
gis_data = queries.get(query)
|
179 |
-
if gis_data is None:
|
180 |
-
try:
|
181 |
-
gis_data = search_for_address(query, api_key=api_key, fields=fields)
|
182 |
-
except:
|
183 |
-
gis_data = {}
|
184 |
-
queries[query] = gis_data
|
185 |
-
retailers.iat[index, retailers.columns.get_loc('premise_street_address')] = gis_data.get('street')
|
186 |
-
retailers.iat[index, retailers.columns.get_loc('premise_county')] = gis_data.get('county')
|
187 |
-
retailers.iat[index, retailers.columns.get_loc('premise_latitude')] = gis_data.get('latitude')
|
188 |
-
retailers.iat[index, retailers.columns.get_loc('premise_longitude')] = gis_data.get('longitude')
|
189 |
-
retailers.iat[index, retailers.columns.get_loc('business_website')] = gis_data.get('website')
|
190 |
-
retailers.iat[index, retailers.columns.get_loc('business_phone')] = gis_data.get('formatted_phone_number')
|
191 |
-
|
192 |
-
# Clean-up after getting GIS data.
|
193 |
-
retailers.drop(columns=['query'], inplace=True)
|
194 |
-
|
195 |
-
# Save and return the data.
|
196 |
-
if data_dir is not None:
|
197 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
198 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
199 |
-
licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
200 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
201 |
-
return licenses
|
202 |
-
|
203 |
-
|
204 |
-
# === Test ===
|
205 |
-
if __name__ == '__main__':
|
206 |
-
|
207 |
-
# Support command line usage.
|
208 |
-
import argparse
|
209 |
-
try:
|
210 |
-
arg_parser = argparse.ArgumentParser()
|
211 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
212 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
213 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
214 |
-
args = arg_parser.parse_args()
|
215 |
-
except SystemExit:
|
216 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
217 |
-
|
218 |
-
# Get licenses, saving them to the specified directory.
|
219 |
-
data_dir = args.get('d', args.get('data_dir'))
|
220 |
-
env_file = args.get('env_file')
|
221 |
-
data = get_licenses_co(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_ct.py
DELETED
@@ -1,163 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Connecticut Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/3/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Connecticut cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Connecticut State Department of Consumer Protection
|
19 |
-
URL: <https://portal.ct.gov/DCP/Medical-Marijuana-Program/Connecticut-Medical-Marijuana-Dispensary-Facilities>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from typing import Optional
|
26 |
-
|
27 |
-
# External imports.
|
28 |
-
from bs4 import BeautifulSoup
|
29 |
-
from cannlytics.data.gis import geocode_addresses
|
30 |
-
from dotenv import dotenv_values
|
31 |
-
import pandas as pd
|
32 |
-
import requests
|
33 |
-
|
34 |
-
|
35 |
-
# Specify where your data lives.
|
36 |
-
DATA_DIR = '../data/ct'
|
37 |
-
ENV_FILE = '../.env'
|
38 |
-
|
39 |
-
# Specify state-specific constants.
|
40 |
-
STATE = 'CT'
|
41 |
-
CONNECTICUT = {
|
42 |
-
'licensing_authority_id': 'CSDCP',
|
43 |
-
'licensing_authority': 'Connecticut State Department of Consumer Protection',
|
44 |
-
'licenses_url': 'https://portal.ct.gov/DCP/Medical-Marijuana-Program/Connecticut-Medical-Marijuana-Dispensary-Facilities',
|
45 |
-
'retailers': {
|
46 |
-
'columns': [
|
47 |
-
'business_legal_name',
|
48 |
-
'address',
|
49 |
-
'business_website',
|
50 |
-
'business_email',
|
51 |
-
'business_phone',
|
52 |
-
]
|
53 |
-
}
|
54 |
-
}
|
55 |
-
|
56 |
-
|
57 |
-
def get_licenses_ct(
|
58 |
-
data_dir: Optional[str] = None,
|
59 |
-
env_file: Optional[str] = '.env',
|
60 |
-
):
|
61 |
-
"""Get Connecticut cannabis license data."""
|
62 |
-
|
63 |
-
# Get the license webpage.
|
64 |
-
url = CONNECTICUT['licenses_url']
|
65 |
-
response = requests.get(url)
|
66 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
67 |
-
|
68 |
-
# Extract the license data.
|
69 |
-
data = []
|
70 |
-
columns = CONNECTICUT['retailers']['columns']
|
71 |
-
table = soup.find('table')
|
72 |
-
rows = table.find_all('tr')
|
73 |
-
for row in rows[1:]:
|
74 |
-
cells = row.find_all('td')
|
75 |
-
obs = {}
|
76 |
-
for i, cell in enumerate(cells):
|
77 |
-
column = columns[i]
|
78 |
-
obs[column] = cell.text
|
79 |
-
data.append(obs)
|
80 |
-
|
81 |
-
# Standardize the license data.
|
82 |
-
retailers = pd.DataFrame(data)
|
83 |
-
retailers = retailers.assign(
|
84 |
-
id=retailers.index,
|
85 |
-
license_status=None,
|
86 |
-
business_dba_name=retailers['business_legal_name'],
|
87 |
-
license_number=None,
|
88 |
-
licensing_authority_id=CONNECTICUT['licensing_authority_id'],
|
89 |
-
licensing_authority=CONNECTICUT['licensing_authority'],
|
90 |
-
license_designation='Adult-Use',
|
91 |
-
premise_state=STATE,
|
92 |
-
license_status_date=None,
|
93 |
-
license_term=None,
|
94 |
-
issue_date=None,
|
95 |
-
expiration_date=None,
|
96 |
-
business_owner_name=None,
|
97 |
-
business_structure=None,
|
98 |
-
activity=None,
|
99 |
-
parcel_number=None,
|
100 |
-
business_image_url=None,
|
101 |
-
license_type=None,
|
102 |
-
)
|
103 |
-
|
104 |
-
# Get address parts.
|
105 |
-
retailers['premise_street_address'] = retailers['address'].apply(
|
106 |
-
lambda x: x.split(',')[0]
|
107 |
-
)
|
108 |
-
retailers['premise_city'] = retailers['address'].apply(
|
109 |
-
lambda x: x.split('CT')[0].strip().split(',')[-2]
|
110 |
-
)
|
111 |
-
retailers['premise_zip_code'] = retailers['address'].apply(
|
112 |
-
lambda x: x.split('CT')[-1].replace('\xa0', '').replace(',', '').strip()
|
113 |
-
)
|
114 |
-
|
115 |
-
# Geocode the licenses.
|
116 |
-
config = dotenv_values(env_file)
|
117 |
-
google_maps_api_key = config['GOOGLE_MAPS_API_KEY']
|
118 |
-
retailers = geocode_addresses(
|
119 |
-
retailers,
|
120 |
-
api_key=google_maps_api_key,
|
121 |
-
address_field='address',
|
122 |
-
)
|
123 |
-
retailers['premise_city'] = retailers['formatted_address'].apply(
|
124 |
-
lambda x: x.split(', ')[1].split(',')[0] if STATE in str(x) else x
|
125 |
-
)
|
126 |
-
drop_cols = ['state', 'state_name', 'address', 'formatted_address']
|
127 |
-
retailers.drop(columns=drop_cols, inplace=True)
|
128 |
-
gis_cols = {
|
129 |
-
'county': 'premise_county',
|
130 |
-
'latitude': 'premise_latitude',
|
131 |
-
'longitude': 'premise_longitude'
|
132 |
-
}
|
133 |
-
retailers.rename(columns=gis_cols, inplace=True)
|
134 |
-
|
135 |
-
# Get the refreshed date.
|
136 |
-
retailers['data_refreshed_date'] = datetime.now().isoformat()
|
137 |
-
|
138 |
-
# Save and return the data.
|
139 |
-
if data_dir is not None:
|
140 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
141 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
142 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
143 |
-
return retailers
|
144 |
-
|
145 |
-
|
146 |
-
# === Test ===
|
147 |
-
if __name__ == '__main__':
|
148 |
-
|
149 |
-
# Support command line usage.
|
150 |
-
import argparse
|
151 |
-
try:
|
152 |
-
arg_parser = argparse.ArgumentParser()
|
153 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
154 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
155 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
156 |
-
args = arg_parser.parse_args()
|
157 |
-
except SystemExit:
|
158 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
159 |
-
|
160 |
-
# Get licenses, saving them to the specified directory.
|
161 |
-
data_dir = args.get('d', args.get('data_dir'))
|
162 |
-
env_file = args.get('env_file')
|
163 |
-
data = get_licenses_ct(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_il.py
DELETED
@@ -1,194 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Illinois Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/3/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Illinois cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Illinois Department of Financial and Professional Regulation
|
19 |
-
Licensed Adult Use Cannabis Dispensaries
|
20 |
-
URL: <https://www.idfpr.com/LicenseLookup/AdultUseDispensaries.pdf>
|
21 |
-
|
22 |
-
"""
|
23 |
-
# Standard imports.
|
24 |
-
from datetime import datetime
|
25 |
-
import os
|
26 |
-
from typing import Optional
|
27 |
-
|
28 |
-
# External imports.
|
29 |
-
from dotenv import dotenv_values
|
30 |
-
from cannlytics.data.gis import geocode_addresses
|
31 |
-
import pandas as pd
|
32 |
-
import pdfplumber
|
33 |
-
import requests
|
34 |
-
|
35 |
-
|
36 |
-
# Specify where your data lives.
|
37 |
-
DATA_DIR = '../data/il'
|
38 |
-
ENV_FILE = '../.env'
|
39 |
-
|
40 |
-
# Specify state-specific constants.
|
41 |
-
STATE = 'IL'
|
42 |
-
ILLINOIS = {
|
43 |
-
'licensing_authority_id': 'IDFPR',
|
44 |
-
'licensing_authority': 'Illinois Department of Financial and Professional Regulation',
|
45 |
-
'retailers': {
|
46 |
-
'url': 'https://www.idfpr.com/LicenseLookup/AdultUseDispensaries.pdf',
|
47 |
-
'columns': [
|
48 |
-
'business_legal_name',
|
49 |
-
'business_dba_name',
|
50 |
-
'address',
|
51 |
-
'medical',
|
52 |
-
'issue_date',
|
53 |
-
'license_number',
|
54 |
-
],
|
55 |
-
},
|
56 |
-
}
|
57 |
-
|
58 |
-
|
59 |
-
def get_licenses_il(
|
60 |
-
data_dir: Optional[str] = None,
|
61 |
-
env_file: Optional[str] = '.env',
|
62 |
-
**kwargs,
|
63 |
-
):
|
64 |
-
"""Get Illinois cannabis license data."""
|
65 |
-
|
66 |
-
# Create necessary directories.
|
67 |
-
pdf_dir = f'{data_dir}/pdfs'
|
68 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
69 |
-
if not os.path.exists(pdf_dir): os.makedirs(pdf_dir)
|
70 |
-
|
71 |
-
# Download the retailers PDF.
|
72 |
-
retailers_url = ILLINOIS['retailers']['url']
|
73 |
-
filename = f'{pdf_dir}/illinois_retailers.pdf'
|
74 |
-
response = requests.get(retailers_url)
|
75 |
-
with open(filename, 'wb') as f:
|
76 |
-
f.write(response.content)
|
77 |
-
|
78 |
-
# Read the retailers PDF.
|
79 |
-
pdf = pdfplumber.open(filename)
|
80 |
-
|
81 |
-
# Get the table data, excluding the headers and removing empty cells.
|
82 |
-
table_data = []
|
83 |
-
for i, page in enumerate(pdf.pages):
|
84 |
-
table = page.extract_table()
|
85 |
-
if i == 0:
|
86 |
-
table = table[4:]
|
87 |
-
table = [c for row in table
|
88 |
-
if (c := [elem for elem in row if elem is not None])]
|
89 |
-
table_data += table
|
90 |
-
|
91 |
-
# Standardize the data.
|
92 |
-
licensee_columns = ILLINOIS['retailers']['columns']
|
93 |
-
retailers = pd.DataFrame(table_data, columns=licensee_columns)
|
94 |
-
retailers = retailers.assign(
|
95 |
-
licensing_authority_id=ILLINOIS['licensing_authority_id'],
|
96 |
-
licensing_authority=ILLINOIS['licensing_authority'],
|
97 |
-
license_designation='Adult-Use',
|
98 |
-
premise_state=STATE,
|
99 |
-
license_status='Active',
|
100 |
-
license_status_date=None,
|
101 |
-
license_type='Commercial - Retailer',
|
102 |
-
license_term=None,
|
103 |
-
expiration_date=None,
|
104 |
-
business_legal_name=retailers['business_dba_name'],
|
105 |
-
business_owner_name=None,
|
106 |
-
business_structure=None,
|
107 |
-
business_email=None,
|
108 |
-
activity=None,
|
109 |
-
parcel_number=None,
|
110 |
-
id=retailers['license_number'],
|
111 |
-
business_image_url=None,
|
112 |
-
business_website=None,
|
113 |
-
)
|
114 |
-
|
115 |
-
# Apply `medical` to `license_designation`
|
116 |
-
retailers.loc[retailers['medical'] == 'Yes', 'license_designation'] = 'Adult-Use and Medicinal'
|
117 |
-
retailers.drop(columns=['medical'], inplace=True)
|
118 |
-
|
119 |
-
# Clean the organization names.
|
120 |
-
retailers['business_legal_name'] = retailers['business_legal_name'].str.replace('\n', '', regex=False)
|
121 |
-
retailers['business_dba_name'] = retailers['business_dba_name'].str.replace('*', '', regex=False)
|
122 |
-
|
123 |
-
# Separate address into 'street', 'city', 'state', 'zip_code', 'phone_number'.
|
124 |
-
streets, cities, states, zip_codes, phone_numbers = [], [], [], [], []
|
125 |
-
for index, row in retailers.iterrows():
|
126 |
-
parts = row.address.split(' \n')
|
127 |
-
streets.append(parts[0])
|
128 |
-
phone_numbers.append(parts[-1])
|
129 |
-
locales = parts[1]
|
130 |
-
city_locales = locales.split(', ')
|
131 |
-
state_locales = city_locales[-1].split(' ')
|
132 |
-
cities.append(city_locales[0])
|
133 |
-
states.append(state_locales[0])
|
134 |
-
zip_codes.append(state_locales[-1])
|
135 |
-
retailers['premise_street_address'] = pd.Series(streets)
|
136 |
-
retailers['premise_city'] = pd.Series(cities)
|
137 |
-
retailers['premise_state'] = pd.Series(states)
|
138 |
-
retailers['premise_zip_code'] = pd.Series(zip_codes)
|
139 |
-
retailers['business_phone'] = pd.Series(phone_numbers)
|
140 |
-
|
141 |
-
# Convert the issue date to ISO format.
|
142 |
-
retailers['issue_date'] = retailers['issue_date'].apply(
|
143 |
-
lambda x: pd.to_datetime(x).isoformat()
|
144 |
-
)
|
145 |
-
|
146 |
-
# Get the refreshed date.
|
147 |
-
date = pdf.metadata['ModDate'].replace('D:', '')
|
148 |
-
date = date[:4] + '-' + date[4:6] + '-' + date[6:8] + 'T' + date[8:10] + \
|
149 |
-
':' + date[10:12] + ':' + date[12:].replace("'", ':').rstrip(':')
|
150 |
-
retailers['data_refreshed_date'] = date
|
151 |
-
|
152 |
-
# Geocode licenses to get `premise_latitude` and `premise_longitude`.
|
153 |
-
config = dotenv_values(env_file)
|
154 |
-
google_maps_api_key = config['GOOGLE_MAPS_API_KEY']
|
155 |
-
retailers['address'] = retailers['address'].str.replace('*', '', regex=False)
|
156 |
-
retailers = geocode_addresses(
|
157 |
-
retailers,
|
158 |
-
api_key=google_maps_api_key,
|
159 |
-
address_field='address',
|
160 |
-
)
|
161 |
-
drop_cols = ['state', 'state_name', 'address', 'formatted_address']
|
162 |
-
retailers.drop(columns=drop_cols, inplace=True)
|
163 |
-
gis_cols = {
|
164 |
-
'county': 'premise_county',
|
165 |
-
'latitude': 'premise_latitude',
|
166 |
-
'longitude': 'premise_longitude'
|
167 |
-
}
|
168 |
-
retailers.rename(columns=gis_cols, inplace=True)
|
169 |
-
|
170 |
-
# Save and return the data.
|
171 |
-
if data_dir is not None:
|
172 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
173 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
174 |
-
return retailers
|
175 |
-
|
176 |
-
|
177 |
-
# === Test ===
|
178 |
-
if __name__ == '__main__':
|
179 |
-
|
180 |
-
# Support command line usage.
|
181 |
-
import argparse
|
182 |
-
try:
|
183 |
-
arg_parser = argparse.ArgumentParser()
|
184 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
185 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
186 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
187 |
-
args = arg_parser.parse_args()
|
188 |
-
except SystemExit:
|
189 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
190 |
-
|
191 |
-
# Get licenses, saving them to the specified directory.
|
192 |
-
data_dir = args.get('d', args.get('data_dir'))
|
193 |
-
env_file = args.get('env_file')
|
194 |
-
data = get_licenses_il(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_ma.py
DELETED
@@ -1,146 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Massachusetts Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/7/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Massachusetts cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Massachusetts Cannabis Control Commission Data Catalog
|
19 |
-
URL: <https://masscannabiscontrol.com/open-data/data-catalog/>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from typing import Optional
|
26 |
-
|
27 |
-
# External imports.
|
28 |
-
from cannlytics.data.opendata import OpenData
|
29 |
-
|
30 |
-
|
31 |
-
# Specify where your data lives.
|
32 |
-
DATA_DIR = '../data/ma'
|
33 |
-
|
34 |
-
# Specify state-specific constants.
|
35 |
-
STATE = 'MA'
|
36 |
-
MASSACHUSETTS = {
|
37 |
-
'licensing_authority_id': 'MACCC',
|
38 |
-
'licensing_authority': 'Massachusetts Cannabis Control Commission',
|
39 |
-
'licenses': {
|
40 |
-
'columns': {
|
41 |
-
'license_number': 'license_number',
|
42 |
-
'business_name': 'business_legal_name',
|
43 |
-
'establishment_address_1': 'premise_street_address',
|
44 |
-
'establishment_address_2': 'premise_street_address_2',
|
45 |
-
'establishment_city': 'premise_city',
|
46 |
-
'establishment_zipcode': 'premise_zip_code',
|
47 |
-
'county': 'premise_county',
|
48 |
-
'license_type': 'license_type',
|
49 |
-
'application_status': 'license_status',
|
50 |
-
'lic_status': 'license_term',
|
51 |
-
'approved_license_type': 'license_designation',
|
52 |
-
'commence_operations_date': 'license_status_date',
|
53 |
-
'massachusetts_business': 'id',
|
54 |
-
'dba_name': 'business_dba_name',
|
55 |
-
'establishment_activities': 'activity',
|
56 |
-
'cccupdatedate': 'data_refreshed_date',
|
57 |
-
'establishment_state': 'premise_state',
|
58 |
-
'latitude': 'premise_latitude',
|
59 |
-
'longitude': 'premise_longitude',
|
60 |
-
},
|
61 |
-
'drop': [
|
62 |
-
'square_footage_establishment',
|
63 |
-
'cooperative_total_canopy',
|
64 |
-
'cooperative_cultivation_environment',
|
65 |
-
'establishment_cultivation_environment',
|
66 |
-
'abutters_count',
|
67 |
-
'is_abutters_notified',
|
68 |
-
'business_zipcode',
|
69 |
-
'dph_rmd_number',
|
70 |
-
'geocoded_county',
|
71 |
-
'geocoded_address',
|
72 |
-
'name_of_rmd',
|
73 |
-
'priority_applicant_type',
|
74 |
-
'rmd_priority_certification',
|
75 |
-
'dba_registration_city',
|
76 |
-
'county_lat',
|
77 |
-
'county_long',
|
78 |
-
]
|
79 |
-
},
|
80 |
-
}
|
81 |
-
|
82 |
-
|
83 |
-
def get_licenses_ma(
|
84 |
-
data_dir: Optional[str] = None,
|
85 |
-
**kwargs,
|
86 |
-
):
|
87 |
-
"""Get Massachusetts cannabis license data."""
|
88 |
-
|
89 |
-
# Get the licenses data.
|
90 |
-
ccc = OpenData()
|
91 |
-
licenses = ccc.get_licensees('approved')
|
92 |
-
|
93 |
-
# Standardize the licenses data.
|
94 |
-
constants = MASSACHUSETTS['licenses']
|
95 |
-
licenses.drop(columns=constants['drop'], inplace=True)
|
96 |
-
licenses.rename(columns=constants['columns'], inplace=True)
|
97 |
-
licenses = licenses.assign(
|
98 |
-
licensing_authority_id=MASSACHUSETTS['licensing_authority_id'],
|
99 |
-
licensing_authority=MASSACHUSETTS['licensing_authority'],
|
100 |
-
business_structure=None,
|
101 |
-
business_email=None,
|
102 |
-
business_owner_name=None,
|
103 |
-
parcel_number=None,
|
104 |
-
issue_date=None,
|
105 |
-
expiration_date=None,
|
106 |
-
business_image_url=None,
|
107 |
-
business_website=None,
|
108 |
-
business_phone=None,
|
109 |
-
)
|
110 |
-
|
111 |
-
# Append `premise_street_address_2` to `premise_street_address`.
|
112 |
-
cols = ['premise_street_address', 'premise_street_address_2']
|
113 |
-
licenses['premise_street_address'] = licenses[cols].apply(
|
114 |
-
lambda x : '{} {}'.format(x[0].strip(), x[1]).replace('nan', '').strip().replace(' ', ' '),
|
115 |
-
axis=1,
|
116 |
-
)
|
117 |
-
licenses.drop(columns=['premise_street_address_2'], inplace=True)
|
118 |
-
|
119 |
-
# Optional: Look-up business websites for each license.
|
120 |
-
|
121 |
-
# Save and return the data.
|
122 |
-
if data_dir is not None:
|
123 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
124 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
125 |
-
retailers = licenses.loc[licenses['license_type'].str.contains('Retailer')]
|
126 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
127 |
-
licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
128 |
-
return licenses
|
129 |
-
|
130 |
-
|
131 |
-
# === Test ===
|
132 |
-
if __name__ == '__main__':
|
133 |
-
|
134 |
-
# Support command line usage.
|
135 |
-
import argparse
|
136 |
-
try:
|
137 |
-
arg_parser = argparse.ArgumentParser()
|
138 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
139 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
140 |
-
args = arg_parser.parse_args()
|
141 |
-
except SystemExit:
|
142 |
-
args = {'d': DATA_DIR}
|
143 |
-
|
144 |
-
# Get licenses, saving them to the specified directory.
|
145 |
-
data_dir = args.get('d', args.get('data_dir'))
|
146 |
-
data = get_licenses_ma(data_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_me.py
DELETED
@@ -1,187 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Maine Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/7/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Maine cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Maine Office of Cannabis Policy
|
19 |
-
URL: <https://www.maine.gov/dafs/ocp/open-data/adult-use>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from typing import Optional
|
26 |
-
|
27 |
-
# External imports.
|
28 |
-
from bs4 import BeautifulSoup
|
29 |
-
from cannlytics.data.gis import geocode_addresses
|
30 |
-
from dotenv import dotenv_values
|
31 |
-
import pandas as pd
|
32 |
-
import requests
|
33 |
-
|
34 |
-
|
35 |
-
# Specify where your data lives.
|
36 |
-
DATA_DIR = '../data/me'
|
37 |
-
ENV_FILE = '../.env'
|
38 |
-
|
39 |
-
# Specify state-specific constants.
|
40 |
-
STATE = 'ME'
|
41 |
-
MAINE = {
|
42 |
-
'licensing_authority_id': 'MEOCP',
|
43 |
-
'licensing_authority': 'Maine Office of Cannabis Policy',
|
44 |
-
'licenses': {
|
45 |
-
'url': 'https://www.maine.gov/dafs/ocp/open-data/adult-use',
|
46 |
-
'key': 'Adult_Use_Establishments_And_Contacts',
|
47 |
-
'columns': {
|
48 |
-
'LICENSE': 'license_number',
|
49 |
-
'LICENSE_CATEGORY': 'license_type',
|
50 |
-
'LICENSE_TYPE': 'license_designation',
|
51 |
-
'LICENSE_NAME': 'business_legal_name',
|
52 |
-
'DBA': 'business_dba_name',
|
53 |
-
'LICENSE_STATUS': 'license_status',
|
54 |
-
'LICENSE_CITY': 'premise_city',
|
55 |
-
'WEBSITE': 'business_website',
|
56 |
-
'CONTACT_NAME': 'business_owner_name',
|
57 |
-
'CONTACT_TYPE': 'contact_type',
|
58 |
-
'CONTACT_CITY': 'contact_city',
|
59 |
-
'CONTACT_DESCRIPTION': 'contact_description',
|
60 |
-
},
|
61 |
-
}
|
62 |
-
}
|
63 |
-
|
64 |
-
|
65 |
-
def get_licenses_me(
|
66 |
-
data_dir: Optional[str] = None,
|
67 |
-
env_file: Optional[str] = '.env',
|
68 |
-
):
|
69 |
-
"""Get Maine cannabis license data."""
|
70 |
-
|
71 |
-
# Create the necessary directories.
|
72 |
-
file_dir = f'{data_dir}/.datasets'
|
73 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
74 |
-
if not os.path.exists(file_dir): os.makedirs(file_dir)
|
75 |
-
|
76 |
-
# Get the download link.
|
77 |
-
licenses_url = None
|
78 |
-
licenses_key = MAINE['licenses']['key']
|
79 |
-
url = MAINE['licenses']['url']
|
80 |
-
response = requests.get(url)
|
81 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
82 |
-
links = soup.find_all('a')
|
83 |
-
for link in links:
|
84 |
-
try:
|
85 |
-
href = link['href']
|
86 |
-
except KeyError:
|
87 |
-
continue
|
88 |
-
if licenses_key in href:
|
89 |
-
licenses_url = href
|
90 |
-
break
|
91 |
-
|
92 |
-
# Download the licenses workbook.
|
93 |
-
filename = licenses_url.split('/')[-1].split('?')[0]
|
94 |
-
licenses_source_file = os.path.join(file_dir, filename)
|
95 |
-
response = requests.get(licenses_url)
|
96 |
-
with open(licenses_source_file, 'wb') as doc:
|
97 |
-
doc.write(response.content)
|
98 |
-
|
99 |
-
# Extract the data from the license workbook.
|
100 |
-
licenses = pd.read_excel(licenses_source_file)
|
101 |
-
licenses.rename(columns=MAINE['licenses']['columns'], inplace=True)
|
102 |
-
licenses = licenses.assign(
|
103 |
-
licensing_authority_id=MAINE['licensing_authority_id'],
|
104 |
-
licensing_authority=MAINE['licensing_authority'],
|
105 |
-
license_designation='Adult-Use',
|
106 |
-
premise_state=STATE,
|
107 |
-
license_status_date=None,
|
108 |
-
license_term=None,
|
109 |
-
issue_date=None,
|
110 |
-
expiration_date=None,
|
111 |
-
business_structure=None,
|
112 |
-
business_email=None,
|
113 |
-
business_phone=None,
|
114 |
-
activity=None,
|
115 |
-
parcel_number=None,
|
116 |
-
premise_street_address=None,
|
117 |
-
id=licenses['license_number'],
|
118 |
-
business_image_url=None,
|
119 |
-
)
|
120 |
-
|
121 |
-
# Remove duplicates.
|
122 |
-
licenses.drop_duplicates(subset='license_number', inplace=True)
|
123 |
-
|
124 |
-
# Replace null DBA with legal name.
|
125 |
-
criterion = licenses['business_dba_name'].isnull()
|
126 |
-
licenses.loc[criterion,'business_dba_name'] = licenses['business_legal_name']
|
127 |
-
|
128 |
-
# Convert certain columns from upper case title case.
|
129 |
-
cols = ['business_legal_name', 'business_dba_name', 'business_owner_name']
|
130 |
-
for col in cols:
|
131 |
-
licenses[col] = licenses[col].apply(
|
132 |
-
lambda x: x.title().strip() if isinstance(x, str) else x
|
133 |
-
)
|
134 |
-
|
135 |
-
# Get the refreshed date.
|
136 |
-
date = licenses_source_file.split('\\')[-1].split('.')[0].replace(licenses_key, '')
|
137 |
-
date = date.replace('%20', '')
|
138 |
-
date = '-'.join([date[:2], date[2:4], date[4:]])
|
139 |
-
licenses['data_refreshed_date'] = pd.to_datetime(date).isoformat()
|
140 |
-
|
141 |
-
# Geocode licenses to get `premise_latitude` and `premise_longitude`.
|
142 |
-
config = dotenv_values(env_file)
|
143 |
-
api_key = config['GOOGLE_MAPS_API_KEY']
|
144 |
-
cols = ['premise_city', 'premise_state']
|
145 |
-
licenses['address'] = licenses[cols].apply(
|
146 |
-
lambda row: ', '.join(row.values.astype(str)),
|
147 |
-
axis=1,
|
148 |
-
)
|
149 |
-
licenses = geocode_addresses(licenses, address_field='address', api_key=api_key)
|
150 |
-
drop_cols = ['state', 'state_name', 'address', 'formatted_address',
|
151 |
-
'contact_type', 'contact_city', 'contact_description']
|
152 |
-
gis_cols = {
|
153 |
-
'county': 'premise_county',
|
154 |
-
'latitude': 'premise_latitude',
|
155 |
-
'longitude': 'premise_longitude',
|
156 |
-
}
|
157 |
-
licenses['premise_zip_code'] = licenses['formatted_address'].apply(
|
158 |
-
lambda x: x.split(', ')[2].split(',')[0].split(' ')[-1] if STATE in str(x) else x
|
159 |
-
)
|
160 |
-
licenses.drop(columns=drop_cols, inplace=True)
|
161 |
-
licenses.rename(columns=gis_cols, inplace=True)
|
162 |
-
|
163 |
-
# Save and return the data.
|
164 |
-
if data_dir is not None:
|
165 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
166 |
-
licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
167 |
-
return licenses
|
168 |
-
|
169 |
-
|
170 |
-
# === Test ===
|
171 |
-
if __name__ == '__main__':
|
172 |
-
|
173 |
-
# Support command line usage.
|
174 |
-
import argparse
|
175 |
-
try:
|
176 |
-
arg_parser = argparse.ArgumentParser()
|
177 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
178 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
179 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
180 |
-
args = arg_parser.parse_args()
|
181 |
-
except SystemExit:
|
182 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
183 |
-
|
184 |
-
# Get licenses, saving them to the specified directory.
|
185 |
-
data_dir = args.get('d', args.get('data_dir'))
|
186 |
-
env_file = args.get('env_file')
|
187 |
-
data = get_licenses_me(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_mi.py
DELETED
@@ -1,259 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Michigan Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/8/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Michigan cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Michigan Cannabis Regulatory Agency
|
19 |
-
URL: <https://michigan.maps.arcgis.com/apps/webappviewer/index.html?id=cd5a1a76daaf470b823a382691c0ff60>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from time import sleep
|
26 |
-
from typing import Optional
|
27 |
-
|
28 |
-
# External imports.
|
29 |
-
from cannlytics.data.gis import geocode_addresses
|
30 |
-
from dotenv import dotenv_values
|
31 |
-
import pandas as pd
|
32 |
-
|
33 |
-
# Selenium imports.
|
34 |
-
from selenium import webdriver
|
35 |
-
from selenium.webdriver.chrome.options import Options
|
36 |
-
from selenium.webdriver.common.by import By
|
37 |
-
from selenium.webdriver.chrome.service import Service
|
38 |
-
from selenium.webdriver.support import expected_conditions as EC
|
39 |
-
from selenium.webdriver.support.ui import WebDriverWait
|
40 |
-
from selenium.webdriver.support.ui import Select
|
41 |
-
try:
|
42 |
-
import chromedriver_binary # Adds chromedriver binary to path.
|
43 |
-
except ImportError:
|
44 |
-
pass # Otherwise, ChromeDriver should be in your path.
|
45 |
-
|
46 |
-
|
47 |
-
# Specify where your data lives.
|
48 |
-
DATA_DIR = '../data/mi'
|
49 |
-
ENV_FILE = '../.env'
|
50 |
-
|
51 |
-
# Specify state-specific constants.
|
52 |
-
STATE = 'MI'
|
53 |
-
MICHIGAN = {
|
54 |
-
'licensing_authority_id': 'CRA',
|
55 |
-
'licensing_authority': 'Michigan Cannabis Regulatory Agency',
|
56 |
-
'licenses_url': 'https://aca-prod.accela.com/MIMM/Cap/CapHome.aspx?module=Adult_Use&TabName=Adult_Use',
|
57 |
-
'medicinal_url': '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',
|
58 |
-
'licenses': {
|
59 |
-
'columns': {
|
60 |
-
'Record Number': 'license_number',
|
61 |
-
'Record Type': 'license_type',
|
62 |
-
'License Name': 'business_legal_name',
|
63 |
-
'Address': 'address',
|
64 |
-
'Expiration Date': 'expiration_date',
|
65 |
-
'Status': 'license_status',
|
66 |
-
'Action': 'activity',
|
67 |
-
'Notes': 'license_designation',
|
68 |
-
'Disciplinary Action': 'license_term',
|
69 |
-
},
|
70 |
-
},
|
71 |
-
}
|
72 |
-
|
73 |
-
|
74 |
-
def wait_for_id_invisible(driver, value, seconds=30):
|
75 |
-
"""Wait for a given value to be invisible."""
|
76 |
-
WebDriverWait(driver, seconds).until(
|
77 |
-
EC.invisibility_of_element((By.ID, value))
|
78 |
-
)
|
79 |
-
|
80 |
-
|
81 |
-
def get_licenses_mi(
|
82 |
-
data_dir: Optional[str] = None,
|
83 |
-
env_file: Optional[str] = '.env',
|
84 |
-
):
|
85 |
-
"""Get Michigan cannabis license data."""
|
86 |
-
|
87 |
-
# Initialize Selenium and specify options.
|
88 |
-
service = Service()
|
89 |
-
options = Options()
|
90 |
-
options.add_argument('--window-size=1920,1200')
|
91 |
-
|
92 |
-
# DEV: Run with the browser open.
|
93 |
-
options.headless = False
|
94 |
-
|
95 |
-
# PRODUCTION: Run with the browser closed.
|
96 |
-
# options.add_argument('--headless')
|
97 |
-
# options.add_argument('--disable-gpu')
|
98 |
-
# options.add_argument('--no-sandbox')
|
99 |
-
|
100 |
-
# Initiate a Selenium driver.
|
101 |
-
driver = webdriver.Chrome(options=options, service=service)
|
102 |
-
|
103 |
-
# Load the license page.
|
104 |
-
url = MICHIGAN['licenses_url']
|
105 |
-
driver.get(url)
|
106 |
-
|
107 |
-
# Get the various license types, excluding certain types without addresses.
|
108 |
-
select = Select(driver.find_element(by=By.TAG_NAME, value='select'))
|
109 |
-
license_types = []
|
110 |
-
options = driver.find_elements(by=By.TAG_NAME, value='option')
|
111 |
-
for option in options:
|
112 |
-
text = option.text
|
113 |
-
if text and '--' not in text:
|
114 |
-
license_types.append(text)
|
115 |
-
|
116 |
-
# Restrict certain license types.
|
117 |
-
license_types = license_types[1:-2]
|
118 |
-
|
119 |
-
# FIXME: Iterate over license types.
|
120 |
-
data = []
|
121 |
-
columns = list(MICHIGAN['licenses']['columns'].values())
|
122 |
-
for license_type in license_types:
|
123 |
-
|
124 |
-
# Select the various license types.
|
125 |
-
try:
|
126 |
-
select.select_by_visible_text(license_type)
|
127 |
-
except:
|
128 |
-
pass
|
129 |
-
wait_for_id_invisible(driver, 'divGlobalLoading')
|
130 |
-
|
131 |
-
# Click the search button.
|
132 |
-
search_button = driver.find_element(by=By.ID, value='ctl00_PlaceHolderMain_btnNewSearch')
|
133 |
-
search_button.click()
|
134 |
-
wait_for_id_invisible(driver, 'divGlobalLoading')
|
135 |
-
|
136 |
-
# Iterate over all of the pages.
|
137 |
-
iterate = True
|
138 |
-
while iterate:
|
139 |
-
|
140 |
-
# Get all of the license data.
|
141 |
-
grid = driver.find_element(by=By.ID, value='ctl00_PlaceHolderMain_dvSearchList')
|
142 |
-
rows = grid.find_elements(by=By.TAG_NAME, value='tr')
|
143 |
-
rows = [x.text for x in rows]
|
144 |
-
rows = [x for x in rows if 'Download results' not in x and not x.startswith('< Prev')]
|
145 |
-
cells = []
|
146 |
-
for row in rows[1:]: # Skip the header.
|
147 |
-
obs = {}
|
148 |
-
cells = row.split('\n')
|
149 |
-
for i, cell in enumerate(cells):
|
150 |
-
column = columns[i]
|
151 |
-
obs[column] = cell
|
152 |
-
data.append(obs)
|
153 |
-
|
154 |
-
# Keep clicking the next button until the next button is disabled.
|
155 |
-
next_button = driver.find_elements(by=By.CLASS_NAME, value='aca_pagination_PrevNext')[-1]
|
156 |
-
current_page = driver.find_element(by=By.CLASS_NAME, value='SelectedPageButton').text
|
157 |
-
next_button.click()
|
158 |
-
wait_for_id_invisible(driver, 'divGlobalLoading')
|
159 |
-
next_page = driver.find_element(by=By.CLASS_NAME, value='SelectedPageButton').text
|
160 |
-
if current_page == next_page:
|
161 |
-
iterate = False
|
162 |
-
|
163 |
-
# TODO: Also get all of the medical licenses!
|
164 |
-
# 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
|
165 |
-
|
166 |
-
# End the browser session.
|
167 |
-
service.stop()
|
168 |
-
|
169 |
-
# Standardize the data.
|
170 |
-
licenses = pd.DataFrame(data)
|
171 |
-
licenses = licenses.assign(
|
172 |
-
id=licenses.index,
|
173 |
-
licensing_authority_id=MICHIGAN['licensing_authority_id'],
|
174 |
-
licensing_authority=MICHIGAN['licensing_authority'],
|
175 |
-
premise_state=STATE,
|
176 |
-
license_status_date=None,
|
177 |
-
issue_date=None,
|
178 |
-
business_owner_name=None,
|
179 |
-
business_structure=None,
|
180 |
-
parcel_number=None,
|
181 |
-
business_phone=None,
|
182 |
-
business_email=None,
|
183 |
-
business_image_url=None,
|
184 |
-
license_designation=None,
|
185 |
-
business_website=None,
|
186 |
-
business_dba_name=licenses['business_legal_name'],
|
187 |
-
)
|
188 |
-
|
189 |
-
# Assign `license_term` if necessary.
|
190 |
-
try:
|
191 |
-
licenses['license_term']
|
192 |
-
except KeyError:
|
193 |
-
licenses['license_term'] = None
|
194 |
-
|
195 |
-
# Clean `license_type`.
|
196 |
-
licenses['license_type'] = licenses['license_type'].apply(
|
197 |
-
lambda x: x.replace(' - License', '')
|
198 |
-
)
|
199 |
-
|
200 |
-
# Format expiration date as an ISO formatted date.
|
201 |
-
licenses['expiration_date'] = licenses['expiration_date'].apply(
|
202 |
-
lambda x: pd.to_datetime(x).isoformat()
|
203 |
-
)
|
204 |
-
|
205 |
-
# Geocode the licenses.
|
206 |
-
config = dotenv_values(env_file)
|
207 |
-
google_maps_api_key = config['GOOGLE_MAPS_API_KEY']
|
208 |
-
licenses = geocode_addresses(
|
209 |
-
licenses,
|
210 |
-
api_key=google_maps_api_key,
|
211 |
-
address_field='address',
|
212 |
-
)
|
213 |
-
licenses['premise_street_address'] = licenses['formatted_address'].apply(
|
214 |
-
lambda x: x.split(',')[0] if STATE in str(x) else x
|
215 |
-
)
|
216 |
-
licenses['premise_city'] = licenses['formatted_address'].apply(
|
217 |
-
lambda x: x.split(', ')[1].split(',')[0] if STATE in str(x) else x
|
218 |
-
)
|
219 |
-
licenses['premise_zip_code'] = licenses['formatted_address'].apply(
|
220 |
-
lambda x: x.split(', ')[2].split(',')[0].split(' ')[-1] if STATE in str(x) else x
|
221 |
-
)
|
222 |
-
drop_cols = ['state', 'state_name', 'address', 'formatted_address']
|
223 |
-
gis_cols = {
|
224 |
-
'county': 'premise_county',
|
225 |
-
'latitude': 'premise_latitude',
|
226 |
-
'longitude': 'premise_longitude'
|
227 |
-
}
|
228 |
-
licenses.drop(columns=drop_cols, inplace=True)
|
229 |
-
licenses.rename(columns=gis_cols, inplace=True)
|
230 |
-
|
231 |
-
# Get the refreshed date.
|
232 |
-
licenses['data_refreshed_date'] = datetime.now().isoformat()
|
233 |
-
|
234 |
-
# Save and return the data.
|
235 |
-
if data_dir is not None:
|
236 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
237 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
238 |
-
licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
239 |
-
return licenses
|
240 |
-
|
241 |
-
|
242 |
-
# === Test ===
|
243 |
-
if __name__ == '__main__':
|
244 |
-
|
245 |
-
# Support command line usage.
|
246 |
-
import argparse
|
247 |
-
try:
|
248 |
-
arg_parser = argparse.ArgumentParser()
|
249 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
250 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
251 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
252 |
-
args = arg_parser.parse_args()
|
253 |
-
except SystemExit:
|
254 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
255 |
-
|
256 |
-
# Get licenses, saving them to the specified directory.
|
257 |
-
data_dir = args.get('d', args.get('data_dir'))
|
258 |
-
env_file = args.get('env_file')
|
259 |
-
data = get_licenses_mi(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_mt.py
DELETED
@@ -1,278 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Montana Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/27/2022
|
9 |
-
Updated: 10/5/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Montana cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Montana Department of Revenue | Cannabis Control Division
|
19 |
-
URL: <https://mtrevenue.gov/cannabis/#CannabisLicenses>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from typing import Optional
|
26 |
-
|
27 |
-
# External imports.
|
28 |
-
from cannlytics.data.gis import search_for_address
|
29 |
-
from cannlytics.utils.constants import DEFAULT_HEADERS
|
30 |
-
from dotenv import dotenv_values
|
31 |
-
import pandas as pd
|
32 |
-
import pdfplumber
|
33 |
-
import requests
|
34 |
-
|
35 |
-
|
36 |
-
# Specify where your data lives.
|
37 |
-
DATA_DIR = '../data/mt'
|
38 |
-
ENV_FILE = '../.env'
|
39 |
-
|
40 |
-
# Specify state-specific constants.
|
41 |
-
STATE = 'MT'
|
42 |
-
MONTANA = {
|
43 |
-
'licensing_authority_id': 'MTCCD',
|
44 |
-
'licensing_authority': 'Montana Cannabis Control Division',
|
45 |
-
'licenses': {
|
46 |
-
'columns': [
|
47 |
-
{
|
48 |
-
'key': 'premise_city',
|
49 |
-
'name': 'City',
|
50 |
-
'area': [0, 0.25, 0.2, 0.95],
|
51 |
-
},
|
52 |
-
{
|
53 |
-
'key': 'business_legal_name',
|
54 |
-
'name': 'Location Name',
|
55 |
-
'area': [0.2, 0.25, 0.6, 0.95],
|
56 |
-
},
|
57 |
-
{
|
58 |
-
'key': 'license_designation',
|
59 |
-
'name': 'Sales Type',
|
60 |
-
'area': [0.6, 0.25, 0.75, 0.95],
|
61 |
-
},
|
62 |
-
{
|
63 |
-
'key': 'business_phone',
|
64 |
-
'name': 'Phone Number',
|
65 |
-
'area': [0.75, 0.25, 1, 0.95],
|
66 |
-
},
|
67 |
-
]
|
68 |
-
},
|
69 |
-
'retailers': {
|
70 |
-
'url': 'https://mtrevenue.gov/?mdocs-file=60245',
|
71 |
-
'columns': ['city', 'dba', 'license_type', 'phone']
|
72 |
-
},
|
73 |
-
'processors': {'url': 'https://mtrevenue.gov/?mdocs-file=60250'},
|
74 |
-
'cultivators': {'url': 'https://mtrevenue.gov/?mdocs-file=60252'},
|
75 |
-
'labs': {'url': 'https://mtrevenue.gov/?mdocs-file=60248'},
|
76 |
-
'transporters': {'url': 'https://mtrevenue.gov/?mdocs-file=72489'},
|
77 |
-
}
|
78 |
-
|
79 |
-
|
80 |
-
def get_licenses_mt(
|
81 |
-
data_dir: Optional[str] = None,
|
82 |
-
env_file: Optional[str] = '.env',
|
83 |
-
):
|
84 |
-
"""Get Montana cannabis license data."""
|
85 |
-
|
86 |
-
# Create directories if necessary.
|
87 |
-
pdf_dir = f'{data_dir}/pdfs'
|
88 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
89 |
-
if not os.path.exists(pdf_dir): os.makedirs(pdf_dir)
|
90 |
-
|
91 |
-
# Download the retailers PDF.
|
92 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
93 |
-
outfile = f'{pdf_dir}/mt-retailers-{timestamp}.pdf'
|
94 |
-
response = requests.get(MONTANA['retailers']['url'], headers=DEFAULT_HEADERS)
|
95 |
-
with open(outfile, 'wb') as pdf:
|
96 |
-
pdf.write(response.content)
|
97 |
-
|
98 |
-
# Read the PDF.
|
99 |
-
doc = pdfplumber.open(outfile)
|
100 |
-
|
101 |
-
# Get the table rows.
|
102 |
-
rows = []
|
103 |
-
front_page = doc.pages[0]
|
104 |
-
width, height = front_page.width, front_page.height
|
105 |
-
x0, y0, x1, y1 = tuple([0, 0.25, 1, 0.95])
|
106 |
-
page_area = (x0 * width, y0 * height, x1 * width, y1 * height)
|
107 |
-
for page in doc.pages:
|
108 |
-
crop = page.within_bbox(page_area)
|
109 |
-
text = crop.extract_text()
|
110 |
-
lines = text.split('\n')
|
111 |
-
for line in lines:
|
112 |
-
rows.append(line)
|
113 |
-
|
114 |
-
# Get cities from the first column, used to identify the city for each line.
|
115 |
-
cities = []
|
116 |
-
city_area = MONTANA['licenses']['columns'][0]['area']
|
117 |
-
x0, y0, x1, y1 = tuple(city_area)
|
118 |
-
column_area = (x0 * width, y0 * height, x1 * width, y1 * height)
|
119 |
-
for page in doc.pages:
|
120 |
-
crop = page.within_bbox(column_area)
|
121 |
-
text = crop.extract_text()
|
122 |
-
lines = text.split('\n')
|
123 |
-
for line in lines:
|
124 |
-
cities.append(line)
|
125 |
-
|
126 |
-
# Find all of the unique cities.
|
127 |
-
cities = list(set(cities))
|
128 |
-
cities = [x for x in cities if x != 'City']
|
129 |
-
|
130 |
-
# Get all of the license data.
|
131 |
-
data = []
|
132 |
-
rows = [x for x in rows if not x.startswith('City')]
|
133 |
-
for row in rows:
|
134 |
-
|
135 |
-
# Get all of the license observation data.
|
136 |
-
obs = {}
|
137 |
-
text = str(row)
|
138 |
-
|
139 |
-
# Identify the city and remove the city from the name (only once b/c of DBAs!).
|
140 |
-
for city in cities:
|
141 |
-
if city in row:
|
142 |
-
obs['premise_city'] = city.title()
|
143 |
-
text = text.replace(city, '', 1).strip()
|
144 |
-
break
|
145 |
-
|
146 |
-
# Identify the license designation.
|
147 |
-
if 'Adult Use' in row:
|
148 |
-
parts = text.split('Adult Use')
|
149 |
-
obs['license_designation'] = 'Adult Use'
|
150 |
-
else:
|
151 |
-
parts = text.split('Medical Only')
|
152 |
-
obs['license_designation'] = 'Medical Only'
|
153 |
-
|
154 |
-
# Skip rows with double-row text.
|
155 |
-
if len(row) == 1: continue
|
156 |
-
|
157 |
-
# Record the name.
|
158 |
-
obs['business_legal_name'] = name = parts[0]
|
159 |
-
|
160 |
-
# Record the phone number.
|
161 |
-
if '(' in text:
|
162 |
-
obs['business_phone'] = parts[-1].strip()
|
163 |
-
|
164 |
-
# Record the observation.
|
165 |
-
data.append(obs)
|
166 |
-
|
167 |
-
# Aggregate the data.
|
168 |
-
retailers = pd.DataFrame(data)
|
169 |
-
retailers = retailers.loc[~retailers['premise_city'].isna()]
|
170 |
-
|
171 |
-
# Convert certain columns from upper case title case.
|
172 |
-
cols = ['business_legal_name', 'premise_city']
|
173 |
-
for col in cols:
|
174 |
-
retailers[col] = retailers[col].apply(
|
175 |
-
lambda x: x.title().replace('Llc', 'LLC').replace("'S", "'s").strip()
|
176 |
-
)
|
177 |
-
|
178 |
-
# Standardize the data.
|
179 |
-
retailers['id'] = retailers.index
|
180 |
-
retailers['license_number'] = None # FIXME: It would be awesome to find these!
|
181 |
-
retailers['licensing_authority_id'] = MONTANA['licensing_authority_id']
|
182 |
-
retailers['licensing_authority'] = MONTANA['licensing_authority']
|
183 |
-
retailers['premise_state'] = STATE
|
184 |
-
retailers['license_status'] = 'Active'
|
185 |
-
retailers['license_status_date'] = None
|
186 |
-
retailers['license_type'] = 'Commercial - Retailer'
|
187 |
-
retailers['license_term'] = None
|
188 |
-
retailers['issue_date'] = None
|
189 |
-
retailers['expiration_date'] = None
|
190 |
-
retailers['business_owner_name'] = None
|
191 |
-
retailers['business_structure'] = None
|
192 |
-
retailers['activity'] = None
|
193 |
-
retailers['parcel_number'] = None
|
194 |
-
retailers['business_email'] = None
|
195 |
-
retailers['business_image_url'] = None
|
196 |
-
|
197 |
-
# Separate any `business_dba_name` from `business_legal_name`.
|
198 |
-
retailers['business_dba_name'] = retailers['business_legal_name']
|
199 |
-
criterion = retailers['business_legal_name'].str.contains('Dba')
|
200 |
-
retailers.loc[criterion, 'business_dba_name'] = retailers.loc[criterion] \
|
201 |
-
['business_legal_name'].apply(lambda x: x.split('Dba')[-1].strip())
|
202 |
-
retailers.loc[criterion, 'business_legal_name'] = retailers.loc[criterion] \
|
203 |
-
['business_legal_name'].apply(lambda x: x.split('Dba')[0].strip())
|
204 |
-
|
205 |
-
# Search for address for each retail license.
|
206 |
-
# Only search for a query once, then re-use the response.
|
207 |
-
# Note: There is probably a much, much more efficient way to do this!!!
|
208 |
-
config = dotenv_values(env_file)
|
209 |
-
api_key = config['GOOGLE_MAPS_API_KEY']
|
210 |
-
cols = ['business_dba_name', 'premise_city', 'premise_state']
|
211 |
-
retailers['query'] = retailers[cols].apply(
|
212 |
-
lambda row: ', '.join(row.values.astype(str)),
|
213 |
-
axis=1,
|
214 |
-
)
|
215 |
-
queries = {}
|
216 |
-
fields = [
|
217 |
-
'formatted_address',
|
218 |
-
'geometry/location/lat',
|
219 |
-
'geometry/location/lng',
|
220 |
-
'website',
|
221 |
-
]
|
222 |
-
retailers = retailers.reset_index(drop=True)
|
223 |
-
retailers = retailers.assign(
|
224 |
-
premise_street_address=None,
|
225 |
-
premise_county=None,
|
226 |
-
premise_zip_code=None,
|
227 |
-
premise_latitude=None,
|
228 |
-
premise_longitude=None,
|
229 |
-
business_website=None,
|
230 |
-
)
|
231 |
-
for index, row in retailers.iterrows():
|
232 |
-
query = row['query']
|
233 |
-
gis_data = queries.get(query)
|
234 |
-
if gis_data is None:
|
235 |
-
try:
|
236 |
-
gis_data = search_for_address(query, api_key=api_key, fields=fields)
|
237 |
-
except:
|
238 |
-
gis_data = {}
|
239 |
-
queries[query] = gis_data
|
240 |
-
retailers.iat[index, retailers.columns.get_loc('premise_street_address')] = gis_data.get('street')
|
241 |
-
retailers.iat[index, retailers.columns.get_loc('premise_county')] = gis_data.get('county')
|
242 |
-
retailers.iat[index, retailers.columns.get_loc('premise_zip_code')] = gis_data.get('zipcode')
|
243 |
-
retailers.iat[index, retailers.columns.get_loc('premise_latitude')] = gis_data.get('latitude')
|
244 |
-
retailers.iat[index, retailers.columns.get_loc('premise_longitude')] = gis_data.get('longitude')
|
245 |
-
retailers.iat[index, retailers.columns.get_loc('business_website')] = gis_data.get('website')
|
246 |
-
|
247 |
-
# Clean-up after getting GIS data.
|
248 |
-
retailers.drop(columns=['query'], inplace=True)
|
249 |
-
|
250 |
-
# Get the refreshed date.
|
251 |
-
retailers['data_refreshed_date'] = datetime.now().isoformat()
|
252 |
-
|
253 |
-
# Save and return the data.
|
254 |
-
if data_dir is not None:
|
255 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
256 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
257 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
258 |
-
return retailers
|
259 |
-
|
260 |
-
|
261 |
-
# === Test ===
|
262 |
-
if __name__ == '__main__':
|
263 |
-
|
264 |
-
# Support command line usage.
|
265 |
-
import argparse
|
266 |
-
try:
|
267 |
-
arg_parser = argparse.ArgumentParser()
|
268 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
269 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
270 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
271 |
-
args = arg_parser.parse_args()
|
272 |
-
except SystemExit:
|
273 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
274 |
-
|
275 |
-
# Get licenses, saving them to the specified directory.
|
276 |
-
data_dir = args.get('d', args.get('data_dir'))
|
277 |
-
env_file = args.get('env_file')
|
278 |
-
data = get_licenses_mt(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_nj.py
DELETED
@@ -1,128 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get New Jersey Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 9/29/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect New Jersey cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- New Jersey Cannabis Regulatory Commission
|
19 |
-
URL: <https://data.nj.gov/stories/s/ggm4-mprw>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from typing import Optional
|
26 |
-
|
27 |
-
# External imports.
|
28 |
-
import pandas as pd
|
29 |
-
import requests
|
30 |
-
|
31 |
-
|
32 |
-
# Specify where your data lives.
|
33 |
-
DATA_DIR = '../data/nj'
|
34 |
-
|
35 |
-
# Specify state-specific constants.
|
36 |
-
STATE = 'NJ'
|
37 |
-
NEW_JERSEY = {
|
38 |
-
'licensing_authority_id': 'NJCRC',
|
39 |
-
'licensing_authority': 'New Jersey Cannabis Regulatory Commission',
|
40 |
-
'retailers': {
|
41 |
-
'columns': {
|
42 |
-
'name': 'business_dba_name',
|
43 |
-
'address': 'premise_street_address',
|
44 |
-
'town': 'premise_city',
|
45 |
-
'state': 'premise_state',
|
46 |
-
'zip_code': 'premise_zip_code',
|
47 |
-
'county': 'premise_county',
|
48 |
-
'phone_number': 'business_phone',
|
49 |
-
'type': 'license_type',
|
50 |
-
}
|
51 |
-
}
|
52 |
-
}
|
53 |
-
|
54 |
-
|
55 |
-
def get_licenses_nj(
|
56 |
-
data_dir: Optional[str] = None,
|
57 |
-
**kwargs,
|
58 |
-
):
|
59 |
-
"""Get New Jersey cannabis license data."""
|
60 |
-
|
61 |
-
# Get retailer data.
|
62 |
-
url = 'https://data.nj.gov/resource/nv37-s2zn.json'
|
63 |
-
response = requests.get(url)
|
64 |
-
data = pd.DataFrame(response.json())
|
65 |
-
|
66 |
-
# Parse the website.
|
67 |
-
data['business_website'] = data['website'].apply(lambda x: x['url'])
|
68 |
-
|
69 |
-
# Parse the GIS coordinates.
|
70 |
-
data['premise_longitude'] = data['dispensary_location'].apply(
|
71 |
-
lambda x: x['coordinates'][0]
|
72 |
-
)
|
73 |
-
data['premise_latitude'] = data['dispensary_location'].apply(
|
74 |
-
lambda x: x['coordinates'][1]
|
75 |
-
)
|
76 |
-
|
77 |
-
# Standardize the data.
|
78 |
-
drop_cols = ['dispensary_location', 'location', 'website']
|
79 |
-
data.drop(columns=drop_cols, inplace=True)
|
80 |
-
data.rename(columns=NEW_JERSEY['retailers']['columns'], inplace=True)
|
81 |
-
data['business_legal_name'] = data['business_dba_name']
|
82 |
-
data['licensing_authority_id'] = NEW_JERSEY['licensing_authority_id']
|
83 |
-
data['licensing_authority'] = NEW_JERSEY['licensing_authority']
|
84 |
-
data['license_designation'] = 'Adult-Use'
|
85 |
-
data['premise_state'] = STATE
|
86 |
-
data['license_status_date'] = None
|
87 |
-
data['license_term'] = None
|
88 |
-
data['issue_date'] = None
|
89 |
-
data['expiration_date'] = None
|
90 |
-
data['business_owner_name'] = None
|
91 |
-
data['business_structure'] = None
|
92 |
-
data['business_email'] = None
|
93 |
-
data['activity'] = None
|
94 |
-
data['parcel_number'] = None
|
95 |
-
data['business_image_url'] = None
|
96 |
-
data['id'] = None
|
97 |
-
data['license_number'] = None
|
98 |
-
data['license_status'] = None
|
99 |
-
data['data_refreshed_date'] = datetime.now().isoformat()
|
100 |
-
|
101 |
-
# Convert certain columns from upper case title case.
|
102 |
-
cols = ['premise_city', 'premise_county', 'premise_street_address']
|
103 |
-
for col in cols:
|
104 |
-
data[col] = data[col].apply(lambda x: x.title().strip())
|
105 |
-
|
106 |
-
# Save and return the data.
|
107 |
-
if data_dir is not None:
|
108 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
109 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
110 |
-
data.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
111 |
-
return data
|
112 |
-
|
113 |
-
|
114 |
-
# === Test ===
|
115 |
-
if __name__ == '__main__':
|
116 |
-
|
117 |
-
# Support command line usage.
|
118 |
-
import argparse
|
119 |
-
try:
|
120 |
-
arg_parser = argparse.ArgumentParser()
|
121 |
-
arg_parser.add_argument('--d', '--data_dir', dest='data_dir', type=str)
|
122 |
-
args = arg_parser.parse_args()
|
123 |
-
except SystemExit:
|
124 |
-
args = {'d': DATA_DIR}
|
125 |
-
|
126 |
-
# Get licenses, saving them to the specified directory.
|
127 |
-
data_dir = args.get('d', args.get('data_dir'))
|
128 |
-
data = get_licenses_nj(data_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_nm.py
DELETED
@@ -1,309 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get New Mexico Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/6/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect New Mexico cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- New Mexico Regulation and Licensing Department | Cannabis Control Division
|
19 |
-
URL: <https://nmrldlpi.force.com/bcd/s/public-search-license?division=CCD&language=en_US>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from time import sleep
|
26 |
-
from typing import Optional
|
27 |
-
|
28 |
-
# External imports.
|
29 |
-
from cannlytics.data.gis import geocode_addresses, search_for_address
|
30 |
-
from dotenv import dotenv_values
|
31 |
-
import pandas as pd
|
32 |
-
|
33 |
-
# Selenium imports.
|
34 |
-
from selenium import webdriver
|
35 |
-
from selenium.webdriver.chrome.options import Options
|
36 |
-
from selenium.webdriver.common.by import By
|
37 |
-
from selenium.webdriver.chrome.service import Service
|
38 |
-
from selenium.webdriver.support import expected_conditions as EC
|
39 |
-
from selenium.webdriver.support.ui import WebDriverWait
|
40 |
-
try:
|
41 |
-
import chromedriver_binary # Adds chromedriver binary to path.
|
42 |
-
except ImportError:
|
43 |
-
pass # Otherwise, ChromeDriver should be in your path.
|
44 |
-
|
45 |
-
|
46 |
-
# Specify where your data lives.
|
47 |
-
DATA_DIR = '../data/nm'
|
48 |
-
ENV_FILE = '../.env'
|
49 |
-
|
50 |
-
# Specify state-specific constants.
|
51 |
-
STATE = 'NM'
|
52 |
-
NEW_MEXICO = {
|
53 |
-
'licensing_authority_id': 'NMCCD',
|
54 |
-
'licensing_authority': 'New Mexico Cannabis Control Division',
|
55 |
-
'licenses_url': 'https://nmrldlpi.force.com/bcd/s/public-search-license?division=CCD&language=en_US',
|
56 |
-
}
|
57 |
-
|
58 |
-
|
59 |
-
def get_licenses_nm(
|
60 |
-
data_dir: Optional[str] = None,
|
61 |
-
env_file: Optional[str] = '.env',
|
62 |
-
):
|
63 |
-
"""Get New Mexico cannabis license data."""
|
64 |
-
|
65 |
-
# Create directories if necessary.
|
66 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
67 |
-
|
68 |
-
# Initialize Selenium and specify options.
|
69 |
-
service = Service()
|
70 |
-
options = Options()
|
71 |
-
options.add_argument('--window-size=1920,1200')
|
72 |
-
|
73 |
-
# DEV: Run with the browser open.
|
74 |
-
options.headless = False
|
75 |
-
|
76 |
-
# PRODUCTION: Run with the browser closed.
|
77 |
-
# options.add_argument('--headless')
|
78 |
-
# options.add_argument('--disable-gpu')
|
79 |
-
# options.add_argument('--no-sandbox')
|
80 |
-
|
81 |
-
# Initiate a Selenium driver.
|
82 |
-
driver = webdriver.Chrome(options=options, service=service)
|
83 |
-
|
84 |
-
# Load the license page.
|
85 |
-
driver.get(NEW_MEXICO['licenses_url'])
|
86 |
-
|
87 |
-
# FIXME: Wait for the page to load by waiting to detect the image.
|
88 |
-
# try:
|
89 |
-
# el = (By.CLASS_NAME, 'slds-radio--faux')
|
90 |
-
# WebDriverWait(driver, 15).until(EC.presence_of_element_located(el))
|
91 |
-
# except TimeoutException:
|
92 |
-
# print('Failed to load page within %i seconds.' % (30))
|
93 |
-
sleep(5)
|
94 |
-
|
95 |
-
# Get the main content and click "License Type" raido.
|
96 |
-
content = driver.find_element(by=By.CLASS_NAME, value='siteforceContentArea')
|
97 |
-
radio = content.find_element(by=By.CLASS_NAME, value='slds-radio--faux')
|
98 |
-
radio.click()
|
99 |
-
sleep(2)
|
100 |
-
|
101 |
-
# Select retailers.
|
102 |
-
# TODO: Also get "Cannabis Manufacturer", "Cannabis Producer", and
|
103 |
-
# "Cannabis Producer Microbusiness".
|
104 |
-
search = content.find_element(by=By.ID, value='comboboxId-40')
|
105 |
-
search.click()
|
106 |
-
choices = content.find_elements(by=By.CLASS_NAME, value='slds-listbox__item')
|
107 |
-
for choice in choices:
|
108 |
-
if choice.text == 'Cannabis Retailer':
|
109 |
-
choice.click()
|
110 |
-
sleep(2)
|
111 |
-
break
|
112 |
-
|
113 |
-
# Click the search button.
|
114 |
-
search = content.find_element(by=By.CLASS_NAME, value='vlocity-btn')
|
115 |
-
search.click()
|
116 |
-
sleep(2)
|
117 |
-
|
118 |
-
# Iterate over all of the pages.
|
119 |
-
# Wait for the table to load, then iterate over the pages.
|
120 |
-
sleep(5)
|
121 |
-
data = []
|
122 |
-
iterate = True
|
123 |
-
while(iterate):
|
124 |
-
|
125 |
-
# Get all of the licenses.
|
126 |
-
items = content.find_elements(by=By.CLASS_NAME, value='block-container')
|
127 |
-
for item in items[3:]:
|
128 |
-
text = item.text
|
129 |
-
if not text:
|
130 |
-
continue
|
131 |
-
values = text.split('\n')
|
132 |
-
data.append({
|
133 |
-
'license_type': values[0],
|
134 |
-
'license_status': values[1],
|
135 |
-
'business_legal_name': values[2],
|
136 |
-
'address': values[-1],
|
137 |
-
'details_url': '',
|
138 |
-
})
|
139 |
-
|
140 |
-
# Get the page number and stop at the last page.
|
141 |
-
# FIXME: This doesn't correctly break!
|
142 |
-
par = content.find_elements(by=By.TAG_NAME, value='p')[-1].text
|
143 |
-
page_number = int(par.split(' ')[2])
|
144 |
-
total_pages = int(par.split(' ')[-2])
|
145 |
-
if page_number == total_pages:
|
146 |
-
iterate = False
|
147 |
-
|
148 |
-
# Otherwise, click the next button.
|
149 |
-
buttons = content.find_elements(by=By.TAG_NAME, value='button')
|
150 |
-
for button in buttons:
|
151 |
-
if button.text == 'Next Page':
|
152 |
-
button.click()
|
153 |
-
sleep(5)
|
154 |
-
break
|
155 |
-
|
156 |
-
# Search for each license name, 1 by 1, to get details.
|
157 |
-
retailers = pd.DataFrame(columns=['business_legal_name'])
|
158 |
-
for i, licensee in enumerate(data):
|
159 |
-
|
160 |
-
# Skip recorded rows.
|
161 |
-
if len(retailers.loc[retailers['business_legal_name'] == licensee['business_legal_name']]):
|
162 |
-
continue
|
163 |
-
|
164 |
-
# Click the "Business Name" search field.
|
165 |
-
content = driver.find_element(by=By.CLASS_NAME, value='siteforceContentArea')
|
166 |
-
radio = content.find_elements(by=By.CLASS_NAME, value='slds-radio--faux')[1]
|
167 |
-
radio.click()
|
168 |
-
sleep(1)
|
169 |
-
|
170 |
-
# Enter the `business_legal_name` into the search.
|
171 |
-
search_field = content.find_element(by=By.CLASS_NAME, value='vlocity-input')
|
172 |
-
search_field.clear()
|
173 |
-
search_field.send_keys(licensee['business_legal_name'])
|
174 |
-
|
175 |
-
# Click the search button.
|
176 |
-
search = content.find_element(by=By.CLASS_NAME, value='vlocity-btn')
|
177 |
-
search.click()
|
178 |
-
|
179 |
-
# FIXME: Wait for the table to load.
|
180 |
-
# WebDriverWait(content, 5).until(EC.presence_of_element_located((By.CLASS_NAME, 'slds-button_icon')))
|
181 |
-
sleep(1.5)
|
182 |
-
|
183 |
-
# Click the "Action" button to get to the details page.
|
184 |
-
# FIXME: There can be multiple search candidates!
|
185 |
-
action = content.find_element(by=By.CLASS_NAME, value='slds-button_icon')
|
186 |
-
try:
|
187 |
-
action.click()
|
188 |
-
except:
|
189 |
-
continue # FIXME: Formally check if "No record found!".
|
190 |
-
|
191 |
-
# FIXME: Wait for the details page to load.
|
192 |
-
el = (By.CLASS_NAME, 'body')
|
193 |
-
WebDriverWait(driver, 5).until(EC.presence_of_element_located(el))
|
194 |
-
|
195 |
-
# Get the page
|
196 |
-
page = driver.find_element(by=By.CLASS_NAME, value='body')
|
197 |
-
|
198 |
-
# FIXME: Wait for the details to load!
|
199 |
-
# el = (By.TAG_NAME, 'vlocity_ins-omniscript-step')
|
200 |
-
# WebDriverWait(page, 5).until(EC.presence_of_element_located(el))
|
201 |
-
sleep(1.5)
|
202 |
-
|
203 |
-
# Get all of the details!
|
204 |
-
fields = [
|
205 |
-
'license_number',
|
206 |
-
'license_status',
|
207 |
-
'issue_date',
|
208 |
-
'expiration_date',
|
209 |
-
'business_owner_name',
|
210 |
-
]
|
211 |
-
values = page.find_elements(by=By.CLASS_NAME, value='field-value')
|
212 |
-
if len(values) > 5:
|
213 |
-
for j, value in enumerate(values[:5]):
|
214 |
-
data[i][fields[j]] = value.text
|
215 |
-
for value in values[5:]:
|
216 |
-
data[i]['business_owner_name'] += f', {value.text}'
|
217 |
-
else:
|
218 |
-
for j, value in enumerate(values):
|
219 |
-
data[i][fields[j]] = value.text
|
220 |
-
|
221 |
-
# Create multiple entries for each address!!!
|
222 |
-
premises = page.find_elements(by=By.CLASS_NAME, value='block-header')
|
223 |
-
for premise in premises:
|
224 |
-
values = premise.text.split('\n')
|
225 |
-
licensee['address'] = values[0].replace(',', ', ')
|
226 |
-
licensee['license_number'] = values[2]
|
227 |
-
retailers = pd.concat([retailers, pd.DataFrame([licensee])])
|
228 |
-
|
229 |
-
# Click the "Back to Search" button.
|
230 |
-
back_button = page.find_element(by=By.CLASS_NAME, value='vlocity-btn')
|
231 |
-
back_button.click()
|
232 |
-
sleep(1)
|
233 |
-
|
234 |
-
# End the browser session.
|
235 |
-
service.stop()
|
236 |
-
|
237 |
-
# Standardize the data, restricting to "Approved" retailers.
|
238 |
-
retailers = retailers.loc[retailers['license_status'] == 'Active']
|
239 |
-
retailers = retailers.assign(
|
240 |
-
business_email=None,
|
241 |
-
business_structure=None,
|
242 |
-
licensing_authority_id=NEW_MEXICO['licensing_authority_id'],
|
243 |
-
licensing_authority=NEW_MEXICO['licensing_authority'],
|
244 |
-
license_designation='Adult-Use',
|
245 |
-
license_status_date=None,
|
246 |
-
license_term=None,
|
247 |
-
premise_state=STATE,
|
248 |
-
parcel_number=None,
|
249 |
-
activity=None,
|
250 |
-
business_image_url=None,
|
251 |
-
business_website=None,
|
252 |
-
business_phone=None,
|
253 |
-
id=retailers['license_number'],
|
254 |
-
business_dba_name=retailers['business_legal_name'],
|
255 |
-
)
|
256 |
-
|
257 |
-
# Get the refreshed date.
|
258 |
-
retailers['data_refreshed_date'] = datetime.now().isoformat()
|
259 |
-
|
260 |
-
# Geocode licenses.
|
261 |
-
# FIXME: This is not working as intended. Perhaps try `search_for_address`?
|
262 |
-
config = dotenv_values(env_file)
|
263 |
-
api_key = config['GOOGLE_MAPS_API_KEY']
|
264 |
-
retailers = geocode_addresses(retailers, api_key=api_key, address_field='address')
|
265 |
-
retailers['premise_street_address'] = retailers['formatted_address'].apply(
|
266 |
-
lambda x: x.split(',')[0] if STATE in str(x) else x
|
267 |
-
)
|
268 |
-
retailers['premise_city'] = retailers['formatted_address'].apply(
|
269 |
-
lambda x: x.split(', ')[1].split(',')[0] if STATE in str(x) else x
|
270 |
-
)
|
271 |
-
retailers['premise_zip_code'] = retailers['formatted_address'].apply(
|
272 |
-
lambda x: x.split(', ')[2].split(',')[0].split(' ')[-1] if STATE in str(x) else x
|
273 |
-
)
|
274 |
-
drop_cols = ['state', 'state_name', 'address', 'formatted_address',
|
275 |
-
'details_url']
|
276 |
-
gis_cols = {
|
277 |
-
'county': 'premise_county',
|
278 |
-
'latitude': 'premise_latitude',
|
279 |
-
'longitude': 'premise_longitude'
|
280 |
-
}
|
281 |
-
retailers.drop(columns=drop_cols, inplace=True)
|
282 |
-
retailers.rename(columns=gis_cols, inplace=True)
|
283 |
-
|
284 |
-
# Save and return the data.
|
285 |
-
if data_dir is not None:
|
286 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
287 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
288 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
289 |
-
return retailers
|
290 |
-
|
291 |
-
|
292 |
-
# === Test ===
|
293 |
-
if __name__ == '__main__':
|
294 |
-
|
295 |
-
# Support command line usage.
|
296 |
-
import argparse
|
297 |
-
try:
|
298 |
-
arg_parser = argparse.ArgumentParser()
|
299 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
300 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
301 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
302 |
-
args = arg_parser.parse_args()
|
303 |
-
except SystemExit:
|
304 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
305 |
-
|
306 |
-
# Get licenses, saving them to the specified directory.
|
307 |
-
data_dir = args.get('d', args.get('data_dir'))
|
308 |
-
env_file = args.get('env_file')
|
309 |
-
data = get_licenses_nm(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_nv.py
DELETED
@@ -1,235 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Nevada Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 9/29/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Nevada cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Nevada
|
19 |
-
URL: <https://ccb.nv.gov/list-of-licensees/>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from typing import Optional
|
26 |
-
|
27 |
-
# External imports.
|
28 |
-
from bs4 import BeautifulSoup
|
29 |
-
from cannlytics.data.gis import geocode_addresses
|
30 |
-
from cannlytics.utils.constants import DEFAULT_HEADERS
|
31 |
-
from dotenv import dotenv_values
|
32 |
-
import pandas as pd
|
33 |
-
import requests
|
34 |
-
|
35 |
-
# Specify where your data lives.
|
36 |
-
DATA_DIR = '../data/nv'
|
37 |
-
ENV_FILE = '../.env'
|
38 |
-
|
39 |
-
# Specify state-specific constants.
|
40 |
-
STATE = 'NV'
|
41 |
-
NEVADA = {
|
42 |
-
'licensing_authority_id': 'NVCCB',
|
43 |
-
'licensing_authority': 'Nevada Cannabis Compliance Board',
|
44 |
-
'licenses': {
|
45 |
-
'key': 'Active-License-List',
|
46 |
-
'columns': {
|
47 |
-
'LicenseNumber': 'license_number',
|
48 |
-
'LicenseName': 'business_dba_name',
|
49 |
-
'CE ID': 'id',
|
50 |
-
'LicenseType': 'license_type',
|
51 |
-
'County': 'premise_county',
|
52 |
-
},
|
53 |
-
'url': 'https://ccb.nv.gov/list-of-licensees/',
|
54 |
-
}
|
55 |
-
}
|
56 |
-
|
57 |
-
|
58 |
-
def get_licenses_nv(
|
59 |
-
data_dir: Optional[str] = None,
|
60 |
-
env_file: Optional[str] = '.env',
|
61 |
-
):
|
62 |
-
"""Get Nevada cannabis license data."""
|
63 |
-
|
64 |
-
# Create the necessary directories.
|
65 |
-
file_dir = f'{data_dir}/.datasets'
|
66 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
67 |
-
if not os.path.exists(file_dir): os.makedirs(file_dir)
|
68 |
-
|
69 |
-
#--------------------------------------------------------------------------
|
70 |
-
# Get all license data.
|
71 |
-
#--------------------------------------------------------------------------
|
72 |
-
|
73 |
-
# Find the latest licenses workbook.
|
74 |
-
licenses_url = ''
|
75 |
-
retailer_key = NEVADA['licenses']['key']
|
76 |
-
url = NEVADA['licenses']['url']
|
77 |
-
response = requests.get(url, headers=DEFAULT_HEADERS)
|
78 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
79 |
-
links = soup.find_all('a')
|
80 |
-
for link in links:
|
81 |
-
href = link['href']
|
82 |
-
if retailer_key in href:
|
83 |
-
licenses_url = href
|
84 |
-
break
|
85 |
-
|
86 |
-
# Download the workbook.
|
87 |
-
filename = licenses_url.split('/')[-1]
|
88 |
-
licenses_source_file = os.path.join(file_dir, filename)
|
89 |
-
response = requests.get(licenses_url, headers=DEFAULT_HEADERS)
|
90 |
-
with open(licenses_source_file, 'wb') as doc:
|
91 |
-
doc.write(response.content)
|
92 |
-
|
93 |
-
# Extract and standardize the data from the workbook.
|
94 |
-
licenses = pd.read_excel(licenses_source_file, skiprows=1)
|
95 |
-
licenses.rename(columns=NEVADA['licenses']['columns'], inplace=True)
|
96 |
-
licenses['id'] = licenses['license_number']
|
97 |
-
licenses['licensing_authority_id'] = NEVADA['licensing_authority_id']
|
98 |
-
licenses['licensing_authority'] = NEVADA['licensing_authority']
|
99 |
-
licenses['license_designation'] = 'Adult-Use'
|
100 |
-
licenses['premise_state'] = STATE
|
101 |
-
licenses['license_status_date'] = None
|
102 |
-
licenses['license_term'] = None
|
103 |
-
licenses['issue_date'] = None
|
104 |
-
licenses['expiration_date'] = None
|
105 |
-
licenses['business_legal_name'] = licenses['business_dba_name']
|
106 |
-
licenses['business_owner_name'] = None
|
107 |
-
licenses['business_structure'] = None
|
108 |
-
licenses['business_email'] = None
|
109 |
-
licenses['activity'] = None
|
110 |
-
licenses['parcel_number'] = None
|
111 |
-
licenses['business_image_url'] = None
|
112 |
-
licenses['business_phone'] = None
|
113 |
-
licenses['business_website'] = None
|
114 |
-
|
115 |
-
# Convert certain columns from upper case title case.
|
116 |
-
cols = ['business_dba_name', 'premise_county']
|
117 |
-
for col in cols:
|
118 |
-
licenses[col] = licenses[col].apply(lambda x: x.title().strip())
|
119 |
-
|
120 |
-
# Get the refreshed date.
|
121 |
-
date = filename.split('.')[0].replace(retailer_key, '').lstrip('-')
|
122 |
-
date = '-'.join([date[:2], date[2:4], date[4:]])
|
123 |
-
licenses['data_refreshed_date'] = pd.to_datetime(date)
|
124 |
-
|
125 |
-
# Wish: Geocode licenses to get `premise_latitude` and `premise_longitude`.
|
126 |
-
|
127 |
-
# Save the licenses
|
128 |
-
if data_dir is not None:
|
129 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
130 |
-
licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
131 |
-
|
132 |
-
#--------------------------------------------------------------------------
|
133 |
-
# Get retailer data
|
134 |
-
#--------------------------------------------------------------------------
|
135 |
-
|
136 |
-
# Get the retailer data.
|
137 |
-
retailers = []
|
138 |
-
tables = soup.find_all('table', attrs={'class': 'customTable'})
|
139 |
-
for table in tables:
|
140 |
-
try:
|
141 |
-
city = table.find('span').text
|
142 |
-
except AttributeError:
|
143 |
-
continue
|
144 |
-
rows = table.find_all('td')
|
145 |
-
for row in rows:
|
146 |
-
cells = row.text.split(' – ')
|
147 |
-
name = cells[0]
|
148 |
-
street = cells[1]
|
149 |
-
designation = cells[-1]
|
150 |
-
retailers.append({
|
151 |
-
'business_legal_name': name,
|
152 |
-
'business_dba_name': name,
|
153 |
-
'license_designation': designation,
|
154 |
-
'premise_city': city,
|
155 |
-
'premise_street_address': street,
|
156 |
-
})
|
157 |
-
|
158 |
-
# Standardize the retailers.
|
159 |
-
retailers = pd.DataFrame(retailers)
|
160 |
-
retailers['licensing_authority_id'] = NEVADA['licensing_authority_id']
|
161 |
-
retailers['licensing_authority'] = NEVADA['licensing_authority']
|
162 |
-
retailers['license_type'] = 'Commercial - Retailer'
|
163 |
-
retailers['license_status'] = 'Active'
|
164 |
-
retailers['license_designation'] = 'Adult-Use'
|
165 |
-
retailers['premise_state'] = STATE
|
166 |
-
retailers['license_status_date'] = None
|
167 |
-
retailers['license_term'] = None
|
168 |
-
retailers['issue_date'] = None
|
169 |
-
retailers['expiration_date'] = None
|
170 |
-
retailers['business_owner_name'] = None
|
171 |
-
retailers['business_structure'] = None
|
172 |
-
retailers['business_email'] = None
|
173 |
-
retailers['activity'] = None
|
174 |
-
retailers['parcel_number'] = None
|
175 |
-
retailers['business_website'] = None
|
176 |
-
retailers['business_image_url'] = None
|
177 |
-
retailers['business_phone'] = None
|
178 |
-
|
179 |
-
# FIXME: Merge `license_number`, `premise_county`, `data_refreshed_date`
|
180 |
-
# from licenses.
|
181 |
-
retailers['license_number'] = None
|
182 |
-
retailers['id'] = None
|
183 |
-
retailers['data_refreshed_date'] = datetime.now().isoformat()
|
184 |
-
|
185 |
-
# Geocode the retailers.
|
186 |
-
config = dotenv_values(env_file)
|
187 |
-
google_maps_api_key = config['GOOGLE_MAPS_API_KEY']
|
188 |
-
cols = ['premise_street_address', 'premise_city', 'premise_state']
|
189 |
-
retailers['address'] = retailers[cols].apply(
|
190 |
-
lambda row: ', '.join(row.values.astype(str)),
|
191 |
-
axis=1,
|
192 |
-
)
|
193 |
-
retailers = geocode_addresses(
|
194 |
-
retailers,
|
195 |
-
api_key=google_maps_api_key,
|
196 |
-
address_field='address',
|
197 |
-
)
|
198 |
-
drop_cols = ['state', 'state_name', 'address', 'formatted_address']
|
199 |
-
gis_cols = {
|
200 |
-
'county': 'premise_county',
|
201 |
-
'latitude': 'premise_latitude',
|
202 |
-
'longitude': 'premise_longitude'
|
203 |
-
}
|
204 |
-
licenses['premise_zip_code'] = licenses['formatted_address'].apply(
|
205 |
-
lambda x: x.split(', ')[2].split(',')[0].split(' ')[-1] if STATE in str(x) else x
|
206 |
-
)
|
207 |
-
retailers.drop(columns=drop_cols, inplace=True)
|
208 |
-
retailers.rename(columns=gis_cols, inplace=True)
|
209 |
-
|
210 |
-
# Save the retailers
|
211 |
-
if data_dir is not None:
|
212 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
213 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
214 |
-
|
215 |
-
# Return all of the data.
|
216 |
-
return pd.concat([licenses, retailers])
|
217 |
-
|
218 |
-
|
219 |
-
if __name__ == '__main__':
|
220 |
-
|
221 |
-
# Support command line usage.
|
222 |
-
import argparse
|
223 |
-
try:
|
224 |
-
arg_parser = argparse.ArgumentParser()
|
225 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
226 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
227 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
228 |
-
args = arg_parser.parse_args()
|
229 |
-
except SystemExit:
|
230 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
231 |
-
|
232 |
-
# Get licenses, saving them to the specified directory.
|
233 |
-
data_dir = args.get('d', args.get('data_dir'))
|
234 |
-
env_file = args.get('env_file')
|
235 |
-
data = get_licenses_nv(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_or.py
DELETED
@@ -1,213 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Oregon Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/28/2022
|
9 |
-
Updated: 10/7/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Oregon cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Oregon Liquor and Cannabis Commission
|
19 |
-
URL: <https://www.oregon.gov/olcc/marijuana/pages/recreational-marijuana-licensing.aspx>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from typing import Optional
|
26 |
-
|
27 |
-
# External imports.
|
28 |
-
from dotenv import dotenv_values
|
29 |
-
import pandas as pd
|
30 |
-
import requests
|
31 |
-
from cannlytics.data.gis import geocode_addresses
|
32 |
-
|
33 |
-
|
34 |
-
# Specify where your data lives.
|
35 |
-
DATA_DIR = '../data/or'
|
36 |
-
ENV_FILE = '../.env'
|
37 |
-
|
38 |
-
# Specify state-specific constants.
|
39 |
-
OREGON = {
|
40 |
-
'licensing_authority_id': 'OLCC',
|
41 |
-
'licensing_authority': 'Oregon Liquor and Cannabis Commission',
|
42 |
-
'licenses': {
|
43 |
-
'url': 'https://www.oregon.gov/olcc/marijuana/Documents/MarijuanaLicenses_Approved.xlsx',
|
44 |
-
},
|
45 |
-
'retailers': {
|
46 |
-
'url': 'https://www.oregon.gov/olcc/marijuana/Documents/Approved_Retail_Licenses.xlsx',
|
47 |
-
'columns': {
|
48 |
-
'TRADE NAME': 'business_dba_name',
|
49 |
-
'POSTAL CITY': 'premise_city',
|
50 |
-
'COUNTY': 'premise_county',
|
51 |
-
'STREET ADDRESS': 'premise_street_address',
|
52 |
-
'ZIP': 'premise_zip_code',
|
53 |
-
'Med Grade': 'medicinal',
|
54 |
-
'Delivery': 'delivery',
|
55 |
-
},
|
56 |
-
'drop_columns': [
|
57 |
-
'medicinal',
|
58 |
-
'delivery',
|
59 |
-
],
|
60 |
-
},
|
61 |
-
}
|
62 |
-
|
63 |
-
def get_licenses_or(
|
64 |
-
data_dir: Optional[str] = None,
|
65 |
-
env_file: Optional[str] = '.env',
|
66 |
-
# Optional: Add print statements.
|
67 |
-
# verbose: Optional[bool] = False,
|
68 |
-
):
|
69 |
-
"""Get California cannabis license data."""
|
70 |
-
|
71 |
-
# Create the necessary directories.
|
72 |
-
file_dir = f'{data_dir}/.datasets'
|
73 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
74 |
-
if not os.path.exists(file_dir): os.makedirs(file_dir)
|
75 |
-
|
76 |
-
# Download the data workbooks.
|
77 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
78 |
-
outfile = f'{file_dir}/retailers-or-{timestamp}.xlsx'
|
79 |
-
response = requests.get(OREGON['retailers']['url'])
|
80 |
-
with open(outfile, 'wb') as doc:
|
81 |
-
doc.write(response.content)
|
82 |
-
|
83 |
-
# Extract data from the workbooks, removing the footnote.
|
84 |
-
data = pd.read_excel(outfile, skiprows=3)
|
85 |
-
data = data[:-1]
|
86 |
-
data.rename(columns=OREGON['retailers']['columns'], inplace=True)
|
87 |
-
|
88 |
-
# Optional: Remove licenses with an asterisk (*).
|
89 |
-
|
90 |
-
# Curate the data.
|
91 |
-
data['licensing_authority_id'] = OREGON['licensing_authority_id']
|
92 |
-
data['licensing_authority'] = OREGON['licensing_authority']
|
93 |
-
data['license_status'] = 'Active'
|
94 |
-
data['license_designation'] = 'Adult-Use'
|
95 |
-
data['premise_state'] = 'OR'
|
96 |
-
data.loc[data['medicinal'] == 'Yes', 'license_designation'] = 'Adult-Use and Medicinal'
|
97 |
-
data['business_image_url'] = None
|
98 |
-
data['license_status_date'] = None
|
99 |
-
data['license_term'] = None
|
100 |
-
data['issue_date'] = None
|
101 |
-
data['expiration_date'] = None
|
102 |
-
data['business_email'] = None
|
103 |
-
data['business_owner_name'] = None
|
104 |
-
data['business_structure'] = None
|
105 |
-
data['business_website'] = None
|
106 |
-
data['activity'] = None
|
107 |
-
data['business_phone'] = None
|
108 |
-
data['parcel_number'] = None
|
109 |
-
data['business_legal_name'] = data['business_dba_name']
|
110 |
-
|
111 |
-
# Optional: Convert `medicinal` and `delivery` columns to boolean.
|
112 |
-
# data['medicinal'] = data['medicinal'].map(dict(Yes=1))
|
113 |
-
# data['delivery'] = data['delivery'].map(dict(Yes=1))
|
114 |
-
# data['medicinal'].fillna(0, inplace=True)
|
115 |
-
# data['delivery'].fillna(0, inplace=True)
|
116 |
-
data.drop(columns=['medicinal', 'delivery'], inplace=True)
|
117 |
-
|
118 |
-
# Convert certain columns from upper case title case.
|
119 |
-
cols = ['business_dba_name', 'premise_city', 'premise_county',
|
120 |
-
'premise_street_address']
|
121 |
-
for col in cols:
|
122 |
-
data[col] = data[col].apply(lambda x: x.title().strip())
|
123 |
-
|
124 |
-
# Convert zip code to a string.
|
125 |
-
data.loc[:, 'premise_zip_code'] = data['premise_zip_code'].apply(lambda x: str(int(x)))
|
126 |
-
|
127 |
-
# Get the `data_refreshed_date`.
|
128 |
-
df = pd.read_excel(outfile, index_col=None, usecols='C', header=1, nrows=0)
|
129 |
-
header = df.columns.values[0]
|
130 |
-
date = pd.to_datetime(header.split(' ')[-1])
|
131 |
-
data['data_refreshed_date'] = date.isoformat()
|
132 |
-
|
133 |
-
# Get the `license_number` and `license_type` from license list.
|
134 |
-
license_file = f'{file_dir}/licenses-or-{timestamp}.xlsx'
|
135 |
-
response = requests.get(OREGON['licenses']['url'])
|
136 |
-
with open(license_file, 'wb') as doc:
|
137 |
-
doc.write(response.content)
|
138 |
-
licenses = pd.read_excel(license_file, skiprows=2)
|
139 |
-
licenses['BUSINESS NAME'] = licenses['BUSINESS NAME'].apply(
|
140 |
-
lambda x: str(x).title().strip(),
|
141 |
-
)
|
142 |
-
licenses = licenses.loc[licenses['LICENSE TYPE'] == 'Recreational Retailer']
|
143 |
-
data = pd.merge(
|
144 |
-
data,
|
145 |
-
licenses[['BUSINESS NAME', 'COUNTY', 'LICENSE NUMBER', 'LICENSE TYPE']],
|
146 |
-
left_on=['business_dba_name', 'premise_county'],
|
147 |
-
right_on=['BUSINESS NAME', 'COUNTY'],
|
148 |
-
how='left',
|
149 |
-
)
|
150 |
-
|
151 |
-
# Clean the merged columns.
|
152 |
-
data.drop_duplicates(subset='premise_street_address', inplace=True)
|
153 |
-
columns = {
|
154 |
-
'LICENSE NUMBER': 'license_number',
|
155 |
-
'LICENSE TYPE': 'license_type',
|
156 |
-
}
|
157 |
-
data.rename(columns=columns, inplace=True)
|
158 |
-
data.drop(columns=['BUSINESS NAME', 'COUNTY'], inplace=True)
|
159 |
-
data['id'] = data['license_number']
|
160 |
-
|
161 |
-
# Geocode licenses to get `premise_latitude` and `premise_longitude`.
|
162 |
-
config = dotenv_values(env_file)
|
163 |
-
google_maps_api_key = config['GOOGLE_MAPS_API_KEY']
|
164 |
-
cols = ['premise_street_address', 'premise_city', 'premise_state',
|
165 |
-
'premise_zip_code']
|
166 |
-
data['address'] = data[cols].apply(
|
167 |
-
lambda row: ', '.join(row.values.astype(str)),
|
168 |
-
axis=1,
|
169 |
-
)
|
170 |
-
data = geocode_addresses(
|
171 |
-
data,
|
172 |
-
api_key=google_maps_api_key,
|
173 |
-
address_field='address',
|
174 |
-
)
|
175 |
-
drop_cols = ['state', 'state_name', 'county', 'address', 'formatted_address']
|
176 |
-
data.drop(columns=drop_cols, inplace=True)
|
177 |
-
gis_cols = {
|
178 |
-
'latitude': 'premise_latitude',
|
179 |
-
'longitude': 'premise_longitude'
|
180 |
-
}
|
181 |
-
data.rename(columns=gis_cols, inplace=True)
|
182 |
-
|
183 |
-
# Optional: Lookup details by searching for business' websites.
|
184 |
-
# - business_email
|
185 |
-
# - business_phone
|
186 |
-
|
187 |
-
# Optional: Create fields for standardization:
|
188 |
-
# - id
|
189 |
-
|
190 |
-
# Save the license data.
|
191 |
-
if data_dir is not None:
|
192 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
193 |
-
data.to_csv(f'{data_dir}/licenses-or-{timestamp}.csv', index=False)
|
194 |
-
return data
|
195 |
-
|
196 |
-
|
197 |
-
if __name__ == '__main__':
|
198 |
-
|
199 |
-
# Support command line usage.
|
200 |
-
import argparse
|
201 |
-
try:
|
202 |
-
arg_parser = argparse.ArgumentParser()
|
203 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
204 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
205 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
206 |
-
args = arg_parser.parse_args()
|
207 |
-
except SystemExit:
|
208 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
209 |
-
|
210 |
-
# Get California licenses, saving them to the specified directory.
|
211 |
-
data_dir = args.get('d', args.get('data_dir'))
|
212 |
-
env_file = args.get('env_file')
|
213 |
-
get_licenses_or(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_ri.py
DELETED
@@ -1,179 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Rhode Island Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/3/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Rhode Island cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Rhode Island
|
19 |
-
URL: <https://dbr.ri.gov/office-cannabis-regulation/compassion-centers/licensed-compassion-centers>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from typing import Optional
|
26 |
-
|
27 |
-
# External imports.
|
28 |
-
from bs4 import BeautifulSoup
|
29 |
-
from cannlytics.data.gis import geocode_addresses
|
30 |
-
from dotenv import dotenv_values
|
31 |
-
import pandas as pd
|
32 |
-
import requests
|
33 |
-
|
34 |
-
|
35 |
-
# Specify where your data lives.
|
36 |
-
DATA_DIR = '../data/ri'
|
37 |
-
ENV_FILE = '../.env'
|
38 |
-
|
39 |
-
# Specify state-specific constants.
|
40 |
-
STATE = 'RI'
|
41 |
-
RHODE_ISLAND = {
|
42 |
-
'licensing_authority_id': 'RIDBH',
|
43 |
-
'licensing_authority': 'Rhode Island Department of Business Regulation',
|
44 |
-
'retailers': {
|
45 |
-
'url': 'https://dbr.ri.gov/office-cannabis-regulation/compassion-centers/licensed-compassion-centers',
|
46 |
-
'columns': [
|
47 |
-
'license_number',
|
48 |
-
'business_legal_name',
|
49 |
-
'address',
|
50 |
-
'business_phone',
|
51 |
-
'license_designation',
|
52 |
-
],
|
53 |
-
}
|
54 |
-
}
|
55 |
-
|
56 |
-
|
57 |
-
def get_licenses_ri(
|
58 |
-
data_dir: Optional[str] = None,
|
59 |
-
env_file: Optional[str] = '.env',
|
60 |
-
):
|
61 |
-
"""Get Rhode Island cannabis license data."""
|
62 |
-
|
63 |
-
# Get the licenses webpage.
|
64 |
-
url = RHODE_ISLAND['retailers']['url']
|
65 |
-
response = requests.get(url)
|
66 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
67 |
-
|
68 |
-
# Parse the table data.
|
69 |
-
data = []
|
70 |
-
columns = RHODE_ISLAND['retailers']['columns']
|
71 |
-
table = soup.find('table')
|
72 |
-
rows = table.find_all('tr')
|
73 |
-
for row in rows[1:]:
|
74 |
-
cells = row.find_all('td')
|
75 |
-
obs = {}
|
76 |
-
for i, cell in enumerate(cells):
|
77 |
-
column = columns[i]
|
78 |
-
obs[column] = cell.text
|
79 |
-
data.append(obs)
|
80 |
-
|
81 |
-
# Optional: It's possible to download the certificate to get it's `issue_date`.
|
82 |
-
|
83 |
-
# Standardize the license data.
|
84 |
-
retailers = pd.DataFrame(data)
|
85 |
-
retailers['id'] = retailers['license_number']
|
86 |
-
retailers['licensing_authority_id'] = RHODE_ISLAND['licensing_authority_id']
|
87 |
-
retailers['licensing_authority'] = RHODE_ISLAND['licensing_authority']
|
88 |
-
retailers['premise_state'] = STATE
|
89 |
-
retailers['license_type'] = 'Commercial - Retailer'
|
90 |
-
retailers['license_status'] = 'Active'
|
91 |
-
retailers['license_status_date'] = None
|
92 |
-
retailers['license_term'] = None
|
93 |
-
retailers['issue_date'] = None
|
94 |
-
retailers['expiration_date'] = None
|
95 |
-
retailers['business_owner_name'] = None
|
96 |
-
retailers['business_structure'] = None
|
97 |
-
retailers['business_email'] = None
|
98 |
-
retailers['activity'] = None
|
99 |
-
retailers['parcel_number'] = None
|
100 |
-
retailers['business_image_url'] = None
|
101 |
-
retailers['business_website'] = None
|
102 |
-
|
103 |
-
# Correct `license_designation`.
|
104 |
-
coding = dict(Yes='Adult Use and Cultivation', No='Adult Use')
|
105 |
-
retailers['license_designation'] = retailers['license_designation'].map(coding)
|
106 |
-
|
107 |
-
# Correct `business_dba_name`.
|
108 |
-
criterion = retailers['business_legal_name'].str.contains('D/B/A')
|
109 |
-
retailers['business_dba_name'] = retailers['business_legal_name']
|
110 |
-
retailers.loc[criterion, 'business_dba_name'] = retailers['business_legal_name'].apply(
|
111 |
-
lambda x: x.split('D/B/A')[1].strip() if 'D/B/A' in x else x
|
112 |
-
)
|
113 |
-
retailers.loc[criterion, 'business_legal_name'] = retailers['business_legal_name'].apply(
|
114 |
-
lambda x: x.split('D/B/A')[0].strip()
|
115 |
-
)
|
116 |
-
criterion = retailers['business_legal_name'].str.contains('F/K/A')
|
117 |
-
retailers.loc[criterion, 'business_dba_name'] = retailers['business_legal_name'].apply(
|
118 |
-
lambda x: x.split('F/K/A')[1].strip() if 'D/B/A' in x else x
|
119 |
-
)
|
120 |
-
retailers.loc[criterion, 'business_legal_name'] = retailers['business_legal_name'].apply(
|
121 |
-
lambda x: x.split('F/K/A')[0].strip()
|
122 |
-
)
|
123 |
-
|
124 |
-
# Get the refreshed date.
|
125 |
-
par = soup.find_all('p')[-1]
|
126 |
-
date = par.text.split('updated on ')[-1].split('.')[0]
|
127 |
-
retailers['data_refreshed_date'] = pd.to_datetime(date).isoformat()
|
128 |
-
|
129 |
-
# Geocode the licenses.
|
130 |
-
config = dotenv_values(env_file)
|
131 |
-
google_maps_api_key = config['GOOGLE_MAPS_API_KEY']
|
132 |
-
retailers = geocode_addresses(
|
133 |
-
retailers,
|
134 |
-
api_key=google_maps_api_key,
|
135 |
-
address_field='address',
|
136 |
-
)
|
137 |
-
retailers['premise_street_address'] = retailers['formatted_address'].apply(
|
138 |
-
lambda x: x.split(',')[0]
|
139 |
-
)
|
140 |
-
retailers['premise_city'] = retailers['formatted_address'].apply(
|
141 |
-
lambda x: x.split(', ')[1].split(',')[0]
|
142 |
-
)
|
143 |
-
retailers['premise_zip_code'] = retailers['formatted_address'].apply(
|
144 |
-
lambda x: x.split(', ')[2].split(',')[0].split(' ')[-1]
|
145 |
-
)
|
146 |
-
drop_cols = ['state', 'state_name', 'address', 'formatted_address']
|
147 |
-
retailers.drop(columns=drop_cols, inplace=True)
|
148 |
-
gis_cols = {
|
149 |
-
'county': 'premise_county',
|
150 |
-
'latitude': 'premise_latitude',
|
151 |
-
'longitude': 'premise_longitude'
|
152 |
-
}
|
153 |
-
retailers.rename(columns=gis_cols, inplace=True)
|
154 |
-
|
155 |
-
# Save and return the data.
|
156 |
-
if data_dir is not None:
|
157 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
158 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
159 |
-
retailers.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
160 |
-
return retailers
|
161 |
-
|
162 |
-
|
163 |
-
if __name__ == '__main__':
|
164 |
-
|
165 |
-
# Support command line usage.
|
166 |
-
import argparse
|
167 |
-
try:
|
168 |
-
arg_parser = argparse.ArgumentParser()
|
169 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
170 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
171 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
172 |
-
args = arg_parser.parse_args()
|
173 |
-
except SystemExit:
|
174 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
175 |
-
|
176 |
-
# Get licenses, saving them to the specified directory.
|
177 |
-
data_dir = args.get('d', args.get('data_dir'))
|
178 |
-
env_file = args.get('env_file')
|
179 |
-
data = get_licenses_ri(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_vt.py
DELETED
@@ -1,253 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Vermont Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/7/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Vermont cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Vermont
|
19 |
-
URL: <https://ccb.vermont.gov/licenses>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from typing import Optional
|
26 |
-
|
27 |
-
# External imports.
|
28 |
-
from bs4 import BeautifulSoup
|
29 |
-
from cannlytics.data.gis import geocode_addresses
|
30 |
-
from dotenv import dotenv_values
|
31 |
-
import pandas as pd
|
32 |
-
import requests
|
33 |
-
|
34 |
-
|
35 |
-
# Specify where your data lives.
|
36 |
-
DATA_DIR = '../data/vt'
|
37 |
-
ENV_FILE = '../.env'
|
38 |
-
|
39 |
-
# Specify state-specific constants.
|
40 |
-
STATE = 'VT'
|
41 |
-
VERMONT = {
|
42 |
-
'licensing_authority_id': 'VTCCB',
|
43 |
-
'licensing_authority': 'Vermont Cannabis Control Board',
|
44 |
-
'licenses_url': 'https://ccb.vermont.gov/licenses',
|
45 |
-
'licenses': {
|
46 |
-
'licensedcultivators': {
|
47 |
-
'columns': [
|
48 |
-
'business_legal_name',
|
49 |
-
'license_type',
|
50 |
-
'address',
|
51 |
-
'license_designation',
|
52 |
-
],
|
53 |
-
},
|
54 |
-
'outdoorcultivators': {
|
55 |
-
'columns': [
|
56 |
-
'business_legal_name',
|
57 |
-
'license_type',
|
58 |
-
'premise_city',
|
59 |
-
'license_designation',
|
60 |
-
],
|
61 |
-
},
|
62 |
-
'mixedcultivators': {
|
63 |
-
'columns': [
|
64 |
-
'business_legal_name',
|
65 |
-
'license_type',
|
66 |
-
'premise_city',
|
67 |
-
'license_designation',
|
68 |
-
],
|
69 |
-
},
|
70 |
-
'testinglaboratories': {
|
71 |
-
'columns': [
|
72 |
-
'business_legal_name',
|
73 |
-
'license_type',
|
74 |
-
'premise_city',
|
75 |
-
'license_designation',
|
76 |
-
'address'
|
77 |
-
],
|
78 |
-
},
|
79 |
-
'integrated': {
|
80 |
-
'columns': [
|
81 |
-
'business_legal_name',
|
82 |
-
'license_type',
|
83 |
-
'premise_city',
|
84 |
-
'license_designation',
|
85 |
-
],
|
86 |
-
},
|
87 |
-
'retailers': {
|
88 |
-
'columns': [
|
89 |
-
'business_legal_name',
|
90 |
-
'license_type',
|
91 |
-
'address',
|
92 |
-
'license_designation',
|
93 |
-
],
|
94 |
-
},
|
95 |
-
'manufacturers': {
|
96 |
-
'columns': [
|
97 |
-
'business_legal_name',
|
98 |
-
'license_type',
|
99 |
-
'premise_city',
|
100 |
-
'license_designation',
|
101 |
-
],
|
102 |
-
},
|
103 |
-
'wholesalers': {
|
104 |
-
'columns': [
|
105 |
-
'business_legal_name',
|
106 |
-
'license_type',
|
107 |
-
'premise_city',
|
108 |
-
'license_designation',
|
109 |
-
],
|
110 |
-
},
|
111 |
-
},
|
112 |
-
}
|
113 |
-
|
114 |
-
|
115 |
-
def get_licenses_vt(
|
116 |
-
data_dir: Optional[str] = None,
|
117 |
-
env_file: Optional[str] = '.env',
|
118 |
-
):
|
119 |
-
"""Get Vermont cannabis license data."""
|
120 |
-
|
121 |
-
# Get the licenses from the webpage.
|
122 |
-
url = VERMONT['licenses_url']
|
123 |
-
response = requests.get(url)
|
124 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
125 |
-
|
126 |
-
# Parse the various table types.
|
127 |
-
data = []
|
128 |
-
for license_type, values in VERMONT['licenses'].items():
|
129 |
-
columns = values['columns']
|
130 |
-
table = block = soup.find(attrs={'id': f'block-{license_type}'})
|
131 |
-
rows = table.find_all('tr')
|
132 |
-
for row in rows[1:]:
|
133 |
-
cells = row.find_all('td')
|
134 |
-
obs = {}
|
135 |
-
for i, cell in enumerate(cells):
|
136 |
-
column = columns[i]
|
137 |
-
obs[column] = cell.text
|
138 |
-
data.append(obs)
|
139 |
-
|
140 |
-
# Standardize the licenses.
|
141 |
-
licenses = pd.DataFrame(data)
|
142 |
-
licenses['id'] = licenses.index
|
143 |
-
licenses['license_number'] = None # FIXME: It would be awesome to find these!
|
144 |
-
licenses['licensing_authority_id'] = VERMONT['licensing_authority_id']
|
145 |
-
licenses['licensing_authority'] = VERMONT['licensing_authority']
|
146 |
-
licenses['license_designation'] = 'Adult-Use'
|
147 |
-
licenses['premise_state'] = STATE
|
148 |
-
licenses['license_status'] = None
|
149 |
-
licenses['license_status_date'] = None
|
150 |
-
licenses['license_term'] = None
|
151 |
-
licenses['issue_date'] = None
|
152 |
-
licenses['expiration_date'] = None
|
153 |
-
licenses['business_owner_name'] = None
|
154 |
-
licenses['business_structure'] = None
|
155 |
-
licenses['activity'] = None
|
156 |
-
licenses['parcel_number'] = None
|
157 |
-
licenses['business_phone'] = None
|
158 |
-
licenses['business_email'] = None
|
159 |
-
licenses['business_image_url'] = None
|
160 |
-
licenses['business_website'] = None
|
161 |
-
|
162 |
-
# Separate the `license_designation` from `license_type` if (Tier x).
|
163 |
-
criterion = licenses['license_type'].str.contains('Tier ')
|
164 |
-
licenses.loc[criterion, 'license_designation'] = licenses.loc[criterion]['license_type'].apply(
|
165 |
-
lambda x: 'Tier ' + x.split('(Tier ')[1].rstrip(')')
|
166 |
-
)
|
167 |
-
licenses.loc[criterion, 'license_type'] = licenses.loc[criterion]['license_type'].apply(
|
168 |
-
lambda x: x.split('(Tier ')[0].strip()
|
169 |
-
)
|
170 |
-
|
171 |
-
# Separate labs' `business_email` and `business_phone` from the `address`.
|
172 |
-
criterion = licenses['license_type'] == 'Testing Lab'
|
173 |
-
licenses.loc[criterion, 'business_email'] = licenses.loc[criterion]['address'].apply(
|
174 |
-
lambda x: x.split('Email: ')[-1].rstrip('\n') if isinstance(x, str) else x
|
175 |
-
)
|
176 |
-
licenses.loc[criterion, 'business_phone'] = licenses.loc[criterion]['address'].apply(
|
177 |
-
lambda x: x.split('Phone: ')[-1].split('Email: ')[0].rstrip('\n') if isinstance(x, str) else x
|
178 |
-
)
|
179 |
-
licenses.loc[criterion, 'address'] = licenses.loc[criterion]['address'].apply(
|
180 |
-
lambda x: x.split('Phone: ')[0].replace('\n', ' ').strip() if isinstance(x, str) else x
|
181 |
-
)
|
182 |
-
|
183 |
-
# Split any DBA from the legal name.
|
184 |
-
splits = [';', 'DBA - ', '(DBA)', 'DBA ', 'dba ']
|
185 |
-
licenses['business_dba_name'] = licenses['business_legal_name']
|
186 |
-
for split in splits:
|
187 |
-
criterion = licenses['business_legal_name'].str.contains(split)
|
188 |
-
licenses.loc[criterion, 'business_dba_name'] = licenses.loc[criterion]['business_legal_name'].apply(
|
189 |
-
lambda x: x.split(split)[1].replace(')', '').strip() if split in x else x
|
190 |
-
)
|
191 |
-
licenses.loc[criterion, 'business_legal_name'] = licenses.loc[criterion]['business_legal_name'].apply(
|
192 |
-
lambda x: x.split(split)[0].replace('(', '').strip()
|
193 |
-
)
|
194 |
-
licenses.loc[licenses['business_legal_name'] == '', 'business_legal_name'] = licenses['business_dba_name']
|
195 |
-
|
196 |
-
# Get the refreshed date.
|
197 |
-
licenses['data_refreshed_date'] = datetime.now().isoformat()
|
198 |
-
|
199 |
-
# Geocode the licenses.
|
200 |
-
# FIXME: There are some wonky addresses that are output!
|
201 |
-
config = dotenv_values(env_file)
|
202 |
-
google_maps_api_key = config['GOOGLE_MAPS_API_KEY']
|
203 |
-
licenses = geocode_addresses(
|
204 |
-
licenses,
|
205 |
-
api_key=google_maps_api_key,
|
206 |
-
address_field='address',
|
207 |
-
)
|
208 |
-
licenses['premise_street_address'] = licenses['formatted_address'].apply(
|
209 |
-
lambda x: x.split(',')[0] if STATE in str(x) else x
|
210 |
-
)
|
211 |
-
licenses['premise_city'] = licenses['formatted_address'].apply(
|
212 |
-
lambda x: x.split(', ')[1].split(',')[0] if STATE in str(x) else x
|
213 |
-
)
|
214 |
-
licenses['premise_zip_code'] = licenses['formatted_address'].apply(
|
215 |
-
lambda x: x.split(', ')[2].split(',')[0].split(' ')[-1] if STATE in str(x) else x
|
216 |
-
)
|
217 |
-
drop_cols = ['state', 'state_name', 'address', 'formatted_address']
|
218 |
-
licenses.drop(columns=drop_cols, inplace=True)
|
219 |
-
gis_cols = {
|
220 |
-
'county': 'premise_county',
|
221 |
-
'latitude': 'premise_latitude',
|
222 |
-
'longitude': 'premise_longitude'
|
223 |
-
}
|
224 |
-
licenses.rename(columns=gis_cols, inplace=True)
|
225 |
-
|
226 |
-
# Save and return the data.
|
227 |
-
if data_dir is not None:
|
228 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
229 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
230 |
-
retailers = licenses.loc[licenses['license_type'] == 'Retail']
|
231 |
-
licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
232 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
233 |
-
return licenses
|
234 |
-
|
235 |
-
|
236 |
-
# === Test ===
|
237 |
-
if __name__ == '__main__':
|
238 |
-
|
239 |
-
# Support command line usage.
|
240 |
-
import argparse
|
241 |
-
try:
|
242 |
-
arg_parser = argparse.ArgumentParser()
|
243 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
244 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
245 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
246 |
-
args = arg_parser.parse_args()
|
247 |
-
except SystemExit:
|
248 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
249 |
-
|
250 |
-
# Get licenses, saving them to the specified directory.
|
251 |
-
data_dir = args.get('d', args.get('data_dir'))
|
252 |
-
env_file = args.get('env_file')
|
253 |
-
data = get_licenses_vt(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/get_licenses_wa.py
DELETED
@@ -1,271 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get Washington Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/7/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect Washington cannabis license data.
|
15 |
-
|
16 |
-
Data Source:
|
17 |
-
|
18 |
-
- Washington State Liquor and Cannabis Board | Frequently Requested Lists
|
19 |
-
URL: <https://lcb.wa.gov/records/frequently-requested-lists>
|
20 |
-
|
21 |
-
"""
|
22 |
-
# Standard imports.
|
23 |
-
from datetime import datetime
|
24 |
-
import os
|
25 |
-
from typing import Optional
|
26 |
-
|
27 |
-
# External imports.
|
28 |
-
from bs4 import BeautifulSoup
|
29 |
-
from cannlytics.data.gis import geocode_addresses
|
30 |
-
from dotenv import dotenv_values
|
31 |
-
import pandas as pd
|
32 |
-
import requests
|
33 |
-
|
34 |
-
|
35 |
-
# Specify where your data lives.
|
36 |
-
DATA_DIR = '../data/wa'
|
37 |
-
ENV_FILE = '../.env'
|
38 |
-
|
39 |
-
# Specify state-specific constants.
|
40 |
-
STATE = 'WA'
|
41 |
-
WASHINGTON = {
|
42 |
-
'licensing_authority_id': 'WSLCB',
|
43 |
-
'licensing_authority': 'Washington State Liquor and Cannabis Board',
|
44 |
-
'licenses_urls': 'https://lcb.wa.gov/records/frequently-requested-lists',
|
45 |
-
'labs': {
|
46 |
-
'key': 'Lab-List',
|
47 |
-
'columns': {
|
48 |
-
'Lab Name': 'business_legal_name',
|
49 |
-
'Lab #': 'license_number',
|
50 |
-
'Address 1': 'premise_street_address',
|
51 |
-
'Address 2': 'premise_street_address_2',
|
52 |
-
'City': 'premise_city',
|
53 |
-
'Zip': 'premise_zip_code',
|
54 |
-
'Phone': 'business_phone',
|
55 |
-
'Status': 'license_status',
|
56 |
-
'Certification Date': 'issue_date',
|
57 |
-
},
|
58 |
-
'drop_columns': [
|
59 |
-
'Pesticides',
|
60 |
-
'Heavy Metals',
|
61 |
-
'Mycotoxins',
|
62 |
-
'Water Activity',
|
63 |
-
'Terpenes',
|
64 |
-
],
|
65 |
-
},
|
66 |
-
'medical': {
|
67 |
-
'key': 'MedicalCannabisEndorsements',
|
68 |
-
'columns': {
|
69 |
-
'License': 'license_number',
|
70 |
-
'UBI': 'id',
|
71 |
-
'Tradename': 'business_dba_name',
|
72 |
-
'Privilege': 'license_type',
|
73 |
-
'Status': 'license_status',
|
74 |
-
'Med Privilege Code': 'license_designation',
|
75 |
-
'Termination Code': 'license_term',
|
76 |
-
'Street Adress': 'premise_street_address',
|
77 |
-
'Suite Rm': 'premise_street_address_2',
|
78 |
-
'City': 'premise_city',
|
79 |
-
'State': 'premise_state',
|
80 |
-
'County': 'premise_county',
|
81 |
-
'Zip Code': 'premise_zip_code',
|
82 |
-
'Date Created': 'issue_date',
|
83 |
-
'Day Phone': 'business_phone',
|
84 |
-
'Email': 'business_email',
|
85 |
-
},
|
86 |
-
},
|
87 |
-
'retailers': {
|
88 |
-
'key': 'CannabisApplicants',
|
89 |
-
'columns': {
|
90 |
-
'Tradename': 'business_dba_name',
|
91 |
-
'License ': 'license_number',
|
92 |
-
'UBI': 'id',
|
93 |
-
'Street Address': 'premise_street_address',
|
94 |
-
'Suite Rm': 'premise_street_address_2',
|
95 |
-
'City': 'premise_city',
|
96 |
-
'State': 'premise_state',
|
97 |
-
'county': 'premise_county',
|
98 |
-
'Zip Code': 'premise_zip_code',
|
99 |
-
'Priv Desc': 'license_type',
|
100 |
-
'Privilege Status': 'license_status',
|
101 |
-
'Day Phone': 'business_phone',
|
102 |
-
},
|
103 |
-
},
|
104 |
-
}
|
105 |
-
|
106 |
-
|
107 |
-
def download_file(url, dest='./', headers=None):
|
108 |
-
"""Download a file from a given URL to a local destination.
|
109 |
-
Args:
|
110 |
-
url (str): The URL of the data file.
|
111 |
-
dest (str): The destination for the data file, `./` by default (optional).
|
112 |
-
headers (dict): HTTP headers, `None` by default (optional).
|
113 |
-
Returns:
|
114 |
-
(str): The location for the data file.
|
115 |
-
"""
|
116 |
-
filename = url.split('/')[-1]
|
117 |
-
data_file = os.path.join(dest, filename)
|
118 |
-
response = requests.get(url, headers=headers)
|
119 |
-
with open(data_file, 'wb') as doc:
|
120 |
-
doc.write(response.content)
|
121 |
-
return data_file
|
122 |
-
|
123 |
-
|
124 |
-
def get_licenses_wa(
|
125 |
-
data_dir: Optional[str] = None,
|
126 |
-
env_file: Optional[str] = '.env',
|
127 |
-
):
|
128 |
-
"""Get Washington cannabis license data."""
|
129 |
-
|
130 |
-
# Create the necessary directories.
|
131 |
-
file_dir = f'{data_dir}/.datasets'
|
132 |
-
if not os.path.exists(data_dir): os.makedirs(data_dir)
|
133 |
-
if not os.path.exists(file_dir): os.makedirs(file_dir)
|
134 |
-
|
135 |
-
# Get the URLs for the license workbooks.
|
136 |
-
labs_url, medical_url, retailers_url = None, None, None
|
137 |
-
labs_key = WASHINGTON['labs']['key']
|
138 |
-
medical_key = WASHINGTON['medical']['key']
|
139 |
-
retailers_key = WASHINGTON['retailers']['key']
|
140 |
-
url = WASHINGTON['licenses_urls']
|
141 |
-
response = requests.get(url)
|
142 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
143 |
-
links = soup.find_all('a')
|
144 |
-
for link in links:
|
145 |
-
href = link['href']
|
146 |
-
if labs_key in href:
|
147 |
-
labs_url = href
|
148 |
-
elif retailers_key in href:
|
149 |
-
retailers_url = href
|
150 |
-
elif medical_key in href:
|
151 |
-
medical_url = href
|
152 |
-
break
|
153 |
-
|
154 |
-
# Download the workbooks.
|
155 |
-
lab_source_file = download_file(labs_url, dest=file_dir)
|
156 |
-
medical_source_file = download_file(medical_url, dest=file_dir)
|
157 |
-
retailers_source_file = download_file(retailers_url, dest=file_dir)
|
158 |
-
|
159 |
-
# Extract and standardize the data from the workbook.
|
160 |
-
retailers = pd.read_excel(retailers_source_file)
|
161 |
-
retailers.rename(columns=WASHINGTON['retailers']['columns'], inplace=True)
|
162 |
-
retailers['license_designation'] = 'Adult-Use'
|
163 |
-
retailers['license_type'] = 'Adult-Use Retailer'
|
164 |
-
|
165 |
-
labs = pd.read_excel(lab_source_file)
|
166 |
-
labs.rename(columns=WASHINGTON['labs']['columns'], inplace=True)
|
167 |
-
labs.drop(columns=WASHINGTON['labs']['drop_columns'], inplace=True)
|
168 |
-
labs['license_type'] = 'Lab'
|
169 |
-
|
170 |
-
medical = pd.read_excel(medical_source_file, skiprows=2)
|
171 |
-
medical.rename(columns=WASHINGTON['medical']['columns'], inplace=True)
|
172 |
-
medical['license_designation'] = 'Medicinal'
|
173 |
-
medical['license_type'] = 'Medical Retailer'
|
174 |
-
|
175 |
-
# Aggregate the licenses.
|
176 |
-
licenses = pd.concat([retailers, medical, labs])
|
177 |
-
|
178 |
-
# Standardize all of the licenses at once!
|
179 |
-
licenses = licenses.assign(
|
180 |
-
licensing_authority_id=WASHINGTON['licensing_authority_id'],
|
181 |
-
licensing_authority=WASHINGTON['licensing_authority'],
|
182 |
-
premise_state=STATE,
|
183 |
-
license_status_date=None,
|
184 |
-
expiration_date=None,
|
185 |
-
activity=None,
|
186 |
-
parcel_number=None,
|
187 |
-
business_owner_name=None,
|
188 |
-
business_structure=None,
|
189 |
-
business_image_url=None,
|
190 |
-
business_website=None,
|
191 |
-
)
|
192 |
-
|
193 |
-
# Fill legal and DBA names.
|
194 |
-
licenses['id'].fillna(licenses['license_number'], inplace=True)
|
195 |
-
licenses['business_legal_name'].fillna(licenses['business_dba_name'], inplace=True)
|
196 |
-
licenses['business_dba_name'].fillna(licenses['business_legal_name'], inplace=True)
|
197 |
-
cols = ['business_legal_name', 'business_dba_name']
|
198 |
-
for col in cols:
|
199 |
-
licenses[col] = licenses[col].apply(
|
200 |
-
lambda x: x.title().replace('Llc', 'LLC').replace("'S", "'s").strip()
|
201 |
-
)
|
202 |
-
|
203 |
-
# Keep only active licenses.
|
204 |
-
license_statuses = ['Active', 'ACTIVE (ISSUED)', 'ACTIVE TITLE CERTIFICATE',]
|
205 |
-
licenses = licenses.loc[licenses['license_status'].isin(license_statuses)]
|
206 |
-
|
207 |
-
# Convert certain columns from upper case title case.
|
208 |
-
cols = ['business_dba_name', 'premise_city', 'premise_county',
|
209 |
-
'premise_street_address', 'license_type', 'license_status']
|
210 |
-
for col in cols:
|
211 |
-
retailers[col] = retailers[col].apply(lambda x: x.title().strip())
|
212 |
-
|
213 |
-
# Get the refreshed date.
|
214 |
-
date = retailers_source_file.split('\\')[-1].split('.')[0]
|
215 |
-
date = date.replace('CannabisApplicants', '')
|
216 |
-
date = date[:2] + '-' + date[2:4] + '-' + date[4:8]
|
217 |
-
licenses['data_refreshed_date'] = pd.to_datetime(date).isoformat()
|
218 |
-
|
219 |
-
# Append `premise_street_address_2` to `premise_street_address`.
|
220 |
-
cols = ['premise_street_address', 'premise_street_address_2']
|
221 |
-
licenses['premise_street_address'] = licenses[cols].apply(
|
222 |
-
lambda x : '{} {}'.format(x[0].strip(), x[1]).replace('nan', '').strip().replace(' ', ' '),
|
223 |
-
axis=1,
|
224 |
-
)
|
225 |
-
licenses.drop(columns=['premise_street_address_2'], inplace=True)
|
226 |
-
|
227 |
-
# Geocode licenses to get `premise_latitude` and `premise_longitude`.
|
228 |
-
config = dotenv_values(env_file)
|
229 |
-
api_key = config['GOOGLE_MAPS_API_KEY']
|
230 |
-
cols = ['premise_street_address', 'premise_city', 'premise_state',
|
231 |
-
'premise_zip_code']
|
232 |
-
licenses['address'] = licenses[cols].apply(
|
233 |
-
lambda row: ', '.join(row.values.astype(str)),
|
234 |
-
axis=1,
|
235 |
-
)
|
236 |
-
licenses = geocode_addresses(licenses, address_field='address', api_key=api_key)
|
237 |
-
drop_cols = ['state', 'state_name', 'county', 'address', 'formatted_address']
|
238 |
-
gis_cols = {'latitude': 'premise_latitude', 'longitude': 'premise_longitude'}
|
239 |
-
licenses.drop(columns=drop_cols, inplace=True)
|
240 |
-
licenses.rename(columns=gis_cols, inplace=True)
|
241 |
-
|
242 |
-
# TODO: Search for business website and image.
|
243 |
-
|
244 |
-
# Save and return the data.
|
245 |
-
if data_dir is not None:
|
246 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
247 |
-
licenses.to_csv(f'{data_dir}/licenses-{STATE.lower()}-{timestamp}.csv', index=False)
|
248 |
-
retailers = licenses.loc[licenses['license_type'] == 'Adult-Use Retailer']
|
249 |
-
retailers.to_csv(f'{data_dir}/retailers-{STATE.lower()}-{timestamp}.csv', index=False)
|
250 |
-
labs = licenses.loc[licenses['license_type'] == 'Lab']
|
251 |
-
labs.to_csv(f'{data_dir}/labs-{STATE.lower()}-{timestamp}.csv', index=False)
|
252 |
-
return retailers
|
253 |
-
|
254 |
-
|
255 |
-
if __name__ == '__main__':
|
256 |
-
|
257 |
-
# Support command line usage.
|
258 |
-
import argparse
|
259 |
-
try:
|
260 |
-
arg_parser = argparse.ArgumentParser()
|
261 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
262 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
263 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
264 |
-
args = arg_parser.parse_args()
|
265 |
-
except SystemExit:
|
266 |
-
args = {'d': DATA_DIR, 'env_file': ENV_FILE}
|
267 |
-
|
268 |
-
# Get licenses, saving them to the specified directory.
|
269 |
-
data_dir = args.get('d', args.get('data_dir'))
|
270 |
-
env_file = args.get('env_file')
|
271 |
-
data = get_licenses_wa(data_dir, env_file=env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
algorithms/main.py
DELETED
@@ -1,109 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | Get All Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/7/2022
|
10 |
-
License: <https://github.com/cannlytics/cannlytics/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Collect all cannabis license data from states with permitted adult-use:
|
15 |
-
|
16 |
-
✓ Alaska (Selenium)
|
17 |
-
✓ Arizona (Selenium)
|
18 |
-
✓ California
|
19 |
-
✓ Colorado
|
20 |
-
✓ Connecticut
|
21 |
-
✓ Illinois
|
22 |
-
✓ Maine
|
23 |
-
✓ Massachusetts
|
24 |
-
✓ Michigan (Selenium)
|
25 |
-
✓ Montana
|
26 |
-
✓ Nevada
|
27 |
-
✓ New Jersey
|
28 |
-
x New Mexico (Selenium) (FIXME)
|
29 |
-
✓ Oregon
|
30 |
-
✓ Rhode Island
|
31 |
-
✓ Vermont
|
32 |
-
✓ Washington
|
33 |
-
"""
|
34 |
-
# Standard imports.
|
35 |
-
from datetime import datetime
|
36 |
-
import importlib
|
37 |
-
import os
|
38 |
-
|
39 |
-
# External imports.
|
40 |
-
import pandas as pd
|
41 |
-
|
42 |
-
|
43 |
-
# Specify state-specific algorithms.
|
44 |
-
ALGORITHMS = {
|
45 |
-
'ak': 'get_licenses_ak',
|
46 |
-
'az': 'get_licenses_az',
|
47 |
-
'ca': 'get_licenses_ca',
|
48 |
-
'co': 'get_licenses_co',
|
49 |
-
'ct': 'get_licenses_ct',
|
50 |
-
'il': 'get_licenses_il',
|
51 |
-
'ma': 'get_licenses_ma',
|
52 |
-
'me': 'get_licenses_me',
|
53 |
-
'mi': 'get_licenses_mi',
|
54 |
-
'mt': 'get_licenses_mt',
|
55 |
-
'nj': 'get_licenses_nj',
|
56 |
-
# 'nm': 'get_licenses_nm',
|
57 |
-
'nv': 'get_licenses_nv',
|
58 |
-
'or': 'get_licenses_or',
|
59 |
-
'ri': 'get_licenses_ri',
|
60 |
-
'vt': 'get_licenses_vt',
|
61 |
-
'wa': 'get_licenses_wa',
|
62 |
-
}
|
63 |
-
DATA_DIR = '../data'
|
64 |
-
|
65 |
-
|
66 |
-
def main(data_dir, env_file):
|
67 |
-
"""Collect all cannabis license data from states with permitted adult-use,
|
68 |
-
dynamically importing modules and finding the entry point for each of the
|
69 |
-
`ALGORITHMS`."""
|
70 |
-
licenses = pd.DataFrame()
|
71 |
-
for state, algorithm in ALGORITHMS.items():
|
72 |
-
module = importlib.import_module(f'{algorithm}')
|
73 |
-
entry_point = getattr(module, algorithm)
|
74 |
-
try:
|
75 |
-
print(f'Getting license data for {state.upper()}.')
|
76 |
-
data = entry_point(data_dir, env_file=env_file)
|
77 |
-
if not os.path.exists(f'{DATA_DIR}/{state}'): os.makedirs(f'{DATA_DIR}/{state}')
|
78 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
79 |
-
data.to_csv(f'{DATA_DIR}/{state}/licenses-{state}-{timestamp}.csv', index=False)
|
80 |
-
licenses = pd.concat([licenses, data])
|
81 |
-
except:
|
82 |
-
print(f'Failed to collect {state.upper()} licenses.')
|
83 |
-
|
84 |
-
# Save all of the retailers.
|
85 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
86 |
-
licenses.to_csv(f'{DATA_DIR}/all/licenses-{timestamp}.csv', index=False)
|
87 |
-
return licenses
|
88 |
-
|
89 |
-
|
90 |
-
# === Test ===
|
91 |
-
if __name__ == '__main__':
|
92 |
-
|
93 |
-
# Support command line usage.
|
94 |
-
import argparse
|
95 |
-
try:
|
96 |
-
arg_parser = argparse.ArgumentParser()
|
97 |
-
arg_parser.add_argument('--d', dest='data_dir', type=str)
|
98 |
-
arg_parser.add_argument('--data_dir', dest='data_dir', type=str)
|
99 |
-
arg_parser.add_argument('--env', dest='env_file', type=str)
|
100 |
-
args = arg_parser.parse_args()
|
101 |
-
except SystemExit:
|
102 |
-
args = {'d': '../data/all', 'env_file': '../.env'}
|
103 |
-
|
104 |
-
# Get arguments.
|
105 |
-
data_dir = args.get('d', args.get('data_dir'))
|
106 |
-
env_file = args.get('env_file')
|
107 |
-
|
108 |
-
# Get licenses for each state.
|
109 |
-
all_licenses = main(data_dir, env_file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
analysis/figures/cannabis-licenses-map.png → all/cannabis_licenses-data.parquet
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b9df1826899c75b4124866b6386ae346b5fecfbfbdf9305d39ea04f0ea85fab1
|
3 |
+
size 972698
|
analysis/figures/cannabis-licenses-map.html
DELETED
The diff for this file is too large to render.
See raw diff
|
|
analysis/license_map.py
DELETED
@@ -1,106 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses | License Mao
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/22/2022
|
9 |
-
Updated: 10/8/2022
|
10 |
-
License: <https://github.com/cannlytics/cannabis-data-science/blob/main/LICENSE>
|
11 |
-
|
12 |
-
Description:
|
13 |
-
|
14 |
-
Map the adult-use cannabis retailers permitted in the United States:
|
15 |
-
|
16 |
-
✓ Alaska
|
17 |
-
✓ Arizona
|
18 |
-
✓ California
|
19 |
-
✓ Colorado
|
20 |
-
✓ Connecticut
|
21 |
-
✓ Illinois
|
22 |
-
✓ Maine
|
23 |
-
✓ Massachusetts
|
24 |
-
✓ Michigan
|
25 |
-
✓ Montana
|
26 |
-
✓ Nevada
|
27 |
-
✓ New Jersey
|
28 |
-
x New Mexico (FIXME)
|
29 |
-
✓ Oregon
|
30 |
-
✓ Rhode Island
|
31 |
-
✓ Vermont
|
32 |
-
✓ Washington
|
33 |
-
|
34 |
-
"""
|
35 |
-
# Standard imports.
|
36 |
-
from datetime import datetime
|
37 |
-
import json
|
38 |
-
import os
|
39 |
-
|
40 |
-
# External imports.
|
41 |
-
import folium
|
42 |
-
import pandas as pd
|
43 |
-
|
44 |
-
|
45 |
-
# Specify where your data lives.
|
46 |
-
DATA_DIR = '../'
|
47 |
-
|
48 |
-
# Read data subsets.
|
49 |
-
with open('../subsets.json', 'r') as f:
|
50 |
-
SUBSETS = json.loads(f.read())
|
51 |
-
|
52 |
-
|
53 |
-
def aggregate_retailers(
|
54 |
-
datafiles,
|
55 |
-
index_col=0,
|
56 |
-
lat='premise_latitude',
|
57 |
-
long='premise_longitude',
|
58 |
-
):
|
59 |
-
"""Aggregate retailer license data files,
|
60 |
-
keeping only those with latitude and longitude."""
|
61 |
-
data = []
|
62 |
-
for filename in datafiles:
|
63 |
-
data.append(pd.read_csv(filename, index_col=index_col))
|
64 |
-
data = pd.concat(data)
|
65 |
-
return data.loc[(~data[lat].isnull()) & (~data[long].isnull())]
|
66 |
-
|
67 |
-
|
68 |
-
def create_retailer_map(
|
69 |
-
df,
|
70 |
-
color='crimson',
|
71 |
-
filename=None,
|
72 |
-
lat='premise_latitude',
|
73 |
-
long='premise_longitude',
|
74 |
-
):
|
75 |
-
"""Create a map of licensed retailers."""
|
76 |
-
m = folium.Map(
|
77 |
-
location=[39.8283, -98.5795],
|
78 |
-
zoom_start=3,
|
79 |
-
control_scale=True,
|
80 |
-
)
|
81 |
-
for _, row in df.iterrows():
|
82 |
-
folium.Circle(
|
83 |
-
radius=5,
|
84 |
-
location=[row[lat], row[long]],
|
85 |
-
color=color,
|
86 |
-
).add_to(m)
|
87 |
-
if filename:
|
88 |
-
m.save(filename)
|
89 |
-
return m
|
90 |
-
|
91 |
-
|
92 |
-
# === Test ===
|
93 |
-
if __name__ == '__main__':
|
94 |
-
|
95 |
-
# Aggregate retailers.
|
96 |
-
subsets = list(SUBSETS.values())
|
97 |
-
datafiles = [DATA_DIR + x['data_url'] for x in subsets]
|
98 |
-
retailers = aggregate_retailers(datafiles)
|
99 |
-
|
100 |
-
# Create the retailers map.
|
101 |
-
map_file = '../analysis/figures/cannabis-licenses-map.html'
|
102 |
-
m = create_retailer_map(retailers, filename=map_file)
|
103 |
-
|
104 |
-
# Save all of the retailers.
|
105 |
-
timestamp = datetime.now().isoformat()[:19].replace(':', '-')
|
106 |
-
retailers.to_csv(f'{DATA_DIR}/data/all/licenses-{timestamp}.csv', index=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data/ct/retailers-ct-2022-10-06T18-28-33.csv → az/cannabis_licenses-data.parquet
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a20ff11117c8b5eb7f3f60b26e8056e5eca447dbf02eca4e66f91ade6e5b8735
|
3 |
+
size 38532
|
data/ak/licenses-ak-2022-10-06T17-46-29.csv → ca/cannabis_licenses-data.parquet
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f5128e0a465672917e28d0902917abeb5c5b42911eeff4001603b2f99f1e1024
|
3 |
+
size 1009853
|
cannabis_licenses.py
DELETED
@@ -1,152 +0,0 @@
|
|
1 |
-
"""
|
2 |
-
Cannabis Licenses
|
3 |
-
Copyright (c) 2022 Cannlytics
|
4 |
-
|
5 |
-
Authors:
|
6 |
-
Keegan Skeate <https://github.com/keeganskeate>
|
7 |
-
Candace O'Sullivan-Sutherland <https://github.com/candy-o>
|
8 |
-
Created: 9/29/2022
|
9 |
-
Updated: 10/8/2022
|
10 |
-
License: <https://huggingface.co/datasets/cannlytics/cannabis_licenses/blob/main/LICENSE>
|
11 |
-
"""
|
12 |
-
# Standard imports.
|
13 |
-
import json
|
14 |
-
|
15 |
-
# External imports.
|
16 |
-
import datasets
|
17 |
-
import pandas as pd
|
18 |
-
|
19 |
-
|
20 |
-
# Constants.
|
21 |
-
_SCRIPT = 'cannabis_licenses.py'
|
22 |
-
_VERSION = '1.0.0'
|
23 |
-
_HOMEPAGE = 'https://huggingface.co/datasets/cannlytics/cannabis_licenses'
|
24 |
-
_LICENSE = "https://opendatacommons.org/licenses/by/4-0/"
|
25 |
-
_DESCRIPTION = """\
|
26 |
-
Cannabis Licenses (https://cannlytics.com/data/licenses) is a
|
27 |
-
dataset of curated cannabis license data. The dataset consists of 18
|
28 |
-
sub-datasets for each state with permitted adult-use cannabis, as well
|
29 |
-
as a sub-dataset that includes all licenses.
|
30 |
-
"""
|
31 |
-
_CITATION = """\
|
32 |
-
@inproceedings{cannlytics2022cannabis_licenses,
|
33 |
-
author = {Skeate, Keegan and O'Sullivan-Sutherland, Candace},
|
34 |
-
title = {Cannabis Licenses},
|
35 |
-
booktitle = {Cannabis Data Science},
|
36 |
-
month = {October},
|
37 |
-
year = {2022},
|
38 |
-
address = {United States of America},
|
39 |
-
publisher = {Cannlytics}
|
40 |
-
}
|
41 |
-
"""
|
42 |
-
|
43 |
-
# Dataset fields.
|
44 |
-
FIELDS = datasets.Features({
|
45 |
-
'id': datasets.Value(dtype='string'),
|
46 |
-
'license_number': datasets.Value(dtype='string'),
|
47 |
-
'license_status': datasets.Value(dtype='string'),
|
48 |
-
'license_status_date': datasets.Value(dtype='string'),
|
49 |
-
'license_term': datasets.Value(dtype='string'),
|
50 |
-
'license_type': datasets.Value(dtype='string'),
|
51 |
-
'license_designation': datasets.Value(dtype='string'),
|
52 |
-
'issue_date': datasets.Value(dtype='string'),
|
53 |
-
'expiration_date': datasets.Value(dtype='string'),
|
54 |
-
'licensing_authority_id': datasets.Value(dtype='string'),
|
55 |
-
'licensing_authority': datasets.Value(dtype='string'),
|
56 |
-
'business_legal_name': datasets.Value(dtype='string'),
|
57 |
-
'business_dba_name': datasets.Value(dtype='string'),
|
58 |
-
'business_image_url': datasets.Value(dtype='string'),
|
59 |
-
'business_owner_name': datasets.Value(dtype='string'),
|
60 |
-
'business_structure': datasets.Value(dtype='string'),
|
61 |
-
'business_website': datasets.Value(dtype='string'),
|
62 |
-
'activity': datasets.Value(dtype='string'),
|
63 |
-
'premise_street_address': datasets.Value(dtype='string'),
|
64 |
-
'premise_city': datasets.Value(dtype='string'),
|
65 |
-
'premise_state': datasets.Value(dtype='string'),
|
66 |
-
'premise_county': datasets.Value(dtype='string'),
|
67 |
-
'premise_zip_code': datasets.Value(dtype='string'),
|
68 |
-
'business_email': datasets.Value(dtype='string'),
|
69 |
-
'business_phone': datasets.Value(dtype='string'),
|
70 |
-
'parcel_number': datasets.Value(dtype='string'),
|
71 |
-
'premise_latitude': datasets.Value(dtype='float'),
|
72 |
-
'premise_longitude': datasets.Value(dtype='float'),
|
73 |
-
'data_refreshed_date': datasets.Value(dtype='string'),
|
74 |
-
})
|
75 |
-
|
76 |
-
# DEV: Read subsets from local source.
|
77 |
-
# with open('subsets.json', 'r') as f:
|
78 |
-
# SUBSETS = json.loads(f.read())
|
79 |
-
|
80 |
-
# PRODUCTION: Read subsets from the official source.
|
81 |
-
import urllib.request
|
82 |
-
with urllib.request.urlopen('https://huggingface.co/datasets/cannlytics/cannabis_licenses/raw/main/subsets.json') as url:
|
83 |
-
SUBSETS = json.load(url)
|
84 |
-
|
85 |
-
|
86 |
-
class CannabisLicensesConfig(datasets.BuilderConfig):
|
87 |
-
"""BuilderConfig for Cannabis Licenses."""
|
88 |
-
|
89 |
-
def __init__(self, name, **kwargs):
|
90 |
-
"""BuilderConfig for Cannabis Licenses.
|
91 |
-
Args:
|
92 |
-
name (str): Configuration name that determines setup.
|
93 |
-
**kwargs: Keyword arguments forwarded to super.
|
94 |
-
"""
|
95 |
-
description = _DESCRIPTION
|
96 |
-
description += f'This configuration is for the `{name}` subset.'
|
97 |
-
super().__init__(name=name, description=description, **kwargs)
|
98 |
-
|
99 |
-
|
100 |
-
class CannabisLicenses(datasets.GeneratorBasedBuilder):
|
101 |
-
"""The Cannabis Licenses dataset."""
|
102 |
-
|
103 |
-
VERSION = datasets.Version(_VERSION)
|
104 |
-
BUILDER_CONFIG_CLASS = CannabisLicensesConfig
|
105 |
-
BUILDER_CONFIGS = [CannabisLicensesConfig(s) for s in SUBSETS.keys()]
|
106 |
-
DEFAULT_CONFIG_NAME = 'ca'
|
107 |
-
|
108 |
-
def _info(self):
|
109 |
-
"""Returns the dataset metadata."""
|
110 |
-
return datasets.DatasetInfo(
|
111 |
-
features=FIELDS,
|
112 |
-
supervised_keys=None,
|
113 |
-
homepage=_HOMEPAGE,
|
114 |
-
citation=_CITATION,
|
115 |
-
description=_DESCRIPTION,
|
116 |
-
license=_LICENSE,
|
117 |
-
version=_VERSION,
|
118 |
-
)
|
119 |
-
|
120 |
-
def _split_generators(self, dl_manager):
|
121 |
-
"""Returns SplitGenerators."""
|
122 |
-
config_name = self.config.name
|
123 |
-
data_url = SUBSETS[config_name]['data_url']
|
124 |
-
urls = {config_name: data_url}
|
125 |
-
downloaded_files = dl_manager.download_and_extract(urls)
|
126 |
-
filepath = downloaded_files[config_name]
|
127 |
-
params = {'filepath': filepath}
|
128 |
-
return [datasets.SplitGenerator(name='data', gen_kwargs=params)]
|
129 |
-
|
130 |
-
def _generate_examples(self, filepath):
|
131 |
-
"""Returns the examples in raw text form."""
|
132 |
-
with open(filepath) as f:
|
133 |
-
df = pd.read_csv(filepath)
|
134 |
-
for index, row in df.iterrows():
|
135 |
-
obs = row.to_dict()
|
136 |
-
yield index, obs
|
137 |
-
|
138 |
-
|
139 |
-
# === Test ===
|
140 |
-
if __name__ == '__main__':
|
141 |
-
|
142 |
-
from datasets import load_dataset
|
143 |
-
|
144 |
-
# Define all of the dataset subsets.
|
145 |
-
subsets = list(SUBSETS.keys())
|
146 |
-
|
147 |
-
# Load each dataset subset.
|
148 |
-
for subset in subsets:
|
149 |
-
dataset = load_dataset(_SCRIPT, subset)
|
150 |
-
data = dataset['data']
|
151 |
-
assert len(data) > 0
|
152 |
-
print('Read %i %s data points.' % (len(data), subset))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data/ak/retailers-ak-2022-10-06T17-46-29.csv → co/cannabis_licenses-data.parquet
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f19639952c1bd866757334effc4cc84732f855766a187db72ecbda222b52a390
|
3 |
+
size 87742
|
data/az/licenses-az-2022-10-07T10-12-07.csv → ct/cannabis_licenses-data.parquet
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d7ff4b2bd3baee5e321bf62de42aab31c345ae8c39781d1260290ac7b20f283e
|
3 |
+
size 17600
|
data/all/licenses-2022-10-06T18-46-11.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:091d343ceee078d47fa9a8c235060f8ee20a500bb3844f752cd243237aeaea0c
|
3 |
-
size 6961305
|
|
|
|
|
|
|
|
data/all/licenses-2022-10-08T14-03-08.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:75e7975601c8f9bc21918c9642dfc7ddcfbfd89427b1553ff754f0fd53d4d309
|
3 |
-
size 3192307
|
|
|
|
|
|
|
|
data/all/retailers-2022-10-07T10-20-55.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:63de8f476d9f52e9a0a1a3bf28f0fe3ad5e601bad87f5cd7b915ecda1e1c53df
|
3 |
-
size 1551940
|
|
|
|
|
|
|
|
data/ca/licenses-ca-2022-10-06T18-10-15.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:9563c185dfe5f594203bee3dceeca3e5bd130d71077a1a359281a2b6e7834e20
|
3 |
-
size 5604246
|
|
|
|
|
|
|
|
data/co/licenses-co-2022-10-06T18-28-29.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:693636fbd2b290f8a121300ac86fa6831a4741aabf2db890393c83b596a9527b
|
3 |
-
size 448918
|
|
|
|
|
|
|
|
data/co/retailers-co-2022-10-06T18-28-29.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:427f3dcfe94b5feead000d0c0e8735a21c14928a1a702f3f90cfe2dd896759a4
|
3 |
-
size 261301
|
|
|
|
|
|
|
|
data/il/retailers-il-2022-10-06T18-28-55.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:2f96d64d5efbf0103392d9c34483977c97d7c776b46cada18e7faf35807e4932
|
3 |
-
size 35040
|
|
|
|
|
|
|
|
data/ma/licenses-ma-2022-10-07T14-45-39.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:38036322058b3fc45112bca58728904a2cb9e48ade60371feb5edcdae934b8f0
|
3 |
-
size 260727
|
|
|
|
|
|
|
|
data/ma/retailers-ma-2022-10-07T14-45-39.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:f076c79fc442d8f94142c724fa20bafa4e6c02e72431da594fc3d1cf892c61e2
|
3 |
-
size 101882
|
|
|
|
|
|
|
|
data/me/licenses-me-2022-10-07T15-26-01.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:92bbfa576b32396673cdc8c95ee5e4902ebf5ff33ed6084c988882ed41fe877e
|
3 |
-
size 128972
|
|
|
|
|
|
|
|
data/mi/licenses-mi-2022-10-08T13-49-04.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:5295070f77b7a572c13de1c069428e5e71cc9dd422ad096745816c0d8fa64e1e
|
3 |
-
size 38635
|
|
|
|
|
|
|
|
data/mt/retailers-mt-2022-10-07T16-28-10.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:2b1bd3b1dfdcb846bb3b3b002e9116596e8b9869b35a0462fcdf8d82176efcc9
|
3 |
-
size 117170
|
|
|
|
|
|
|
|
data/nj/licenses-nj-2022-10-06T18-39-17.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:eeb27486bc5cfb4b8ab0568f85b2d48a5aadb77fd2f68850a4e325c8793aef64
|
3 |
-
size 5525
|
|
|
|
|
|
|
|
data/nm/retailers-nm-2022-10-05T15-09-21.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:978d2a7dab0c9e4dffdfb6e29d01974429de3cdd9887ac13893aec74790ef896
|
3 |
-
size 128187
|
|
|
|
|
|
|
|
data/nv/licenses-nv-2022-10-06T18-42-39.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:2f0c00bfd35141ca85d1fb29cf1d972124e384bf5432d8ba060ffd236bed8d4b
|
3 |
-
size 129201
|
|
|
|
|
|
|
|
data/nv/retailers-nv-2022-10-06T18-43-01.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:df8707ab150055148ae3ab65313aa73f5d1f6ccb32bc4fc20785f4c3ba9e6ece
|
3 |
-
size 22015
|
|
|
|
|
|
|
|
data/or/licenses-or-2022-10-07T14-47-55.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:99cdb82c0ceb4741110f7e425ba0c2c380ca681f63683c77937c34c5cca0ce2b
|
3 |
-
size 209474
|
|
|
|
|
|
|
|
data/ri/licenses-ri-2022-10-06T18-45-41.csv
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:303cf4840665188d577305de183ad2425b162abd7117e7ff08a9e423b2215e12
|
3 |
-
size 2029
|
|
|
|
|
|
|
|