├── .coveragerc
├── .gitignore
├── AUTHORS.txt
├── LICENSE.txt
├── MANIFEST.in
├── Pipfile
├── Pipfile.lock
├── README.md
├── code_of_conduct.md
├── create-credentials.png
├── create-new-project.png
├── docs
├── Makefile
├── conf.py
├── index.rst
├── make.bat
└── requirements.txt
├── external-user-type.png
├── google-cloud-new-project.png
├── navigate-library.png
├── pyproject.toml
├── setup.py
├── src
└── ezsheets
│ ├── __init__.py
│ └── colorvalues.py
├── tests
├── my_spreadsheet.xlsx
├── produceSales.xlsx
├── test_automate2nded.py
└── test_ezsheets.py
└── tox.ini
/.coveragerc:
--------------------------------------------------------------------------------
1 | # .coveragerc to control coverage.py
2 |
3 | # To run coverage tests, run `coverage run tests/test_ezsheets.py` then `coverage html`. The report will be in htmlconv/index.html
4 |
5 |
6 |
7 | [run]
8 |
9 |
10 |
11 | [report]
12 | # Regexes for lines to exclude from consideration
13 | exclude_lines =
14 | # Have to re-enable the standard pragma
15 | pragma: no cover
16 |
17 | # Don't complain if tests don't hit defensive assertion code:
18 | raise AssertionError
19 | raise NotImplementedError
20 |
21 | # Don't complain if non-runnable code isn't run:
22 | if 0:
23 | if __name__ == .__main__.:
24 |
25 | ignore_errors = True
26 |
27 |
28 | [html]
29 | directory = htmlcov
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # OSX useful to ignore
7 | *.DS_Store
8 | .AppleDouble
9 | .LSOverride
10 |
11 | # Thumbnails
12 | ._*
13 |
14 | # Files that might appear in the root of a volume
15 | .DocumentRevisions-V100
16 | .fseventsd
17 | .Spotlight-V100
18 | .TemporaryItems
19 | .Trashes
20 | .VolumeIcon.icns
21 | .com.apple.timemachine.donotpresent
22 |
23 | # Directories potentially created on remote AFP share
24 | .AppleDB
25 | .AppleDesktop
26 | Network Trash Folder
27 | Temporary Items
28 | .apdisk
29 |
30 | # C extensions
31 | *.so
32 |
33 | # Distribution / packaging
34 | .Python
35 | env/
36 | build/
37 | develop-eggs/
38 | dist/
39 | downloads/
40 | eggs/
41 | .eggs/
42 | lib/
43 | lib64/
44 | parts/
45 | sdist/
46 | var/
47 | *.egg-info/
48 | .installed.cfg
49 | *.egg
50 |
51 | # PyInstaller
52 | # Usually these files are written by a python script from a template
53 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
54 | *.manifest
55 | *.spec
56 |
57 | # Installer logs
58 | pip-log.txt
59 | pip-delete-this-directory.txt
60 |
61 | # Unit test / coverage reports
62 | htmlcov/
63 | .tox/
64 | .coverage
65 | .coverage.*
66 | .cache
67 | nosetests.xml
68 | coverage.xml
69 | *,cover
70 | .hypothesis/
71 | .pytest_cache/
72 |
73 | # Translations
74 | *.mo
75 | *.pot
76 |
77 | # Django stuff:
78 | *.log
79 |
80 | # Sphinx documentation
81 | docs/_build/
82 |
83 | # IntelliJ Idea family of suites
84 | .idea
85 | *.iml
86 | ## File-based project format:
87 | *.ipr
88 | *.iws
89 | ## mpeltonen/sbt-idea plugin
90 | .idea_modules/
91 |
92 | # PyBuilder
93 | target/
94 |
95 | # Cookiecutter
96 | output/
97 | python_boilerplate/
98 |
99 |
100 |
101 | credentials.json
102 | token-sheets.pickle
103 | token-drive.pickle
--------------------------------------------------------------------------------
/AUTHORS.txt:
--------------------------------------------------------------------------------
1 |
2 |
3 | Al Sweigart https://github.com/asweigart
4 | mwishoff https://github.com/mwishoff
5 | solarpete https://github.com/solarpete
6 | sreyemnayr https://github.com/sreyemnayr
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include README.md
2 |
--------------------------------------------------------------------------------
/Pipfile:
--------------------------------------------------------------------------------
1 | [[source]]
2 | name = "pypi"
3 | url = "https://pypi.org/simple"
4 | verify_ssl = true
5 |
6 | [dev-packages]
7 | pytest = "*"
8 |
9 | [packages]
10 | ezsheets = {editable = true, path = "."}
11 | pytest = "*"
12 |
13 | [requires]
14 | python_version = "3.7"
15 |
--------------------------------------------------------------------------------
/Pipfile.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_meta": {
3 | "hash": {
4 | "sha256": "f537053808304182e4c658ada95db82b6f3a9bae36323df25cc9df1671ff87d7"
5 | },
6 | "pipfile-spec": 6,
7 | "requires": {
8 | "python_version": "3.7"
9 | },
10 | "sources": [
11 | {
12 | "name": "pypi",
13 | "url": "https://pypi.org/simple",
14 | "verify_ssl": true
15 | }
16 | ]
17 | },
18 | "default": {
19 | "attrs": {
20 | "hashes": [
21 | "sha256:29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6",
22 | "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c"
23 | ],
24 | "markers": "python_version >= '3.5'",
25 | "version": "==22.1.0"
26 | },
27 | "cachetools": {
28 | "hashes": [
29 | "sha256:6a94c6402995a99c3970cc7e4884bb60b4a8639938157eeed436098bf9831757",
30 | "sha256:f9f17d2aec496a9aa6b76f53e3b614c965223c061982d434d160f930c698a9db"
31 | ],
32 | "markers": "python_version ~= '3.7'",
33 | "version": "==5.2.0"
34 | },
35 | "certifi": {
36 | "hashes": [
37 | "sha256:35824b4c3a97115964b408844d64aa14db1cc518f6562e8d7261699d1350a9e3",
38 | "sha256:4ad3232f5e926d6718ec31cfc1fcadfde020920e278684144551c91769c7bc18"
39 | ],
40 | "index": "pypi",
41 | "version": "==2022.12.7"
42 | },
43 | "charset-normalizer": {
44 | "hashes": [
45 | "sha256:5a3d016c7c547f69d6f81fb0db9449ce888b418b5b9952cc5e6e66843e9dd845",
46 | "sha256:83e9a75d1911279afd89352c68b45348559d1fc0506b054b346651b5e7fee29f"
47 | ],
48 | "markers": "python_full_version >= '3.6.0'",
49 | "version": "==2.1.1"
50 | },
51 | "ezsheets": {
52 | "editable": true,
53 | "path": "."
54 | },
55 | "google-api-core": {
56 | "hashes": [
57 | "sha256:4b9bb5d5a380a0befa0573b302651b8a9a89262c1730e37bf423cec511804c22",
58 | "sha256:ce222e27b0de0d7bc63eb043b956996d6dccab14cc3b690aaea91c9cc99dc16e"
59 | ],
60 | "markers": "python_version >= '3.7'",
61 | "version": "==2.11.0"
62 | },
63 | "google-api-python-client": {
64 | "hashes": [
65 | "sha256:19177411b7dcf8fcd66bff085c6838ecea5fd6b598998d594be1f7290dfc34b4",
66 | "sha256:d4d317ccd365118f96d8d4b6a61aaba8fd414cf1a8617cb229386f2094013cea"
67 | ],
68 | "markers": "python_version >= '3.7'",
69 | "version": "==2.68.0"
70 | },
71 | "google-auth": {
72 | "hashes": [
73 | "sha256:6897b93556d8d807ad70701bb89f000183aea366ca7ed94680828b37437a4994",
74 | "sha256:72f12a6cfc968d754d7bdab369c5c5c16032106e52d32c6dfd8484e4c01a6d1f"
75 | ],
76 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'",
77 | "version": "==2.15.0"
78 | },
79 | "google-auth-httplib2": {
80 | "hashes": [
81 | "sha256:31e49c36c6b5643b57e82617cb3e021e3e1d2df9da63af67252c02fa9c1f4a10",
82 | "sha256:a07c39fd632becacd3f07718dfd6021bf396978f03ad3ce4321d060015cc30ac"
83 | ],
84 | "version": "==0.1.0"
85 | },
86 | "googleapis-common-protos": {
87 | "hashes": [
88 | "sha256:27a849d6205838fb6cc3c1c21cb9800707a661bb21c6ce7fb13e99eb1f8a0c46",
89 | "sha256:a9f4a1d7f6d9809657b7f1316a1aa527f6664891531bcfcc13b6696e685f443c"
90 | ],
91 | "markers": "python_version >= '3.7'",
92 | "version": "==1.57.0"
93 | },
94 | "httplib2": {
95 | "hashes": [
96 | "sha256:987c8bb3eb82d3fa60c68699510a692aa2ad9c4bd4f123e51dfb1488c14cdd01",
97 | "sha256:fc144f091c7286b82bec71bdbd9b27323ba709cc612568d3000893bfd9cb4b34"
98 | ],
99 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
100 | "version": "==0.21.0"
101 | },
102 | "idna": {
103 | "hashes": [
104 | "sha256:814f528e8dead7d329833b91c5faa87d60bf71824cd12a7530b5526063d02cb4",
105 | "sha256:90b77e79eaa3eba6de819a0c442c0b4ceefc341a7a2ab77d7562bf49f425c5c2"
106 | ],
107 | "markers": "python_version >= '3.5'",
108 | "version": "==3.4"
109 | },
110 | "importlib-metadata": {
111 | "hashes": [
112 | "sha256:d5059f9f1e8e41f80e9c56c2ee58811450c31984dfa625329ffd7c0dad88a73b",
113 | "sha256:d84d17e21670ec07990e1044a99efe8d615d860fd176fc29ef5c306068fda313"
114 | ],
115 | "markers": "python_version < '3.8'",
116 | "version": "==5.1.0"
117 | },
118 | "iniconfig": {
119 | "hashes": [
120 | "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3",
121 | "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"
122 | ],
123 | "version": "==1.1.1"
124 | },
125 | "oauth2client": {
126 | "hashes": [
127 | "sha256:b8a81cc5d60e2d364f0b1b98f958dbd472887acaf1a5b05e21c28c31a2d6d3ac",
128 | "sha256:d486741e451287f69568a4d26d70d9acd73a2bbfa275746c535b4209891cccc6"
129 | ],
130 | "version": "==4.1.3"
131 | },
132 | "packaging": {
133 | "hashes": [
134 | "sha256:2198ec20bd4c017b8f9717e00f0c8714076fc2fd93816750ab48e2c41de2cfd3",
135 | "sha256:957e2148ba0e1a3b282772e791ef1d8083648bc131c8ab0c1feba110ce1146c3"
136 | ],
137 | "markers": "python_version >= '3.7'",
138 | "version": "==22.0"
139 | },
140 | "pluggy": {
141 | "hashes": [
142 | "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0",
143 | "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"
144 | ],
145 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
146 | "version": "==0.13.1"
147 | },
148 | "protobuf": {
149 | "hashes": [
150 | "sha256:25266bf373ee06d5d66f9eb1ec9d434b243dccce5c32faf151054cfa6f9dcbf1",
151 | "sha256:260e346927fd4e6fbb49ab545137b19610c24a1d853dc5f29ddf777ab1987211",
152 | "sha256:2c6a4d13732d9b094db31b3841986c38b17ac61a3fe05ee26a779d94c4c3fb43",
153 | "sha256:4922e3320ed70e81f05060822da36923d09fd9e04e17f411f2d8d8d0070f9f5c",
154 | "sha256:4b75c947289a2e9c1f37d21c593f1ef6fb4fed33977dfb2ac84f799eb29a8ff4",
155 | "sha256:4d01ef83517c181d60ea1c6d0b2f644be250ade740d6554a2f5a021b1ad622e3",
156 | "sha256:553e35c0878f6855e55f01a14561e6bce6df79b6636a5acf83b9d9ac7eab7922",
157 | "sha256:85ccb4753ee21de7dc81a7a68a051f25dbe133ffa01a639ac998427d0b223387",
158 | "sha256:a5a14b907a191319e7a58b38c583bbf50deb21e002f723a912c5e4f6969a778e",
159 | "sha256:a944dc9550baae276afc7dc8193191d4c2ad660270a1e5ed5a71539817ebe2e2",
160 | "sha256:bab4b21a986ded225b9392c07ce21c35d790951f51e1ebfd32e4d443b05c3726",
161 | "sha256:c3b9e329b4c247dc3ba5c50f60915a84e08278eb6d9e3fa674d0d04ff816bfd7",
162 | "sha256:d91a47c77b33580024b0271b65bb820c4e0264c25eb49151ad01e691de8fa0b6",
163 | "sha256:efb16b16fd3eef25357f84d516062753014b76279ce4e0ec4880badd2fba7370"
164 | ],
165 | "markers": "python_version >= '3.7'",
166 | "version": "==4.21.11"
167 | },
168 | "py": {
169 | "hashes": [
170 | "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719",
171 | "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"
172 | ],
173 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
174 | "version": "==1.11.0"
175 | },
176 | "pyasn1": {
177 | "hashes": [
178 | "sha256:014c0e9976956a08139dc0712ae195324a75e142284d5f87f1a87ee1b068a359",
179 | "sha256:03840c999ba71680a131cfaee6fab142e1ed9bbd9c693e285cc6aca0d555e576",
180 | "sha256:0458773cfe65b153891ac249bcf1b5f8f320b7c2ce462151f8fa74de8934becf",
181 | "sha256:08c3c53b75eaa48d71cf8c710312316392ed40899cb34710d092e96745a358b7",
182 | "sha256:39c7e2ec30515947ff4e87fb6f456dfc6e84857d34be479c9d4a4ba4bf46aa5d",
183 | "sha256:5c9414dcfede6e441f7e8f81b43b34e834731003427e5b09e4e00e3172a10f00",
184 | "sha256:6e7545f1a61025a4e58bb336952c5061697da694db1cae97b116e9c46abcf7c8",
185 | "sha256:78fa6da68ed2727915c4767bb386ab32cdba863caa7dbe473eaae45f9959da86",
186 | "sha256:7ab8a544af125fb704feadb008c99a88805126fb525280b2270bb25cc1d78a12",
187 | "sha256:99fcc3c8d804d1bc6d9a099921e39d827026409a58f2a720dcdb89374ea0c776",
188 | "sha256:aef77c9fb94a3ac588e87841208bdec464471d9871bd5050a287cc9a475cd0ba",
189 | "sha256:e89bf84b5437b532b0803ba5c9a5e054d21fec423a89952a74f87fa2c9b7bce2",
190 | "sha256:fec3e9d8e36808a28efb59b489e4528c10ad0f480e57dcc32b4de5c9d8c9fdf3"
191 | ],
192 | "version": "==0.4.8"
193 | },
194 | "pyasn1-modules": {
195 | "hashes": [
196 | "sha256:0845a5582f6a02bb3e1bde9ecfc4bfcae6ec3210dd270522fee602365430c3f8",
197 | "sha256:0fe1b68d1e486a1ed5473f1302bd991c1611d319bba158e98b106ff86e1d7199",
198 | "sha256:15b7c67fabc7fc240d87fb9aabf999cf82311a6d6fb2c70d00d3d0604878c811",
199 | "sha256:426edb7a5e8879f1ec54a1864f16b882c2837bfd06eee62f2c982315ee2473ed",
200 | "sha256:65cebbaffc913f4fe9e4808735c95ea22d7a7775646ab690518c056784bc21b4",
201 | "sha256:905f84c712230b2c592c19470d3ca8d552de726050d1d1716282a1f6146be65e",
202 | "sha256:a50b808ffeb97cb3601dd25981f6b016cbb3d31fbf57a8b8a87428e6158d0c74",
203 | "sha256:a99324196732f53093a84c4369c996713eb8c89d360a496b599fb1a9c47fc3eb",
204 | "sha256:b80486a6c77252ea3a3e9b1e360bc9cf28eaac41263d173c032581ad2f20fe45",
205 | "sha256:c29a5e5cc7a3f05926aff34e097e84f8589cd790ce0ed41b67aed6857b26aafd",
206 | "sha256:cbac4bc38d117f2a49aeedec4407d23e8866ea4ac27ff2cf7fb3e5b570df19e0",
207 | "sha256:f39edd8c4ecaa4556e989147ebf219227e2cd2e8a43c7e7fcb1f1c18c5fd6a3d",
208 | "sha256:fe0644d9ab041506b62782e92b06b8c68cca799e1a9636ec398675459e031405"
209 | ],
210 | "version": "==0.2.8"
211 | },
212 | "pyparsing": {
213 | "hashes": [
214 | "sha256:2b020ecf7d21b687f219b71ecad3631f644a47f01403fa1d1036b0c6416d70fb",
215 | "sha256:5026bae9a10eeaefb61dab2f09052b9f4307d44aee4eda64b309723d8d206bbc"
216 | ],
217 | "markers": "python_version >= '3.1'",
218 | "version": "==3.0.9"
219 | },
220 | "pytest": {
221 | "hashes": [
222 | "sha256:7a8190790c17d79a11f847fba0b004ee9a8122582ebff4729a082c109e81a4c9",
223 | "sha256:8f593023c1a0f916110285b6efd7f99db07d59546e3d8c36fc60e2ab05d3be92"
224 | ],
225 | "index": "pypi",
226 | "version": "==6.1.1"
227 | },
228 | "requests": {
229 | "hashes": [
230 | "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983",
231 | "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"
232 | ],
233 | "markers": "python_version >= '3.7' and python_version < '4'",
234 | "version": "==2.28.1"
235 | },
236 | "rsa": {
237 | "hashes": [
238 | "sha256:90260d9058e514786967344d0ef75fa8727eed8a7d2e43ce9f4bcf1b536174f7",
239 | "sha256:e38464a49c6c85d7f1351b0126661487a7e0a14a50f1675ec50eb34d4f20ef21"
240 | ],
241 | "markers": "python_version < '4' and python_full_version >= '3.6.0'",
242 | "version": "==4.9"
243 | },
244 | "sanitized-package": {
245 | "editable": true,
246 | "path": "."
247 | },
248 | "six": {
249 | "hashes": [
250 | "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926",
251 | "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"
252 | ],
253 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
254 | "version": "==1.16.0"
255 | },
256 | "toml": {
257 | "hashes": [
258 | "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
259 | "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"
260 | ],
261 | "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
262 | "version": "==0.10.2"
263 | },
264 | "typing-extensions": {
265 | "hashes": [
266 | "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa",
267 | "sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e"
268 | ],
269 | "markers": "python_version < '3.8'",
270 | "version": "==4.4.0"
271 | },
272 | "uritemplate": {
273 | "hashes": [
274 | "sha256:4346edfc5c3b79f694bccd6d6099a322bbeb628dbf2cd86eea55a456ce5124f0",
275 | "sha256:830c08b8d99bdd312ea4ead05994a38e8936266f84b9a7878232db50b044e02e"
276 | ],
277 | "markers": "python_full_version >= '3.6.0'",
278 | "version": "==4.1.1"
279 | },
280 | "urllib3": {
281 | "hashes": [
282 | "sha256:47cc05d99aaa09c9e72ed5809b60e7ba354e64b59c9c173ac3018642d8bb41fc",
283 | "sha256:c083dd0dce68dbfbe1129d5271cb90f9447dea7d52097c6e0126120c521ddea8"
284 | ],
285 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4, 3.5'",
286 | "version": "==1.26.13"
287 | },
288 | "zipp": {
289 | "hashes": [
290 | "sha256:83a28fcb75844b5c0cdaf5aa4003c2d728c77e05f5aeabe8e95e56727005fbaa",
291 | "sha256:a7a22e05929290a67401440b39690ae6563279bced5f314609d9d03798f56766"
292 | ],
293 | "markers": "python_version >= '3.7'",
294 | "version": "==3.11.0"
295 | }
296 | },
297 | "develop": {
298 | "attrs": {
299 | "hashes": [
300 | "sha256:29adc2665447e5191d0e7c568fde78b21f9672d344281d0c6e1ab085429b22b6",
301 | "sha256:86efa402f67bf2df34f51a335487cf46b1ec130d02b8d39fd248abfd30da551c"
302 | ],
303 | "markers": "python_version >= '3.5'",
304 | "version": "==22.1.0"
305 | },
306 | "importlib-metadata": {
307 | "hashes": [
308 | "sha256:d5059f9f1e8e41f80e9c56c2ee58811450c31984dfa625329ffd7c0dad88a73b",
309 | "sha256:d84d17e21670ec07990e1044a99efe8d615d860fd176fc29ef5c306068fda313"
310 | ],
311 | "markers": "python_version < '3.8'",
312 | "version": "==5.1.0"
313 | },
314 | "iniconfig": {
315 | "hashes": [
316 | "sha256:011e24c64b7f47f6ebd835bb12a743f2fbe9a26d4cecaa7f53bc4f35ee9da8b3",
317 | "sha256:bc3af051d7d14b2ee5ef9969666def0cd1a000e121eaea580d4a313df4b37f32"
318 | ],
319 | "version": "==1.1.1"
320 | },
321 | "packaging": {
322 | "hashes": [
323 | "sha256:2198ec20bd4c017b8f9717e00f0c8714076fc2fd93816750ab48e2c41de2cfd3",
324 | "sha256:957e2148ba0e1a3b282772e791ef1d8083648bc131c8ab0c1feba110ce1146c3"
325 | ],
326 | "markers": "python_version >= '3.7'",
327 | "version": "==22.0"
328 | },
329 | "pluggy": {
330 | "hashes": [
331 | "sha256:15b2acde666561e1298d71b523007ed7364de07029219b604cf808bfa1c765b0",
332 | "sha256:966c145cd83c96502c3c3868f50408687b38434af77734af1e9ca461a4081d2d"
333 | ],
334 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'",
335 | "version": "==0.13.1"
336 | },
337 | "py": {
338 | "hashes": [
339 | "sha256:51c75c4126074b472f746a24399ad32f6053d1b34b68d2fa41e558e6f4a98719",
340 | "sha256:607c53218732647dff4acdfcd50cb62615cedf612e72d1724fb1a0cc6405b378"
341 | ],
342 | "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4'",
343 | "version": "==1.11.0"
344 | },
345 | "pytest": {
346 | "hashes": [
347 | "sha256:7a8190790c17d79a11f847fba0b004ee9a8122582ebff4729a082c109e81a4c9",
348 | "sha256:8f593023c1a0f916110285b6efd7f99db07d59546e3d8c36fc60e2ab05d3be92"
349 | ],
350 | "index": "pypi",
351 | "version": "==6.1.1"
352 | },
353 | "toml": {
354 | "hashes": [
355 | "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b",
356 | "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"
357 | ],
358 | "markers": "python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3'",
359 | "version": "==0.10.2"
360 | },
361 | "typing-extensions": {
362 | "hashes": [
363 | "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa",
364 | "sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e"
365 | ],
366 | "markers": "python_version < '3.8'",
367 | "version": "==4.4.0"
368 | },
369 | "zipp": {
370 | "hashes": [
371 | "sha256:83a28fcb75844b5c0cdaf5aa4003c2d728c77e05f5aeabe8e95e56727005fbaa",
372 | "sha256:a7a22e05929290a67401440b39690ae6563279bced5f314609d9d03798f56766"
373 | ],
374 | "markers": "python_version >= '3.7'",
375 | "version": "==3.11.0"
376 | }
377 | }
378 | }
379 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # EZSheets
2 |
3 |
4 | A Pythonic interface to the Google Sheets API that actually works as of July 2024.
5 |
6 | ## Installation and Setup
7 |
8 | To install with pip, run:
9 |
10 | pip install ezsheets
11 |
12 | For your Python script to use EZSheets to access and edit your Google Sheets spreadsheets, you need a credentials JSON file and a token JSON file. If you have a Google/Gmail account, you can do this and it is free. I strongly recommend creating a new Google account instead of using your existing one, to prevent a bug in your Python script from affecting the spreadsheets in your personal Google account. There are five parts to creating credentials:
13 |
14 | 1. Create a new Google Cloud project.
15 | 2. Enable the Google Sheets API and Google Drive API for your project.
16 | 3. Configure the OAuth Consent Screen for your project.
17 | 4. Create credentials for your project.
18 | 5. Log in with the credentials file.
19 |
20 | This may seem like a lot of work, but you only have to perform this setup once.
21 |
22 | ### Create a new Google Cloud Project
23 |
24 | First, you need to set up a Google Cloud project. In your browser, go to https://console.cloud.google.com and sign in to your Google account with your username and password. (Your app can connect to any Google account, but this Google account will manage the Google API access for EZSheets.) You will be taken to a Getting Started page. At the top of the page, click on "Select a project". In the pop-up window that appears, click "New Project".
25 |
26 | 
27 |
28 | This takes you to a new project page. A Project Name like "My Project 23135" will be generated for you. There is also a Project ID like "macro-nuance-362516" randomly generated for you. These names won't be visible to users of your Python scripts and you can use whatever name you want. You can change the Project Name later but not the Project ID. I just use the default names that the website generates for me. You can leave the Location as "No organization". Free Google accounts can have up to 12 projects but you only need one project for all the Python scripts that you want to create. Click the blue "CREATE" button to create the project.
29 |
30 | 
31 |
32 |
33 |
34 | Click on "Select a project" at the top of the page again, and select the project you just created. You will be taken to the dashboard page for this Google Cloud Project. Next, you need to enable the Google Sheets API and Google Drive API for your project.
35 |
36 | ### Enable the Google Sheets API and Google Drive API for Your Project
37 |
38 | On the https://console.cloud.google.com page, click on the Navigation button in the upper left (the icon is three horizontal stripes, often called the "hamburger" icon.) Navigate to "APIs & Services" and then "Library" to go to the API Library page. There are many Google APIs for Gmail, Google Maps, Google Cloud Storage, and other Google services. We need to allow our project to use the Google Sheets and Google Drive APIs.
39 |
40 | 
41 |
42 | Scroll down and find the "Google Sheets API" and click it, or enter "Google Sheets API" into the search bar to find it. This takes you to the Google Sheets API page. Click the blue "ENABLE" button to enable your Google Cloud project to use the Google Sheets API. You'll be redirected to the "APIs & Services > Enabled APIs & Services" page where you can find information about how often your Python scripts are using this API. Repeat this for the "Google Drive API" to enable it as well.
43 |
44 | Next, you need to configure your project's OAuth Consent Screen.
45 |
46 | ### Configure the OAuth Consent Screen for Your Project
47 |
48 | Click on the Navigation button in the upper left and then navigate to "APIs & Services" and then "OAuth Consent Screen." The consent screen will appear the first time when you or users of your Python script use EZSheets. With a free Google account that is not set up as a Google Workspace user, you'll have to select the External User Type option instead of Internal User Type. These are further explained on Google's [Setting up your OAuth consent screen help page](https://support.google.com/cloud/answer/10311615).
49 |
50 | On Step 1 "OAuth consent screen", select External and click the blue "CREATE" button. The next page shows what the OAuth consent screen looks like. This screen appears to the user when they first import the ezsheets module. Pick a name for App Name (I use something generic like Python Google API Script) and enter your email address for the User Support Email and Developer Contact Information. Then click the "SAVE AND CONTINUE" button.
51 |
52 | On Step 2 "Scopes", your projects' scopes are the permissions for what the project is allowed to access. Click the "ADD OR REMOVE SCOPES" button, and in the new panel that appears, go through the table and check the checkboxes for the scopes `.../auth/drive` (Google Drive API) and `.../auth/spreadsheets` (Google Sheets API) and click the blue "UPDATE" button. Then click "SAVE AND CONTINUE."
53 |
54 | Step 3 "Test users" requires you to add the Gmail email addresses of the Google accounts that own the spreadsheets your Python script will interact with. Without going through Google's app approval process, your scripts are limited to interacting with the email addresses you provide in this step. Click the "+ ADD USERS" button and in the new panel that appears, enter the Gmail address of your Google account and click the blue "ADD" button. Then click "SAVE AND CONTINUE."
55 |
56 | Step 4 "Summary" provides a summary of the previous steps. If all the information looks right, click the "BACK TO DASHBOARD" button. The next step is to create credentials for your project.
57 |
58 | ### Create Credentials for Your Project
59 |
60 | From the Navigation sidebar menu, click on "APIs & Services" and then "Credentials" to go to the Credentials page. Click the "+ CREATE CREDENTIALS" link at the top of the page. A submenu will open asking what kind of credentials you want to create: "API key", "OAuth client ID", or "Service account". Click on "OAuth client ID".
61 |
62 | 
63 |
64 | On the new page that appears, select "Desktop app" for the "Application type" and leave "Name" as the default "Desktop client 1." (You can change this to a different name if you want, it doesn't appear to the users of your Python script.) Click the blue "CREATE" button.
65 |
66 | On the pop up that appears, click "DOWNLOAD JSON" to download the credentials file. This credentials JSON file will have a name like *client_secret_282792235794-p2o9gfcub4htibfg2u207gcomco9nqm7.apps.googleusercontent.com.json*. Place it in the same folder that your Python script will be in.
67 |
68 | ### Log In with the Credentials File
69 |
70 | Run the Python interactive shell from the same folder that the credentials JSON file is in and run `import ezsheets`. Or, place a *.py* Python program in this folder and have it run `import ezsheets`. EZSheets will load and automatically check this folder for a credentials JSON file and, if found, launches your web browser to the OAuth consent screen. Sign in with the Google account you want to access from your Python script. This must be the same email address that you gave for the "test user" when configuring the Google Cloud project's OAuth consent screen.
71 |
72 | You will get a warning message that reads "Google hasn't verified this app," but that's fine because this is the app (or project) that you've just created yourself. Click the Continue link. You'll come to another page that says "Python Google API Script wants access to your Google Account" (or whatever name you gave in the OAuth consent screen setup.) Click Continue.
73 |
74 | You'll come to a plain web page that says, "The authentication flow has completed." You can now close the browser window. In the same folder as your credentials JSON file, you'll now see a *token-drive.pickle* and *token-sheets.pickle* file. Treat these files like passwords and do not share them: they can be used to log in and access your Google Sheets spreadsheets.
75 |
76 | ## Quickstart Guide
77 |
78 | After you've set up your credentials and token files, you can import EZSheets to access your Google Sheets. Create a `Spreadsheet` object by using the Spreadsheet's URL:
79 |
80 | >>> import ezsheets
81 | >>> s = ezsheets.Spreadsheet('https://docs.google.com/spreadsheets/d/16RWH9XBBwd8pRYZDSo9EontzdVPqxdGnwM5MnP6T48c/edit#gid=0')
82 |
83 | You can also just provide the spreadsheet ID part of the URL:
84 |
85 | >>> s = ezsheets.Spreadsheet('16RWH9XBBwd8pRYZDSo9EontzdVPqxdGnwM5MnP6T48c')
86 |
87 | `Spreadsheet` objects have a `title` and `spreadsheetId` attributes:
88 |
89 | >>> s.title
90 | 'Class Data Example'
91 | >>> s.title = 'Class Data'
92 | >>> s.title
93 | 'Class Data'
94 | >>> s.spreadsheetId
95 | '16RWH9XBBwd8pRYZDSo9EontzdVPqxdGnwM5MnP6T48c'
96 |
97 | `Spreadsheet` objects also have a `sheets` attribute, which is a list of `Sheet` objects:
98 |
99 | >>> s.sheets
100 | (Sheet(title='Sheet3', sheetId=314007586, rowCount=1000, columnCount=26), Sheet(title='Foobar', sheetId=2075929783, rowCount=1000, columnCount=27), Sheet(title='Class Data', sheetId=0, rowCount=101, columnCount=22, frozenRowCount=1), Sheet(title='Sheet2', sheetId=880141843, rowCount=1000, columnCount=26))
101 | >>> s.sheetTitles
102 | ('Sheet3', 'Foobar', 'Class Data', 'Sheet2')
103 | >>> sh = s.sheets[0]
104 |
105 | You can then view the size and title of a sheet:
106 |
107 | >>> sh = s.sheets[0]
108 | >>> sh.title
109 | 'Sheet3'
110 | >>> sh.title = 'My New Title'
111 | >>> sh.title
112 | 'My New Title'
113 | >>> sh.columnCount, sh.rowCount
114 | (26, 1000)
115 |
116 | You can also get or update data in a specific cell, row, or column:
117 |
118 | >>> sh.get(1,1)
119 | 'fads'
120 | >>> sh.update(1, 1, 'New cell value')
121 | >>> sh.getRow(1)
122 | ['New cell value', 'fe', 'fa', 'ewafwe', 'f', 'ew', 'ewafawef', 'ewf', 'ewf', 'ew', 'fewa', 'f', 'ew', '', '', '', '', '', '', 'ewf', 'ewafewaf', 'ewfewf', '', 'f', 'ewfewafewaf', 'ewfew']
123 | >>> sh.updateRow(['cell A', 'cell B', 'cell C'])
124 | Traceback (most recent call last):
125 | File "", line 1, in
126 | TypeError: updateRow() missing 1 required positional argument: 'values'
127 | >>> sh.updateRow(1, ['cell A', 'cell B', 'cell C'])
128 | >>> sh.getColumn(1)
129 | ['cell A']
130 | >>> sh.update(1, 2, 'another value')
131 | >>> sh.getColumn(1)
132 | ['cell A', 'another value']
133 | >>> sh.updateAll([['CELL A', 'ANOTHER VALUE', 'CELL C'], ['ANOTHER VALUE']])
134 | >>> sh.getRows()
135 | [['CELL A', 'ANOTHER VALUE', 'CELL C'], ['ANOTHER VALUE']]
136 |
137 | If the data on the Google Sheet changes, you can refresh your local copy of the data:
138 |
139 | >>> sh.refresh() # Updates the Sheet object.
140 | >>> s.refresh() # Updates the Spreadsheet object and all its sheets.
141 |
142 | You can rearrange the order of the sheets in the spreadsheet:
143 |
144 | >>> s.sheetTitles
145 | ('My New Title', 'Foobar', 'Class Data', 'Sheet2')
146 | >>> s.sheets[0].index
147 | 0
148 | >>> s.sheets[0].index = 2
149 | >>> s.sheetTitles
150 | ('Foobar', 'Class Data', 'My New Title', 'Sheet2')
151 | >>> s.sheets[2].index = 0
152 | >>> s.sheetTitles
153 | ('My New Title', 'Foobar', 'Class Data', 'Sheet2')
154 |
155 | You can recolor the tabs as well. (Currently you can't reset the tab color back to no color.)
156 |
157 |
158 |
159 | ## Contribute
160 |
161 | If you'd like to contribute to EZSheets, check out https://github.com/asweigart/ezsheets
162 |
163 | ## Support
164 |
165 | If you find this project helpful and would like to support its development, [consider donating to its creator on Patreon](https://www.patreon.com/AlSweigart).
166 |
--------------------------------------------------------------------------------
/code_of_conduct.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, gender identity and expression, level of experience,
9 | nationality, personal appearance, race, religion, or sexual identity and
10 | orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team.
59 |
60 | All complaints will be reviewed and investigated and will result in a response that
61 | is deemed necessary and appropriate to the circumstances. The project team is
62 | obligated to maintain confidentiality with regard to the reporter of an incident.
63 | Further details of specific enforcement policies may be posted separately.
64 |
65 | Project maintainers who do not follow or enforce the Code of Conduct in good
66 | faith may face temporary or permanent repercussions as determined by other
67 | members of the project's leadership.
68 |
69 | ## Attribution
70 |
71 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
72 | available at [http://contributor-covenant.org/version/1/4][version]
73 |
74 | [homepage]: http://contributor-covenant.org
75 | [version]: http://contributor-covenant.org/version/1/4/
--------------------------------------------------------------------------------
/create-credentials.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asweigart/ezsheets/58d32e8e7c35694ba6ef2f89612b6d0ae198df24/create-credentials.png
--------------------------------------------------------------------------------
/create-new-project.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asweigart/ezsheets/58d32e8e7c35694ba6ef2f89612b6d0ae198df24/create-new-project.png
--------------------------------------------------------------------------------
/docs/Makefile:
--------------------------------------------------------------------------------
1 | # Minimal makefile for Sphinx documentation
2 | #
3 |
4 | # You can set these variables from the command line.
5 | SPHINXOPTS =
6 | SPHINXBUILD = sphinx-build
7 | SOURCEDIR = .
8 | BUILDDIR = _build
9 |
10 | # Put it first so that "make" without argument is like "make help".
11 | help:
12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
13 |
14 | .PHONY: help Makefile
15 |
16 | # Catch-all target: route all unknown targets to Sphinx using the new
17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
18 | %: Makefile
19 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
--------------------------------------------------------------------------------
/docs/conf.py:
--------------------------------------------------------------------------------
1 | # -*- coding: utf-8 -*-
2 | #
3 | # Configuration file for the Sphinx documentation builder.
4 | #
5 | # This file does only contain a selection of the most common options. For a
6 | # full list see the documentation:
7 | # http://www.sphinx-doc.org/en/master/config
8 |
9 | # -- Path setup --------------------------------------------------------------
10 |
11 | # If extensions (or modules to document with autodoc) are in another directory,
12 | # add these directories to sys.path here. If the directory is relative to the
13 | # documentation root, use os.path.abspath to make it absolute, like shown here.
14 | #
15 | import os
16 | import sys
17 | sys.path.insert(0, os.path.abspath('../ezsheets'))
18 |
19 |
20 | # -- Project information -----------------------------------------------------
21 |
22 | project = 'EZSheets'
23 | copyright = '2018-2019, Al Sweigart'
24 | author = 'Al Sweigart'
25 |
26 | # The short X.Y version
27 | version = ''
28 | # The full version, including alpha/beta/rc tags
29 | release = ''
30 |
31 |
32 | # -- General configuration ---------------------------------------------------
33 |
34 | # If your documentation needs a minimal Sphinx version, state it here.
35 | #
36 | # needs_sphinx = '1.0'
37 |
38 | # Add any Sphinx extension module names here, as strings. They can be
39 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
40 | # ones.
41 | extensions = [
42 | 'sphinx.ext.autodoc',
43 | 'sphinx.ext.doctest',
44 | 'sphinx.ext.coverage',
45 | ]
46 |
47 | # Add any paths that contain templates here, relative to this directory.
48 | templates_path = ['_templates']
49 |
50 | # The suffix(es) of source filenames.
51 | # You can specify multiple suffix as a list of string:
52 | #
53 | # source_suffix = ['.rst', '.md']
54 | source_suffix = '.rst'
55 |
56 | # The master toctree document.
57 | master_doc = 'index'
58 |
59 | # The language for content autogenerated by Sphinx. Refer to documentation
60 | # for a list of supported languages.
61 | #
62 | # This is also used if you do content translation via gettext catalogs.
63 | # Usually you set "language" from the command line for these cases.
64 | language = None
65 |
66 | # List of patterns, relative to source directory, that match files and
67 | # directories to ignore when looking for source files.
68 | # This pattern also affects html_static_path and html_extra_path.
69 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
70 |
71 | # The name of the Pygments (syntax highlighting) style to use.
72 | pygments_style = None
73 |
74 |
75 | # -- Options for HTML output -------------------------------------------------
76 |
77 | # The theme to use for HTML and HTML Help pages. See the documentation for
78 | # a list of builtin themes.
79 | #
80 | html_theme = 'sphinx_rtd_theme'
81 |
82 | # Theme options are theme-specific and customize the look and feel of a theme
83 | # further. For a list of options available for each theme, see the
84 | # documentation.
85 | #
86 | # html_theme_options = {}
87 |
88 | # Add any paths that contain custom static files (such as style sheets) here,
89 | # relative to this directory. They are copied after the builtin static files,
90 | # so a file named "default.css" will overwrite the builtin "default.css".
91 | html_static_path = ['_static']
92 |
93 | # Custom sidebar templates, must be a dictionary that maps document names
94 | # to template names.
95 | #
96 | # The default sidebars (for documents that don't match any pattern) are
97 | # defined by theme itself. Builtin themes are using these templates by
98 | # default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
99 | # 'searchbox.html']``.
100 | #
101 | # html_sidebars = {}
102 |
103 |
104 | # -- Options for HTMLHelp output ---------------------------------------------
105 |
106 | # Output file base name for HTML help builder.
107 | htmlhelp_basename = 'ezsheetsdoc'
108 |
109 |
110 | # -- Options for LaTeX output ------------------------------------------------
111 |
112 | latex_elements = {
113 | # The paper size ('letterpaper' or 'a4paper').
114 | #
115 | # 'papersize': 'letterpaper',
116 |
117 | # The font size ('10pt', '11pt' or '12pt').
118 | #
119 | # 'pointsize': '10pt',
120 |
121 | # Additional stuff for the LaTeX preamble.
122 | #
123 | # 'preamble': '',
124 |
125 | # Latex figure (float) alignment
126 | #
127 | # 'figure_align': 'htbp',
128 | }
129 |
130 | # Grouping the document tree into LaTeX files. List of tuples
131 | # (source start file, target name, title,
132 | # author, documentclass [howto, manual, or own class]).
133 | latex_documents = [
134 | (master_doc, 'ezsheets.tex', 'EZSheets Documentation',
135 | 'Al Sweigart', 'manual'),
136 | ]
137 |
138 |
139 | # -- Options for manual page output ------------------------------------------
140 |
141 | # One entry per manual page. List of tuples
142 | # (source start file, name, description, authors, manual section).
143 | man_pages = [
144 | (master_doc, 'ezsheets', 'EZSheets Documentation',
145 | [author], 1)
146 | ]
147 |
148 |
149 | # -- Options for Texinfo output ----------------------------------------------
150 |
151 | # Grouping the document tree into Texinfo files. List of tuples
152 | # (source start file, target name, title, author,
153 | # dir menu entry, description, category)
154 | texinfo_documents = [
155 | (master_doc, 'ezsheets', 'EZSheets Documentation',
156 | author, 'EZSheets', 'A Pythonic interface to the Google Sheets API that actually works as of Feb 2019.',
157 | 'Miscellaneous'),
158 | ]
159 |
160 |
161 | # -- Options for Epub output -------------------------------------------------
162 |
163 | # Bibliographic Dublin Core info.
164 | epub_title = project
165 |
166 | # The unique identifier of the text. This can be a ISBN number
167 | # or the project homepage.
168 | #
169 | # epub_identifier = ''
170 |
171 | # A unique identification for the text.
172 | #
173 | # epub_uid = ''
174 |
175 | # A list of files that should not be packed into the epub file.
176 | epub_exclude_files = ['search.html']
177 |
178 |
179 | # -- Extension configuration -------------------------------------------------
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | EZSheets
2 | ========
3 |
4 | A Pythonic interface to the Google Sheets API that actually works as of November 2019.
5 |
6 |
7 | Installation
8 | ------------
9 |
10 | EZSheets can be installed from PyPI using `pip`:
11 |
12 | ``pip install ezsheets``
13 |
14 | On macOS and Linux, installing EZSheets for Python 3 is done with `pip3`:
15 |
16 | ``pip3 install ezsheets``
17 |
18 | If you run into permissions errors, try installing with the `--user` option:
19 |
20 | ``pip install --user ezsheets``
21 |
22 | Before you can use EZSheets, you need to enable the Google Sheets and
23 | Google Drive APIs for your Google account. Visit the following web pages
24 | and click the Enable API buttons at the top of each:
25 |
26 | * https://console.developers.google.com/apis/library/sheets.googleapis.com/
27 | * https://console.developers.google.com/apis/library/drive.googleapis.com/
28 |
29 | You'll also need to obtain three files, which you should save in the same
30 | folder as your .py Python script that uses EZSheets:
31 |
32 | * A credentials file named credentials-sheets.json
33 | * A token for Google Sheets named token-sheets.pickle
34 | * A token for Google Drive named token-drive.pickle
35 |
36 | The credentials file will generate the token files. The easiest way to
37 | obtain a credentials file is to go to the Google Sheets Python Quickstart
38 | page at https://developers.google.com/sheets/api/quickstart/python/ and click the
39 | blue **Enable the Google Sheets API** button. You'll
40 | need to log in to your Google account to view this page.
41 |
42 | Clicking this button will bring up a window with a **Download Client
43 | Configuration** link that lets you download a *credentials.json* file. Rename
44 | this file to *credentials-sheets.json* and place it in the same folder as your
45 | Python scripts.
46 |
47 | Once you have a *credentials-sheets.json* file, run the import ezsheets module.
48 | The first time you import the EZSheets module, it will open a new
49 | browser window for you to log in to your Google account. Click **Allow**.
50 |
51 | The message about Quickstart comes from the fact that you downloaded
52 | the credentials file from the Google Sheets Python Quickstart page.
53 | Note that this window will open twice: first for Google Sheets access and second
54 | for Google Drive access. EZSheets uses Google Drive access to upload,
55 | download, and delete spreadsheets.
56 |
57 | After you log in, the browser window will prompt you to close it, and
58 | the *token-sheets.pickle* and *token-drive.pickle* files will appear in the same folder
59 | as *credentials-sheets.json*. You only need to go through this process the first
60 | time you run ``import ezsheets``.
61 |
62 | If you encounter an error after clicking **Allow** and the page seems to
63 | hang, make sure you have first enabled the Google Sheets and Drive APIs
64 | from the links at the start of this section. It may take a few minutes for
65 | Google's servers to register this change, so you may have to wait before
66 | you can use EZSheets.
67 |
68 | Don't share the credential or token files with anyone: treat them
69 | like passwords.
70 |
71 |
72 | Quickstart
73 | ----------
74 |
75 | .. code-block:: none
76 |
77 | >>> import ezsheets
78 |
79 | >>> ss = ezsheets.createSpreadsheet(title='My New Spreadsheet')
80 |
81 | >>> ss.sheetTitles
82 | ('Sheet1',)
83 |
84 | >>> ss.sheets
85 | (Sheet(sheetId=0, title='Sheet1', rowCount=1000, columnCount=26),)
86 |
87 | >>> sh = ss.sheets[0]
88 | >>> sh.title
89 | 'Sheet1'
90 |
91 | >>> sh.updateRow(1, ['Name', 'Species', 'Color', 'Weight'])
92 | >>> sh.updateRow(2, ('Zophie', 'Cat', 'Gray', 11))
93 | >>> sh[1, 1]
94 | 'Name'
95 | >>> sh[1, 2]
96 | 'Zophie'
97 | >>> sh['A2']
98 | 'Zophie'
99 | >>> sh['A2'] = 'Pooka'
100 | >>> sh['A2']
101 | 'Pooka'
102 |
103 | The API section contains complete documentation.
104 |
105 | Unit Tests
106 | ----------
107 |
108 | The unit test suite takes approximately 7 minutes to run, due to the throttling.
109 |
110 |
111 | API
112 | ---
113 |
114 | .. automodule:: ezsheets
115 | :members:
116 |
117 |
--------------------------------------------------------------------------------
/docs/make.bat:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 |
3 | pushd %~dp0
4 |
5 | REM Command file for Sphinx documentation
6 |
7 | if "%SPHINXBUILD%" == "" (
8 | set SPHINXBUILD=sphinx-build
9 | )
10 | set SOURCEDIR=.
11 | set BUILDDIR=_build
12 |
13 | if "%1" == "" goto help
14 |
15 | %SPHINXBUILD% >NUL 2>NUL
16 | if errorlevel 9009 (
17 | echo.
18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19 | echo.installed, then set the SPHINXBUILD environment variable to point
20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you
21 | echo.may add the Sphinx directory to PATH.
22 | echo.
23 | echo.If you don't have Sphinx installed, grab it from
24 | echo.http://sphinx-doc.org/
25 | exit /b 1
26 | )
27 |
28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
29 | goto end
30 |
31 | :help
32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
33 |
34 | :end
35 | popd
36 |
--------------------------------------------------------------------------------
/docs/requirements.txt:
--------------------------------------------------------------------------------
1 | ezsheets
--------------------------------------------------------------------------------
/external-user-type.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asweigart/ezsheets/58d32e8e7c35694ba6ef2f89612b6d0ae198df24/external-user-type.png
--------------------------------------------------------------------------------
/google-cloud-new-project.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asweigart/ezsheets/58d32e8e7c35694ba6ef2f89612b6d0ae198df24/google-cloud-new-project.png
--------------------------------------------------------------------------------
/navigate-library.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asweigart/ezsheets/58d32e8e7c35694ba6ef2f89612b6d0ae198df24/navigate-library.png
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [tool.ruff]
2 | line-length = 120
3 |
4 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | import re
2 | from setuptools import setup, find_packages
3 |
4 | # Load version from module (without loading the whole module)
5 | with open('src/ezsheets/__init__.py', 'r') as fo:
6 | version = re.search(r'^__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
7 | fo.read(), re.MULTILINE).group(1)
8 |
9 | # Read in the README.md for the long description.
10 | with open('README.md') as fo:
11 | content = fo.read()
12 | long_description = content
13 | description = re.search('(A Pythonic interface to.*)', content).group(1)
14 |
15 | setup(
16 | name='EZSheets',
17 | version=version,
18 | url='https://github.com/asweigart/ezsheets',
19 | author='Al Sweigart',
20 | author_email='al@inventwithpython.com',
21 | description=description,
22 | long_description=long_description,
23 | long_description_content_type="text/markdown",
24 | license='GPLv3+',
25 | packages=find_packages(where='src'),
26 | package_dir={'': 'src'},
27 | test_suite='tests',
28 | install_requires=['google-api-python-client', 'google-auth-httplib2', 'google-auth-oauthlib'],
29 | keywords='',
30 | classifiers=[
31 | 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
32 | 'Programming Language :: Python',
33 | 'Programming Language :: Python :: 3',
34 | 'Programming Language :: Python :: 3.4',
35 | 'Programming Language :: Python :: 3.5',
36 | 'Programming Language :: Python :: 3.6',
37 | 'Programming Language :: Python :: 3.7',
38 | 'Programming Language :: Python :: 3.8',
39 | 'Programming Language :: Python :: 3.9',
40 | 'Programming Language :: Python :: 3.10',
41 | 'Programming Language :: Python :: 3.11',
42 | 'Programming Language :: Python :: 3.12',
43 | ],
44 | )
45 |
--------------------------------------------------------------------------------
/src/ezsheets/colorvalues.py:
--------------------------------------------------------------------------------
1 | COLORS = {
2 | 'alice blue': (0.941, 0.973, 1.0, 1.0),
3 | 'antique white': (0.98, 0.922, 0.843, 1.0),
4 | 'aqua': (0.0, 1.0, 1.0, 1.0),
5 | 'aquamarine': (0.498, 1.0, 0.831, 1.0),
6 | 'azure': (0.941, 1.0, 1.0, 1.0),
7 | 'beige': (0.961, 0.961, 0.863, 1.0),
8 | 'bisque': (1.0, 0.894, 0.769, 1.0),
9 | 'black': (0.0, 0.0, 0.0, 1.0),
10 | 'blanched almond': (1.0, 0.922, 0.804, 1.0),
11 | 'blue violet': (0.541, 0.169, 0.886, 1.0),
12 | 'blue': (0.0, 0.0, 1.0, 1.0),
13 | 'brown': (0.647, 0.165, 0.165, 1.0),
14 | 'burlywood': (0.871, 0.722, 0.529, 1.0),
15 | 'cadet blue': (0.373, 0.62, 0.627, 1.0),
16 | 'chartreuse': (0.498, 1.0, 0.0, 1.0),
17 | 'chocolate': (0.824, 0.412, 0.118, 1.0),
18 | 'coral': (1.0, 0.498, 0.314, 1.0),
19 | 'cornflower blue': (0.392, 0.584, 0.929, 1.0),
20 | 'cornsilk': (1.0, 0.973, 0.863, 1.0),
21 | 'crimson': (0.863, 0.078, 0.235, 1.0),
22 | 'cyan': (0.0, 1.0, 1.0, 1.0),
23 | 'dark blue': (0.0, 0.0, 0.545, 1.0),
24 | 'dark cyan': (0.0, 0.545, 0.545, 1.0),
25 | 'dark goldenrod': (0.722, 0.525, 0.043, 1.0),
26 | 'dark gray': (0.663, 0.663, 0.663, 1.0),
27 | 'dark green': (0.0, 0.392, 0.0, 1.0),
28 | 'dark khaki': (0.741, 0.718, 0.42, 1.0),
29 | 'dark magenta': (0.545, 0.0, 0.545, 1.0),
30 | 'dark olive green': (0.333, 0.42, 0.184, 1.0),
31 | 'dark orange': (1.0, 0.549, 0.0, 1.0),
32 | 'dark orchid': (0.6, 0.196, 0.8, 1.0),
33 | 'dark red': (0.545, 0.0, 0.0, 1.0),
34 | 'dark salmon': (0.914, 0.588, 0.478, 1.0),
35 | 'dark sea green': (0.561, 0.737, 0.561, 1.0),
36 | 'dark slate blue': (0.282, 0.239, 0.545, 1.0),
37 | 'dark slate gray': (0.184, 0.31, 0.31, 1.0),
38 | 'dark turquoise': (0.0, 0.808, 0.82, 1.0),
39 | 'dark violet': (0.58, 0.0, 0.827, 1.0),
40 | 'deep pink': (1.0, 0.078, 0.576, 1.0),
41 | 'deep sky blue': (0.0, 0.749, 1.0, 1.0),
42 | 'dim gray': (0.412, 0.412, 0.412, 1.0),
43 | 'dodger blue': (0.118, 0.565, 1.0, 1.0),
44 | 'firebrick': (0.698, 0.133, 0.133, 1.0),
45 | 'floral white': (1.0, 0.98, 0.941, 1.0),
46 | 'forest green': (0.133, 0.545, 0.133, 1.0),
47 | 'fuchsia': (1.0, 0.0, 1.0, 1.0),
48 | 'gainsboro': (0.863, 0.863, 0.863, 1.0),
49 | 'ghost white': (0.973, 0.973, 1.0, 1.0),
50 | 'gold': (1.0, 0.843, 0.0, 1.0),
51 | 'goldenrod': (0.855, 0.647, 0.125, 1.0),
52 | 'gray': (0.502, 0.502, 0.502, 1.0),
53 | 'green yellow': (0.678, 1.0, 0.184, 1.0),
54 | 'green': (0.0, 0.502, 0.0, 1.0),
55 | 'honeydew': (0.941, 1.0, 0.941, 1.0),
56 | 'hot pink': (1.0, 0.412, 0.706, 1.0),
57 | 'indian red': (0.804, 0.361, 0.361, 1.0),
58 | 'indigo': (0.294, 0.0, 0.51, 1.0),
59 | 'ivory': (1.0, 1.0, 0.941, 1.0),
60 | 'khaki': (0.941, 0.902, 0.549, 1.0),
61 | 'lavender blush': (1.0, 0.941, 0.961, 1.0),
62 | 'lavender': (0.902, 0.902, 0.98, 1.0),
63 | 'lawn green': (0.486, 0.988, 0.0, 1.0),
64 | 'lemon chiffon': (1.0, 0.98, 0.804, 1.0),
65 | 'light blue': (0.678, 0.847, 0.902, 1.0),
66 | 'light coral': (0.941, 0.502, 0.502, 1.0),
67 | 'light cyan': (0.878, 1.0, 1.0, 1.0),
68 | 'light goldenrod yellow': (0.98, 0.98, 0.824, 1.0),
69 | 'light gray': (0.827, 0.827, 0.827, 1.0),
70 | 'light green': (0.565, 0.933, 0.565, 1.0),
71 | 'light pink': (1.0, 0.714, 0.757, 1.0),
72 | 'light salmon': (1.0, 0.627, 0.478, 1.0),
73 | 'light sea green': (0.125, 0.698, 0.667, 1.0),
74 | 'light sky blue': (0.529, 0.808, 0.98, 1.0),
75 | 'light slate gray': (0.467, 0.533, 0.6, 1.0),
76 | 'light steel blue': (0.69, 0.769, 0.871, 1.0),
77 | 'light yellow': (1.0, 1.0, 0.878, 1.0),
78 | 'lime green': (0.196, 0.804, 0.196, 1.0),
79 | 'lime': (0.0, 1.0, 0.0, 1.0),
80 | 'linen': (0.98, 0.941, 0.902, 1.0),
81 | 'magenta': (1.0, 0.0, 1.0, 1.0),
82 | 'maroon': (0.502, 0.0, 0.0, 1.0),
83 | 'medium aquamarine': (0.4, 0.804, 0.667, 1.0),
84 | 'medium blue': (0.0, 0.0, 0.804, 1.0),
85 | 'medium orchid': (0.729, 0.333, 0.827, 1.0),
86 | 'medium purple': (0.576, 0.439, 0.859, 1.0),
87 | 'medium sea green': (0.235, 0.702, 0.443, 1.0),
88 | 'medium slate blue': (0.482, 0.408, 0.933, 1.0),
89 | 'medium spring green': (0.0, 0.98, 0.604, 1.0),
90 | 'medium turquoise': (0.282, 0.82, 0.8, 1.0),
91 | 'medium violet red': (0.78, 0.082, 0.522, 1.0),
92 | 'midnight blue': (0.098, 0.098, 0.439, 1.0),
93 | 'mint cream': (0.961, 1.0, 0.98, 1.0),
94 | 'misty rose': (1.0, 0.894, 0.882, 1.0),
95 | 'moccasin': (1.0, 0.894, 0.71, 1.0),
96 | 'navajo white': (1.0, 0.871, 0.678, 1.0),
97 | 'navy': (0.0, 0.0, 0.502, 1.0),
98 | 'old lace': (0.992, 0.961, 0.902, 1.0),
99 | 'olive drab': (0.42, 0.557, 0.137, 1.0),
100 | 'olive': (0.502, 0.502, 0.0, 1.0),
101 | 'orange red': (1.0, 0.271, 0.0, 1.0),
102 | 'orange': (1.0, 0.647, 0.0, 1.0),
103 | 'orchid': (0.855, 0.439, 0.839, 1.0),
104 | 'pale goldenrod': (0.933, 0.91, 0.667, 1.0),
105 | 'pale green': (0.596, 0.984, 0.596, 1.0),
106 | 'pale turquoise': (0.686, 0.933, 0.933, 1.0),
107 | 'pale violet red': (0.859, 0.439, 0.576, 1.0),
108 | 'papaya whip': (1.0, 0.937, 0.835, 1.0),
109 | 'peach puff': (1.0, 0.855, 0.725, 1.0),
110 | 'peru': (0.804, 0.522, 0.247, 1.0),
111 | 'pink': (1.0, 0.753, 0.796, 1.0),
112 | 'plum': (0.867, 0.627, 0.867, 1.0),
113 | 'powder blue': (0.69, 0.878, 0.902, 1.0),
114 | 'purple': (0.502, 0.0, 0.502, 1.0),
115 | 'red': (1.0, 0.0, 0.0, 1.0),
116 | 'rosy brown': (0.737, 0.561, 0.561, 1.0),
117 | 'royal blue': (0.255, 0.412, 0.882, 1.0),
118 | 'saddle brown': (0.545, 0.271, 0.075, 1.0),
119 | 'salmon': (0.98, 0.502, 0.447, 1.0),
120 | 'sandy brown': (0.957, 0.643, 0.376, 1.0),
121 | 'sea green': (0.18, 0.545, 0.341, 1.0),
122 | 'seashell': (1.0, 0.961, 0.933, 1.0),
123 | 'sienna': (0.627, 0.322, 0.176, 1.0),
124 | 'silver': (0.753, 0.753, 0.753, 1.0),
125 | 'sky blue': (0.529, 0.808, 0.922, 1.0),
126 | 'slate blue': (0.416, 0.353, 0.804, 1.0),
127 | 'slate gray': (0.439, 0.502, 0.565, 1.0),
128 | 'snow': (1.0, 0.98, 0.98, 1.0),
129 | 'spring green': (0.0, 1.0, 0.498, 1.0),
130 | 'steel blue': (0.275, 0.51, 0.706, 1.0),
131 | 'tan': (0.824, 0.706, 0.549, 1.0),
132 | 'teal': (0.0, 0.502, 0.502, 1.0),
133 | 'thistle': (0.847, 0.749, 0.847, 1.0),
134 | 'tomato': (1.0, 0.388, 0.278, 1.0),
135 | 'turquoise': (0.251, 0.878, 0.816, 1.0),
136 | 'violet': (0.933, 0.51, 0.933, 1.0),
137 | 'wheat': (0.961, 0.871, 0.702, 1.0),
138 | 'white smoke': (0.961, 0.961, 0.961, 1.0),
139 | 'white': (1.0, 1.0, 1.0, 1.0),
140 | 'yellow green': (0.604, 0.804, 0.196, 1.0),
141 | 'yellow': (1.0, 1.0, 0.0, 1.0),
142 | }
143 |
--------------------------------------------------------------------------------
/tests/my_spreadsheet.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asweigart/ezsheets/58d32e8e7c35694ba6ef2f89612b6d0ae198df24/tests/my_spreadsheet.xlsx
--------------------------------------------------------------------------------
/tests/produceSales.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/asweigart/ezsheets/58d32e8e7c35694ba6ef2f89612b6d0ae198df24/tests/produceSales.xlsx
--------------------------------------------------------------------------------
/tests/test_automate2nded.py:
--------------------------------------------------------------------------------
1 | """
2 | These tests check to make sure that the interactive shell examples in Automate the Boring Stuff 2nd Edition still run. It is critically important
3 | that this code still works as it is printed in the book.
4 | """
5 |
6 | import os
7 |
8 | THIS_TEST_SCRIPT_FOLDER = os.path.dirname(os.path.abspath(__file__))
9 |
10 |
11 | def test_page333():
12 | """
13 | Page 333
14 | >>> import ezsheets
15 | >>> ss = ezsheets.Spreadsheet('1J-Jx6Ne2K_vqI9J2SO-TAXOFbxx_9tUjwnkPC22LjeU')
16 | >>> ss
17 | Spreadsheet(spreadsheetId='1J-Jx6Ne2K_vqI9J2SO-TAXOFbxx_9tUjwnkPC22LjeU')
18 | >>> ss.title
19 | 'Education Data'
20 | """
21 | import ezsheets
22 | dummy_ss = ezsheets.createSpreadsheet('Education Data') # (setup)
23 | ss = ezsheets.Spreadsheet(dummy_ss.spreadsheetId) # (adjusted)
24 | assert ss.title == 'Education Data'
25 | ss.delete(permanent=True) # (teardown)
26 |
27 |
28 | def test_page334_create():
29 | """
30 | Page 334
31 | >>> import ezsheets
32 | >>> ss = ezsheets.createSpreadsheet('Title of My New Spreadsheet')
33 | >>> ss.title
34 | 'Title of My New Spreadsheet'
35 | """
36 |
37 | import ezsheets
38 | ss = ezsheets.createSpreadsheet('Title of My New Spreadsheet')
39 | assert ss.title == 'Title of My New Spreadsheet'
40 | ss.delete(permanent=True) # (teardown)
41 |
42 |
43 | def test_page334_upload_list():
44 | """
45 | >>> import ezsheets
46 | >>> ss = ezsheets.upload('my_spreadsheet.xlsx')
47 | >>> ss.title
48 | 'my_spreadsheet'
49 |
50 | >>> ezsheets.listSpreadsheets()
51 | {'1J-Jx6Ne2K_vqI9J2SO-TAXOFbxx_9tUjwnkPC22LjeU': 'Education Data'}
52 | """
53 | import ezsheets
54 | ss = ezsheets.upload(os.path.join(THIS_TEST_SCRIPT_FOLDER, 'my_spreadsheet.xlsx')) # (adjusted)
55 | assert ss.title == 'my_spreadsheet'
56 | assert (ss.spreadsheetId, 'my_spreadsheet') in ezsheets.listSpreadsheets().items()
57 | ss.delete(permanent=True) # (teardown)
58 |
59 |
60 | def test_page334_335():
61 | """
62 | Page 334-335
63 | >>> import ezsheets
64 | >>> ss = ezsheets.Spreadsheet('1J-Jx6Ne2K_vqI9J2SO-TAXOFbxx_9tUjwnkPC22LjeU')
65 | >>> ss.title # The title of the spreadsheet.
66 | 'Education Data'
67 | >>> ss.title = 'Class Data' # Change the title.
68 | >>> ss.spreadsheetId # The unique ID (this is a read-only attribute).
69 | '1J-Jx6Ne2K_vqI9J2SO-TAXOFbxx_9tUjwnkPC22LjeU'
70 | >>> ss.url # The original URL (this is a read-only attribute).
71 | 'https://docs.google.com/spreadsheets/d/1J-Jx6Ne2K_vqI9J2SO-
72 | TAXOFbxx_9tUjwnkPC22LjeU/'
73 | >>> ss.sheetTitles # The titles of all the Sheet objects
74 | ('Students', 'Classes', 'Resources')
75 | >>> ss.sheets # The Sheet objects in this Spreadsheet, in order.
76 | (, , )
79 | >>> ss[0] # The first Sheet object in this Spreadsheet.
80 |
81 | >>> ss['Students'] # Sheets can also be accessed by title.
82 |
83 | >>> del ss[0] # Delete the first Sheet object in this Spreadsheet.
84 | >>> ss.sheetTitles # The "Students" Sheet object has been deleted:
85 | ('Classes', 'Resources')
86 | """
87 |
88 | import ezsheets
89 | dummy_ss = ezsheets.createSpreadsheet('Education Data') # (setup)
90 | ss = ezsheets.Spreadsheet(dummy_ss.spreadsheetId) # (adjusted)
91 | assert ss.title == 'Education Data' # The title of the spreadsheet.
92 | ss.title = 'Class Data' # Change the title.
93 | assert ss.spreadsheetId
94 | assert ss.url == 'https://docs.google.com/spreadsheets/d/' + ss.spreadsheetId + '/'
95 | ss.createSheet('Students') # (setup)
96 | ss.createSheet('Classes') # (setup)
97 | ss.createSheet('Resources') # (setup)
98 | ss['Sheet1'].delete() # (setup)
99 | assert ss.sheetTitles == ('Students', 'Classes', 'Resources')
100 | assert len(ss.sheets) == 3 # (adjusted)
101 | assert ss[0]
102 | assert ss['Students']
103 | del ss[0]
104 | assert ss.sheetTitles == ('Classes', 'Resources')
105 |
106 | ss.delete(permanent=True) # (teardown)
107 |
108 |
109 | def test_page335_refresh():
110 | """
111 | >>> ss.refresh()
112 | """
113 | import ezsheets
114 | dummy_ss = ezsheets.createSpreadsheet('Class Data') # (setup)
115 | dummy_ss.refresh()
116 | dummy_ss.delete(permanent=True) # (teardown)
117 |
118 |
119 | def test_page335_download_upload():
120 | """
121 | >>> import ezsheets
122 | >>> ss = ezsheets.Spreadsheet('1J-Jx6Ne2K_vqI9J2SO-TAXOFbxx_9tUjwnkPC22LjeU')
123 | >>> ss.title
124 | 'Class Data'
125 | >>> ss.downloadAsExcel() # Downloads the spreadsheet as an Excel file.
126 | 'Class_Data.xlsx'
127 | >>> ss.downloadAsODS() # Downloads the spreadsheet as an OpenOffice file.
128 | 'Class_Data.ods'
129 | >>> ss.downloadAsCSV() # Only downloads the first sheet as a CSV file.
130 | 'Class_Data.csv'
131 | >>> ss.downloadAsTSV() # Only downloads the first sheet as a TSV file.
132 | 'Class_Data.tsv'
133 | >>> ss.downloadAsPDF() # Downloads the spreadsheet as a PDF.
134 | 'Class_Data.pdf'
135 | >>> ss.downloadAsHTML() # Downloads the spreadsheet as a ZIP of HTML files.
136 | 'Class_Data.zip'
137 |
138 | >>> ss.downloadAsExcel('a_different_filename.xlsx')
139 | 'a_different_filename.xlsx'
140 | """
141 |
142 | import ezsheets
143 | dummy_ss = ezsheets.createSpreadsheet('Class Data') # (setup)
144 | ss = ezsheets.Spreadsheet(dummy_ss.spreadsheetId) # (adjusted)
145 | assert ss.title == 'Class Data'
146 |
147 | assert ss.downloadAsExcel() == 'Class_Data.xlsx'
148 | assert os.path.exists('Class_Data.xlsx') # (teardown)
149 | os.unlink('Class_Data.xlsx') # (teardown)
150 |
151 | assert ss.downloadAsODS() == 'Class_Data.ods'
152 | assert os.path.exists('Class_Data.ods') # (teardown)
153 | os.unlink('Class_Data.ods') # (teardown)
154 |
155 | assert ss.downloadAsCSV() == 'Class_Data.csv'
156 | assert os.path.exists('Class_Data.csv') # (teardown)
157 | os.unlink('Class_Data.csv') # (teardown)
158 |
159 | assert ss.downloadAsTSV() == 'Class_Data.tsv'
160 | assert os.path.exists('Class_Data.tsv') # (teardown)
161 | os.unlink('Class_Data.tsv') # (teardown)
162 |
163 | assert ss.downloadAsPDF() == 'Class_Data.pdf'
164 | assert os.path.exists('Class_Data.pdf') # (teardown)
165 | os.unlink('Class_Data.pdf') # (teardown)
166 |
167 | assert ss.downloadAsHTML() == 'Class_Data.zip'
168 | assert os.path.exists('Class_Data.zip') # (teardown)
169 | os.unlink('Class_Data.zip') # (teardown)
170 |
171 | assert ss.downloadAsExcel('a_different_filename.xlsx') == 'a_different_filename.xlsx'
172 | assert os.path.exists('a_different_filename.xlsx') # (teardown)
173 | os.unlink('a_different_filename.xlsx') # (teardown)
174 |
175 | ss.delete(permanent=True) # (teardown)
176 |
177 |
178 | def test_page336_deleting_spreadsheets():
179 | """
180 | >>> import ezsheets
181 | >>> ss = ezsheets.createSpreadsheet('Delete me') # Create the spreadsheet.
182 | >>> ezsheets.listSpreadsheets() # Confirm that we've created a spreadsheet.
183 | {'1aCw2NNJSZblDbhygVv77kPsL3djmgV5zJZllSOZ_mRk': 'Delete me'}
184 | >>> ss.delete() # Delete the spreadsheet.
185 | >>> ezsheets.listSpreadsheets()
186 | {}
187 |
188 | >>> ss.delete(permanent=True)
189 | """
190 |
191 | # NOTE - delete() moves stuff to trash, and ss in the trash will still show up in listSpreadsheets()!!!!
192 |
193 | import ezsheets
194 | ss = ezsheets.createSpreadsheet('Delete me PAGE336') # Create the spreadsheet. (adjusted since there can be other 'Delete me' spreadsheets on this account)
195 | assert (ss.spreadsheetId, 'Delete me PAGE336') in ezsheets.listSpreadsheets().items() # Confirm that we've created a spreadsheet.
196 | savedId = ss.spreadsheetId # (setup)
197 | ss.delete() # Delete the spreadsheet.
198 | assert (savedId, 'Delete me PAGE336') in ezsheets.listSpreadsheets().items() # (teardown)
199 | ss.delete(permanent=True) # (teardown)
200 | assert (savedId, 'Delete me PAGE336') not in ezsheets.listSpreadsheets().items() # (teardown)
201 |
202 | #ss = ezsheets.createSpreadsheet('Delete me PAGE336') # Create the spreadsheet.
203 | #assert (ss.spreadsheetId, 'Delete me PAGE336') in ezsheets.listSpreadsheets().items() # Confirm that we've created a spreadsheet.
204 | #savedId = ss.spreadsheetId # (setup)
205 | #ss.delete(permanent=True) # Delete the spreadsheet.
206 | #assert (savedId, 'Delete me PAGE336') not in ezsheets.listSpreadsheets().items() # (teardown)
207 |
208 | def test_page336_337_sheet_objects():
209 | """
210 | >>> import ezsheets
211 | >>> ss = ezsheets.Spreadsheet('1J-Jx6Ne2K_vqI9J2SO-TAXOFbxx_9tUjwnkPC22LjeU')
212 | >>> ss.sheets # The Sheet objects in this Spreadsheet, in order.
213 | (,
214 | )
215 | >>> ss.sheets[0] # Gets the first Sheet object in this Spreadsheet.
216 |
217 | >>> ss[0] # Also gets the first Sheet object in this Spreadsheet.
218 |
219 |
220 | >>> ss.sheetTitles # The titles of all the Sheet objects in this Spreadsheet.
221 | ('Classes', 'Resources')
222 | >>> ss['Classes'] # Sheets can also be accessed by title.
223 |
224 | """
225 |
226 | import ezsheets
227 | dummy_ss = ezsheets.createSpreadsheet('Education Data') # (setup)
228 | ss = ezsheets.Spreadsheet(dummy_ss.spreadsheetId) # (adjusted)
229 | ss.createSheet('Classes') # (setup)
230 | ss.createSheet('Resources') # (setup)
231 | del ss['Sheet1'] # (setup)
232 |
233 | assert len(ss.sheets) == 2 # (adjusted)
234 | assert ss.sheets[0] == ss[0]
235 |
236 | assert ss.sheetTitles == ('Classes', 'Resources')
237 |
238 |
239 | def test_page337_read_write():
240 | """
241 | >>> import ezsheets
242 | >>> ss = ezsheets.createSpreadsheet('My Spreadsheet')
243 | >>> sheet = ss[0] # Get the first sheet in this spreadsheet.
244 | >>> sheet.title
245 | 'Sheet1'
246 | >>> sheet = ss[0]
247 | >>> sheet['A1'] = 'Name' # Set the value in cell A1.
248 | >>> sheet['B1'] = 'Age'
249 | >>> sheet['C1'] = 'Favorite Movie'
250 | >>> sheet['A1'] # Read the value in cell A1.
251 | 'Name'
252 | >>> sheet['A2'] # Empty cells return a blank string.
253 | ''
254 | >>> sheet[2, 1] # Column 2, Row 1 is the same address as B1.
255 | 'Age'
256 | >>> sheet['A2'] = 'Alice'
257 | >>> sheet['B2'] = 30
258 | >>> sheet['C2'] = 'RoboCop'
259 | """
260 | import ezsheets
261 | ss = ezsheets.createSpreadsheet('My Spreadsheet')
262 | sheet = ss[0] # Get the first sheet in this spreadsheet.
263 | assert sheet.title == 'Sheet1'
264 | sheet = ss[0]
265 | sheet['A1'] = 'Name' # Set the value in cell A1.
266 | sheet['B1'] = 'Age'
267 | sheet['C1'] = 'Favorite Movie'
268 | assert sheet['A1'] == 'Name' # Read the value in cell A1.
269 |
270 | assert sheet['A2'] == '' # Empty cells return a blank string.
271 | assert sheet[2, 1] == 'Age' # Column 2, Row 1 is the same address as B1.
272 | sheet['A2'] = 'Alice'
273 | assert sheet['A2'] == 'Alice'
274 | sheet['B2'] = 30
275 | assert sheet['B2'] == '30'
276 | sheet['C2'] = 'RoboCop'
277 | assert sheet['C2'] == 'RoboCop'
278 |
279 | ss.delete(permanent=True)
280 |
281 |
282 | def test_page338():
283 | """
284 | >>> import ezsheets
285 | >>> ezsheets.convertAddress('A2') # Converts addresses...
286 | (1, 2)
287 | >>> ezsheets.convertAddress(1, 2) # ...and converts them back, too.
288 | 'A2'
289 | >>> ezsheets.getColumnLetterOf(2)
290 | 'B'
291 | >>> ezsheets.getColumnNumberOf('B')
292 | 2
293 | >>> ezsheets.getColumnLetterOf(999)
294 | 'ALK'
295 |
296 |
297 | >>> ezsheets.getColumnNumberOf('ZZZ')
298 | 18278
299 | """
300 | import ezsheets
301 | assert ezsheets.convertAddress('A2') == (1, 2)# Converts addresses...
302 | assert ezsheets.convertAddress(1, 2) == 'A2'# ...and converts them back, too.
303 | assert ezsheets.getColumnLetterOf(2) == 'B'
304 | assert ezsheets.getColumnNumberOf('B') == 2
305 | assert ezsheets.getColumnLetterOf(999) == 'ALK'
306 | assert ezsheets.getColumnNumberOf('ZZZ') == 18278
307 |
308 | def test_page339_341():
309 | """
310 | >>> import ezsheets
311 | >>> ss = ezsheets.upload('produceSales.xlsx')
312 | >>> sheet = ss[0]
313 | >>> sheet.getRow(1) # The first row is row 1, not row 0.
314 | ['PRODUCE', 'COST PER POUND', 'POUNDS SOLD', 'TOTAL', '', '']
315 | >>> sheet.getRow(2)
316 | ['Potatoes', '0.86', '21.6', '18.58', '', '']
317 | >>> columnOne = sheet.getColumn(1)
318 | >>> sheet.getColumn(1)
319 | ['PRODUCE', 'Potatoes', 'Okra', 'Fava beans', 'Watermelon', 'Garlic',
320 | --snip--
321 | >>> sheet.getColumn('A') # Same result as getColumn(1)
322 | ['PRODUCE', 'Potatoes', 'Okra', 'Fava beans', 'Watermelon', 'Garlic',
323 | --snip--
324 | >>> sheet.getRow(3)
325 | ['Okra', '2.26', '38.6', '87.24', '', '']
326 | >>> sheet.updateRow(3, ['Pumpkin', '11.50', '20', '230'])
327 | >>> sheet.getRow(3)
328 | ['Pumpkin', '11.50', '20', '230', '', '']
329 | >>> columnOne = sheet.getColumn(1)
330 | >>> for i, value in enumerate(columnOne):
331 | ... # Make the Python list contain uppercase strings:
332 | ... columnOne[i] = value.upper()
333 | ...
334 | >>> sheet.updateColumn(1, columnOne) # Update the entire column in one
335 | request.
336 |
337 |
338 | >>> rows = sheet.getRows() # Get every row in the spreadsheet.
339 | >>> rows[0] # Examine the values in the first row.
340 | ['PRODUCE', 'COST PER POUND', 'POUNDS SOLD', 'TOTAL', '', '']
341 | >>> rows[1]
342 | ['POTATOES', '0.86', '21.6', '18.58', '', '']
343 | >>> rows[1][0] = 'PUMPKIN' # Change the produce name.
344 | >>> rows[1]
345 | ['PUMPKIN', '0.86', '21.6', '18.58', '', '']
346 | >>> rows[10]
347 | ['OKRA', '2.26', '40', '90.4', '', '']
348 | >>> rows[10][2] = '400' # Change the pounds sold.
349 | >>> rows[10][3] = '904' # Change the total.
350 | >>> rows[10]
351 | ['OKRA', '2.26', '400', '904', '', '']
352 | >>> sheet.updateRows(rows) # Update the online spreadsheet with the changes.
353 |
354 |
355 | >>> sheet.rowCount # The number of rows in the sheet.
356 | 23758
357 | >>> sheet.columnCount # The number of columns in the sheet.
358 | 6
359 | >>> sheet.columnCount = 4 # Change the number of columns to 4.
360 | >>> sheet.columnCount # Now the number of columns in the sheet is 4.
361 | 4
362 | """
363 |
364 | import ezsheets
365 | ss = ezsheets.upload(os.path.join(THIS_TEST_SCRIPT_FOLDER, 'produceSales.xlsx')) # (adjusted)
366 | sheet = ss[0]
367 | assert sheet.getRow(1) == ['PRODUCE', 'COST PER POUND', 'POUNDS SOLD', 'TOTAL', '', ''] # The first row is row 1, not row 0.
368 |
369 | assert sheet.getRow(2) == ['Potatoes', '0.86', '21.6', '18.58', '', '']
370 |
371 | columnOne = sheet.getColumn(1)
372 | assert sheet.getColumn(1)[0:6] == ['PRODUCE', 'Potatoes', 'Okra', 'Fava beans', 'Watermelon', 'Garlic',] # (adjusted)
373 |
374 | assert sheet.getColumn('A')[0:6] == ['PRODUCE', 'Potatoes', 'Okra', 'Fava beans', 'Watermelon', 'Garlic',] # Same result as getColumn(1) # (adjusted)
375 |
376 | assert sheet.getRow(3) == ['Okra', '2.26', '38.6', '87.24', '', '']
377 | sheet.updateRow(3, ['Pumpkin', '11.50', '20', '230'])
378 | assert sheet.getRow(3) == ['Pumpkin', '11.50', '20', '230', '', '']
379 |
380 | columnOne = sheet.getColumn(1)
381 | for i, value in enumerate(columnOne):
382 | # Make the Python list contain uppercase strings:
383 | columnOne[i] = value.upper()
384 |
385 | sheet.updateColumn(1, columnOne) # Update the entire column in one request.
386 |
387 |
388 | rows = sheet.getRows() # Get every row in the spreadsheet.
389 | assert rows[0] == ['PRODUCE', 'COST PER POUND', 'POUNDS SOLD', 'TOTAL', '', ''] # Examine the values in the first row.
390 | assert rows[1] == ['POTATOES', '0.86', '21.6', '18.58', '', '']
391 | rows[1][0] = 'PUMPKIN' # Change the produce name.
392 | assert rows[1] == ['PUMPKIN', '0.86', '21.6', '18.58', '', '']
393 | assert rows[10] == ['OKRA', '2.26', '40', '90.4', '', '']
394 | rows[10][2] = '400' # Change the pounds sold.
395 | rows[10][3] = '904' # Change the total.
396 | assert rows[10] == ['OKRA', '2.26', '400', '904', '', '']
397 | sheet.updateRows(rows) # Update the online spreadsheet with the changes.
398 |
399 |
400 | assert sheet.rowCount == 23758 # The number of rows in the sheet.
401 |
402 | assert sheet.columnCount == 6 # The number of columns in the sheet.
403 |
404 | sheet.columnCount = 4 # Change the number of columns to 4.
405 | assert sheet.columnCount == 4 # Now the number of columns in the sheet is 4.
406 |
407 |
408 | ss.delete(permanent=True) # (teardown)
409 |
410 |
411 | def test_page341_342():
412 | """
413 | >>> import ezsheets
414 | >>> ss = ezsheets.createSpreadsheet('Multiple Sheets')
415 | >>> ss.sheetTitles
416 | ('Sheet1',)
417 | >>> ss.createSheet('Spam') # Create a new sheet at the end of the list of
418 | sheets.
419 |
420 | >>> ss.createSheet('Eggs') # Create another new sheet.
421 |
422 | >>> ss.sheetTitles
423 | ('Sheet1', 'Spam', 'Eggs')
424 | >>> ss.createSheet('Bacon', 0) # Create a sheet at index 0 in the list of
425 | sheets.
426 |
427 | >>> ss.sheetTitles
428 | ('Bacon', 'Sheet1', 'Spam', 'Eggs')
429 |
430 |
431 | >>> ss.sheetTitles
432 | ('Bacon', 'Sheet1', 'Spam', 'Eggs')
433 | >>> ss[0].delete() # Delete the sheet at index 0: the "Bacon" sheet.
434 | >>> ss.sheetTitles
435 | ('Sheet1', 'Spam', 'Eggs')
436 | >>> ss['Spam'].delete() # Delete the "Spam" sheet.
437 | >>> ss.sheetTitles
438 | ('Sheet1', 'Eggs')
439 | >>> sheet = ss['Eggs'] # Assign a variable to the "Eggs" sheet.
440 | >>> sheet.delete() # Delete the "Eggs" sheet.
441 | >>> ss.sheetTitles
442 | ('Sheet1',)
443 | >>> ss[0].clear() # Clear all the cells on the "Sheet1" sheet.
444 | >>> ss.sheetTitles # The "Sheet1" sheet is empty but still exists.
445 | ('Sheet1',)
446 | """
447 | import ezsheets
448 | ss = ezsheets.createSpreadsheet('Multiple Sheets')
449 | assert ss.sheetTitles == ('Sheet1',)
450 | ss.createSheet('Spam') # Create a new sheet at the end of the list of sheets.
451 | ss.createSheet('Eggs') # Create another new sheet.
452 | assert ss.sheetTitles == ('Sheet1', 'Spam', 'Eggs')
453 | ss.createSheet('Bacon', 0) # Create a sheet at index 0 in the list of sheets.
454 | assert ss.sheetTitles == ('Bacon', 'Sheet1', 'Spam', 'Eggs')
455 |
456 | ss[0].delete() # Delete the sheet at index 0: the "Bacon" sheet.
457 | assert ss.sheetTitles == ('Sheet1', 'Spam', 'Eggs')
458 | ss['Spam'].delete() # Delete the "Spam" sheet.
459 | assert ss.sheetTitles == ('Sheet1', 'Eggs')
460 | sheet = ss['Eggs'] # Assign a variable to the "Eggs" sheet.
461 | sheet.delete() # Delete the "Eggs" sheet.
462 | assert ss.sheetTitles == ('Sheet1',)
463 | ss[0].clear() # Clear all the cells on the "Sheet1" sheet.
464 | assert ss.sheetTitles == ('Sheet1',)
465 |
466 | ss.delete(permanent=True) # (teardown)
467 |
468 |
469 | def test_page343():
470 | """
471 | >>> import ezsheets
472 | >>> ss1 = ezsheets.createSpreadsheet('First Spreadsheet')
473 | >>> ss2 = ezsheets.createSpreadsheet('Second Spreadsheet')
474 | >>> ss1[0]
475 |
476 | >>> ss1[0].updateRow(1, ['Some', 'data', 'in', 'the', 'first', 'row'])
477 | >>> ss1[0].copyTo(ss2) # Copy the ss1's Sheet1 to the ss2 spreadsheet.
478 | >>> ss2.sheetTitles # ss2 now contains a copy of ss1's Sheet1.
479 | ('Sheet1', 'Copy of Sheet1')
480 | """
481 |
482 | import ezsheets
483 | ss1 = ezsheets.createSpreadsheet('First Spreadsheet')
484 | ss2 = ezsheets.createSpreadsheet('Second Spreadsheet')
485 | ss1[0]
486 | ss1[0].updateRow(1, ['Some', 'data', 'in', 'the', 'first', 'row'])
487 | ss1[0].copyTo(ss2) # Copy the ss1's Sheet1 to the ss2 spreadsheet.
488 | assert ss2.sheetTitles == ('Sheet1', 'Copy of Sheet1') # ss2 now contains a copy of ss1's Sheet1.
489 |
490 | ss1.delete(permanent=True) # (teardown)
491 | ss2.delete(permanent=True) # (teardown)
492 |
493 |
494 | def test_bean_count():
495 | # Just test to make sure this is still there. This URL is referenced by the "Finding Mistakes in a Spreadsheet" practice project section.
496 | import ezsheets
497 | ezsheets.Spreadsheet('https://docs.google.com/spreadsheets/d/1jDZEdvSIh4TmZxccyy0ZXrH-ELlrwq8_YYiZrEOB4jg/edit?usp=sharing/')
498 |
--------------------------------------------------------------------------------
/tests/test_ezsheets.py:
--------------------------------------------------------------------------------
1 | from __future__ import division, print_function
2 | import random
3 | import pytest
4 | import ezsheets
5 |
6 | #now = time.time()
7 | #random.seed(now)
8 | #print('Random seed: %s' % (now))
9 |
10 | """
11 | NOTE: This test requires a credentials.json and token.pickle file to be in the
12 | same folder as this script. A new spreadsheet will be created for use by this
13 | script.
14 | """
15 |
16 |
17 | def checkIfSpreadsheetInOriginalState():
18 | # Check if there exists only one Sheet in the TEST_SS Spreadsheet object.
19 | assert TEST_SS.title == 'Delete Me'
20 | assert len(TEST_SS) == 1
21 | assert TEST_SS[0].title == 'Sheet1'
22 | #print('READS=%s, WRITES=%s' % (ezsheets._READ_REQUESTS, ezsheets._WRITE_REQUESTS))
23 |
24 |
25 | def addOriginalSheet():
26 | # If we delete all the sheets in TEST_SS, call this to restore the original Sheet1 Sheet object.
27 | assert 'Sheet1' not in TEST_SS.sheetTitles
28 | TEST_SS.createSheet(title='Sheet1')
29 | checkIfSpreadsheetInOriginalState()
30 |
31 |
32 | @pytest.fixture
33 | def checkPreAndPostCondition():
34 | # Check that Spreadsheet is in original condition before the test.
35 | checkIfSpreadsheetInOriginalState()
36 | yield
37 | # Check that Spreadsheet is in original condition after the test.
38 | checkIfSpreadsheetInOriginalState()
39 |
40 |
41 | def test_basic():
42 | pass # TODO - add unit tests
43 |
44 |
45 | def test_getIdFromUrl():
46 | # Fake url and id
47 | assert ezsheets.getIdFromUrl("https://docs.google.com/spreadsheets/d/10tRbpHZYkfRecHyRHRjBLdQYoq5QWNBqZmH9tt4Tjng/edit#gid=0") == "10tRbpHZYkfRecHyRHRjBLdQYoq5QWNBqZmH9tt4Tjng"
48 |
49 | with pytest.raises(ValueError):
50 | # Fake url and id
51 | ezsheets.getIdFromUrl(r"https://docs.google.com/spread sheets/d/10tRbpHZYkfRecHyRHRjBLdQYoq5QWNBqZmH9tt4Tjng/edit#gid=0")
52 |
53 |
54 | def test_getColumnLetterOf():
55 | assert ezsheets.getColumnLetterOf(1) == 'A'
56 | assert ezsheets.getColumnLetterOf(26) == 'Z'
57 | assert ezsheets.getColumnLetterOf(27) == 'AA'
58 | assert ezsheets.getColumnLetterOf(702) == 'ZZ'
59 |
60 | with pytest.raises(TypeError):
61 | ezsheets.getColumnLetterOf('invalid arg')
62 |
63 | with pytest.raises(ValueError):
64 | ezsheets.getColumnLetterOf(0)
65 |
66 | with pytest.raises(ValueError):
67 | ezsheets.getColumnLetterOf(-1)
68 |
69 |
70 | def test_getColumnNumberOf():
71 | assert ezsheets.getColumnNumberOf('A') == 1
72 | assert ezsheets.getColumnNumberOf('Z') == 26
73 | assert ezsheets.getColumnNumberOf('AA') == 27
74 | assert ezsheets.getColumnNumberOf('ZZ') == 702
75 |
76 | with pytest.raises(TypeError):
77 | ezsheets.getColumnNumberOf(1)
78 |
79 | with pytest.raises(ValueError):
80 | ezsheets.getColumnNumberOf('123')
81 |
82 |
83 | def test_columnNumberLetterTranslation():
84 | for i in range(1, 5000):
85 | assert ezsheets.getColumnNumberOf(ezsheets.getColumnLetterOf(i)) == i
86 |
87 |
88 | def test_convertToColumnRowInts():
89 | assert ezsheets.convertToColumnRowInts('A1') == (1, 1)
90 | assert ezsheets.convertToColumnRowInts('Z1') == (26, 1)
91 | assert ezsheets.convertToColumnRowInts('AA1') == (27, 1)
92 | assert ezsheets.convertToColumnRowInts('ZZ1') == (702, 1)
93 |
94 | assert ezsheets.convertToColumnRowInts('A10') == (1, 10)
95 | assert ezsheets.convertToColumnRowInts('ZZ10') == (702, 10)
96 |
97 | for i in range(1, 1000):
98 | for j in range(101):
99 | assert ezsheets.convertToColumnRowInts(ezsheets.getColumnLetterOf(i) + str(j)) == (i, j)
100 |
101 | with pytest.raises(ValueError):
102 | ezsheets.convertToColumnRowInts('1')
103 | with pytest.raises(ValueError):
104 | ezsheets.convertToColumnRowInts('A')
105 | with pytest.raises(ValueError):
106 | ezsheets.convertToColumnRowInts('')
107 |
108 | with pytest.raises(TypeError):
109 | ezsheets.convertToColumnRowInts(123)
110 |
111 |
112 | def test__getTabColorArg():
113 | RED_COLOR = {'red': 1.0, 'green': 0.0, 'blue': 0.0, 'alpha': 1.0}
114 | assert ezsheets._getTabColorArg('red') == RED_COLOR
115 | assert ezsheets._getTabColorArg((1.0, 0.0, 0.0)) == RED_COLOR
116 | assert ezsheets._getTabColorArg((1.0, 0.0, 0.0, 1.0)) == RED_COLOR
117 | assert ezsheets._getTabColorArg((1.0, 0.0, 0.0, 1.0)) == RED_COLOR
118 | assert ezsheets._getTabColorArg([1.0, 0.0, 0.0]) == RED_COLOR
119 |
120 | with pytest.raises(ValueError):
121 | ezsheets._getTabColorArg('invalid value')
122 |
123 |
124 | @pytest.fixture(scope='module')
125 | def init():
126 | global TEST_SS
127 | ezsheets.init()
128 |
129 | # Create a new spreadsheet
130 | TEST_SS = ezsheets.createSpreadsheet(title='Delete Me')
131 | # Use an existing spreadsheet:
132 | #TEST_SS = ezsheets.Spreadsheet('https://docs.google.com/spreadsheets/d/1lRyPHuaLIgqYwkCTJYexbZUO1dcWeunm69B0L7L4ZQ8/edit#gid=0')
133 |
134 | tempName = 'temp_%s' % (random.sample('abcdefg'*10, 10))
135 | TEST_SS.createSheet(tempName, index=0)
136 | while len(TEST_SS) > 1:
137 | del TEST_SS[1]
138 | TEST_SS.createSheet('Sheet1', index=0)
139 | del TEST_SS[tempName]
140 |
141 | checkIfSpreadsheetInOriginalState()
142 |
143 |
144 | def test_Spreadsheet_url(init):
145 | assert TEST_SS.url == 'https://docs.google.com/spreadsheets/d/' + TEST_SS.spreadsheetId + '/'
146 |
147 |
148 | def test_Spreadsheet_attr(init, checkPreAndPostCondition):
149 | assert TEST_SS.title == 'Delete Me'
150 | assert TEST_SS.spreadsheetId != ''
151 | assert TEST_SS.sheetTitles == ('Sheet1',)
152 | assert len(TEST_SS) == 1
153 |
154 | assert TEST_SS.spreadsheetId == TEST_SS.id
155 |
156 |
157 | def test_createSheet_deleteSheet(init, checkPreAndPostCondition):
158 | newSheet1 = TEST_SS.createSheet(title='New Sheet 1')
159 |
160 | assert 'New Sheet 1' in TEST_SS.sheetTitles
161 | assert newSheet1 == TEST_SS.sheets[1]
162 | assert newSheet1.title == 'New Sheet 1'
163 | assert newSheet1.index == 1
164 |
165 | newSheet2 = TEST_SS.createSheet(title='New Sheet 2', index=1)
166 | assert newSheet2 == TEST_SS.sheets[1]
167 | assert newSheet2.index == 1
168 | assert newSheet1 == TEST_SS.sheets[2]
169 | assert newSheet1.index == 2
170 |
171 | newSheet1.delete()
172 | newSheet2.delete()
173 |
174 |
175 | def test_getitem_delitem(init, checkPreAndPostCondition):
176 | assert TEST_SS['Sheet1'].title == 'Sheet1'
177 |
178 | # Attempt get with invalid index:
179 | with pytest.raises(KeyError):
180 | TEST_SS[99]
181 | with pytest.raises(KeyError):
182 | TEST_SS[-99]
183 | with pytest.raises(KeyError):
184 | TEST_SS['nonexistent title']
185 | with pytest.raises(KeyError):
186 | TEST_SS[['invalid', 'key', 'type']]
187 |
188 | # Attempt delete with invalid index:
189 | with pytest.raises(KeyError):
190 | del TEST_SS[99]
191 | with pytest.raises(KeyError):
192 | del TEST_SS[-99]
193 | with pytest.raises(KeyError):
194 | del TEST_SS['nonexistent title']
195 | with pytest.raises(TypeError):
196 | del TEST_SS[['invalid', 'key', 'type']]
197 |
198 | newSheet = TEST_SS.createSheet(title='Added Sheet')
199 | assert TEST_SS[1] == newSheet # Get by int index.
200 | assert TEST_SS[-1] == newSheet # Get by negative index.
201 | assert TEST_SS[1].title == 'Added Sheet'
202 |
203 | assert TEST_SS[1:2] == (newSheet,) # Get by slice
204 |
205 | # Delete by int index:
206 | del TEST_SS[1]
207 | checkIfSpreadsheetInOriginalState()
208 |
209 | TEST_SS.createSheet(title='Added Sheet 2')
210 | # Get by str title:
211 | assert TEST_SS['Added Sheet 2'].title == 'Added Sheet 2'
212 |
213 | # Delete by str title:
214 | del TEST_SS['Added Sheet 2']
215 | checkIfSpreadsheetInOriginalState()
216 |
217 | # Get multiple sheets with slice:
218 | newSheet3 = TEST_SS.createSheet(title='Added Sheet 3')
219 | newSheet4 = TEST_SS.createSheet(title='Added Sheet 4')
220 | assert TEST_SS[1:3] == (newSheet3, newSheet4)
221 |
222 | # Delete multiple sheets with slice:
223 | del TEST_SS[1:3] # deleting newSheet3 and newSheet4
224 | checkIfSpreadsheetInOriginalState()
225 |
226 | TEST_SS.createSheet(title='Added Sheet 5')
227 | TEST_SS.createSheet(title='Added Sheet 6')
228 | del TEST_SS[1:] # deleting newSheet5 and newSheet6
229 | checkIfSpreadsheetInOriginalState()
230 |
231 | TEST_SS.createSheet(title='Added Sheet 7', index=0)
232 | TEST_SS.createSheet(title='Added Sheet 8', index=1)
233 | del TEST_SS[:2]
234 | checkIfSpreadsheetInOriginalState()
235 |
236 | TEST_SS.createSheet(title='Added Sheet 9')
237 | TEST_SS.createSheet(title='Added Sheet 10')
238 | del TEST_SS[3:0:-1]
239 | checkIfSpreadsheetInOriginalState()
240 |
241 | # Attempt to delete all sheets:
242 | with pytest.raises(ValueError):
243 | del TEST_SS[0]
244 |
245 | # Attempt to delete all sheets:
246 | with pytest.raises(ValueError):
247 | del TEST_SS[0:1]
248 |
249 | # Deleting with negative start or stop in slice is a no-op
250 | del TEST_SS[-1:]
251 | del TEST_SS[:-1]
252 |
253 |
254 | def test_len(init, checkPreAndPostCondition):
255 | # The length of a Spreadsheet object is how many Sheet objects it contains.
256 | assert len(TEST_SS) == len(TEST_SS.sheets)
257 | TEST_SS.createSheet(title='Length Test Sheet')
258 | assert len(TEST_SS) == len(TEST_SS.sheets)
259 | del TEST_SS[-1]
260 | assert len(TEST_SS) == len(TEST_SS.sheets)
261 |
262 |
263 | def test_changeSheetIndex(init, checkPreAndPostCondition):
264 | newSheet1 = TEST_SS.createSheet(title='New Sheet 1')
265 | newSheet2 = TEST_SS.createSheet(title='New Sheet 2')
266 |
267 | assert TEST_SS.sheetTitles == ('Sheet1', 'New Sheet 1', 'New Sheet 2')
268 |
269 | # Move 'New Sheet 2' to front:
270 |
271 | newSheet2.index = 0 # LEFT OFF with error happening here, some quota issue? Am I just making too many calls with this test suite?
272 | assert newSheet2.index == 0
273 | assert TEST_SS[0] == newSheet2
274 | assert TEST_SS.sheetTitles == ('New Sheet 2', 'Sheet1', 'New Sheet 1')
275 |
276 | newSheet2.index = 1
277 | assert newSheet2.index == 1
278 | assert TEST_SS[1] == newSheet2
279 | assert TEST_SS[1].title == 'New Sheet 2'
280 | assert TEST_SS.sheetTitles == ('Sheet1', 'New Sheet 2', 'New Sheet 1')
281 |
282 | newSheet1.index = 1
283 | assert newSheet1.index == 1
284 | assert TEST_SS[1] == newSheet1
285 | assert TEST_SS[1].title == 'New Sheet 1'
286 | assert TEST_SS.sheetTitles == ('Sheet1', 'New Sheet 1', 'New Sheet 2')
287 |
288 | # Test no change to index:
289 | newSheet1.index = 1
290 | assert newSheet1.index == 1
291 | assert TEST_SS[1] == newSheet1
292 | assert TEST_SS[1].title == 'New Sheet 1'
293 | assert TEST_SS.sheetTitles == ('Sheet1', 'New Sheet 1', 'New Sheet 2')
294 |
295 | # Test negative index:
296 | newSheet1.index = -1
297 | assert newSheet1.index == 2
298 | assert TEST_SS[2] == newSheet1
299 | assert TEST_SS[2].title == 'New Sheet 1'
300 | assert TEST_SS.sheetTitles == ('Sheet1', 'New Sheet 2', 'New Sheet 1')
301 |
302 | # Check setting to invalid index:
303 | with pytest.raises(TypeError):
304 | TEST_SS[0].index = 1.0
305 | with pytest.raises(IndexError):
306 | TEST_SS[0].index = 9999
307 | with pytest.raises(IndexError):
308 | TEST_SS[0].index = -9999
309 |
310 | newSheet1.delete()
311 | newSheet2.delete()
312 |
313 |
314 | def test_iter(init, checkPreAndPostCondition):
315 | TEST_SS.createSheet(title='New Sheet 1')
316 | TEST_SS.createSheet(title='New Sheet 2')
317 |
318 | for i, sheet in enumerate(TEST_SS):
319 | if i == 0:
320 | assert sheet.title == 'Sheet1'
321 | elif i == 1:
322 | assert sheet.title == 'New Sheet 1'
323 | elif i == 2:
324 | assert sheet.title == 'New Sheet 2'
325 |
326 | del TEST_SS[1] # delete New Sheet 1
327 | del TEST_SS[1] # delete New Sheet 2
328 | checkIfSpreadsheetInOriginalState()
329 |
330 |
331 | def test_str_spreadsheet(init, checkPreAndPostCondition):
332 | assert str(TEST_SS) == ''
333 |
334 |
335 | def test_repr_spreadsheet(init, checkPreAndPostCondition):
336 | assert repr(TEST_SS) == 'Spreadsheet(spreadsheetId=%r)' % (TEST_SS.spreadsheetId)
337 |
338 |
339 | def test_title_spreadsheet(init, checkPreAndPostCondition):
340 | assert TEST_SS.title == 'Delete Me'
341 | TEST_SS.title = 'New Title'
342 | assert TEST_SS.title == 'New Title'
343 | TEST_SS.refresh()
344 | assert TEST_SS.title == 'New Title'
345 | TEST_SS.title = 'Delete Me'
346 | checkIfSpreadsheetInOriginalState()
347 |
348 |
349 | def test_title_sheet(init, checkPreAndPostCondition):
350 | assert TEST_SS[0].title == 'Sheet1'
351 | TEST_SS[0].title = 'New Title'
352 | assert TEST_SS[0].title == 'New Title'
353 | TEST_SS.refresh()
354 | assert TEST_SS[0].title == 'New Title'
355 | TEST_SS[0].title = 'Sheet1'
356 | checkIfSpreadsheetInOriginalState()
357 |
358 |
359 | def test_spreadsheet_attr(init, checkPreAndPostCondition):
360 | assert TEST_SS[0].spreadsheet == TEST_SS
361 |
362 |
363 | def test_tabColor(init, checkPreAndPostCondition):
364 | newSheet = TEST_SS.createSheet(title='New Sheet 1')
365 | newSheet.tabColor = 'red'
366 | assert newSheet.tabColor == {'red': 1.0, 'green': 0.0, 'blue': 0.0, 'alpha': 1.0}
367 | TEST_SS.refresh()
368 | assert newSheet.tabColor == {'red': 1.0, 'green': 0.0, 'blue': 0.0, 'alpha': 1.0}
369 |
370 | newSheet.tabColor = {'red': 0.0, 'green': 1.0, 'blue': 0.0, 'alpha': 1.0}
371 | assert newSheet.tabColor == {'red': 0.0, 'green': 1.0, 'blue': 0.0, 'alpha': 1.0}
372 |
373 | newSheet.delete()
374 |
375 |
376 | def test_eq(init, checkPreAndPostCondition):
377 | assert TEST_SS[0] == TEST_SS[0]
378 | assert TEST_SS[0] != 'some misc value'
379 |
380 |
381 | def test_sheet_attrs(init, checkPreAndPostCondition):
382 | sheet1 = TEST_SS[0]
383 | assert sheet1.rowCount == 1000
384 | assert sheet1.columnCount == 26
385 | assert sheet1.frozenRowCount == 0
386 | assert sheet1.frozenColumnCount == 0
387 | assert sheet1.hideGridlines == False
388 | assert sheet1.rowGroupControlAfter == False
389 | assert sheet1.columnGroupControlAfter == False
390 |
391 |
392 | def test_str_sheet(init, checkPreAndPostCondition):
393 | assert str(TEST_SS[0]) == '' % (TEST_SS[0].sheetId)
394 |
395 |
396 | def test_repr_sheet(init, checkPreAndPostCondition):
397 | assert repr(TEST_SS[0]) == "" % (TEST_SS[0].sheetId)
398 |
399 |
400 | def test_updateRows(init, checkPreAndPostCondition):
401 | newSheet = TEST_SS.createSheet(title='New Sheet 1', columnCount=5, rowCount=4)
402 |
403 | newSheet.updateRows([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']])
404 | assert newSheet.getRows() == [['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', ''], ['', '', '', '', '']]
405 | assert newSheet.getRows(startRow=2) == [['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', ''], ['', '', '', '', '']]
406 | assert newSheet.getRows(stopRow=4) == [['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', '']]
407 | assert newSheet.getRows(startRow=2, stopRow=4) == [['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', '']]
408 |
409 | newSheet.clear()
410 | newSheet.updateRows([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']], startRow=2)
411 | assert newSheet.getRows() == [['', '', '', '', ''], ['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', '']]
412 | assert newSheet.getRows(startRow=2) == [['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', '']]
413 | assert newSheet.getRows(stopRow=4) == [['', '', '', '', ''], ['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', '']]
414 | assert newSheet.getRows(startRow=2, stopRow=4) == [['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', '']]
415 |
416 | newSheet.clear()
417 | newSheet.resize(columnCount=4, rowCount=5)
418 |
419 | newSheet.updateRows([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']])
420 | assert newSheet.getRows() == [['a', 'b', 'c', ''], ['d', 'e', 'f', ''], ['g', 'h', 'i', ''], ['', '', '', ''], ['', '', '', '']]
421 | assert newSheet.getRows(startRow=2) == [['d', 'e', 'f', ''], ['g', 'h', 'i', ''], ['', '', '', ''], ['', '', '', '']]
422 | assert newSheet.getRows(stopRow=4) == [['a', 'b', 'c', ''], ['d', 'e', 'f', ''], ['g', 'h', 'i', '']]
423 | assert newSheet.getRows(startRow=2, stopRow=4) == [['d', 'e', 'f', ''], ['g', 'h', 'i', '']]
424 |
425 | newSheet.clear()
426 | newSheet.updateRows([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']], startRow=2)
427 | assert newSheet.getRows() == [['', '', '', ''], ['a', 'b', 'c', ''], ['d', 'e', 'f', ''], ['g', 'h', 'i', ''], ['', '', '', '']]
428 | assert newSheet.getRows(startRow=2) == [['a', 'b', 'c', ''], ['d', 'e', 'f', ''], ['g', 'h', 'i', ''], ['', '', '', '']]
429 | assert newSheet.getRows(stopRow=4) == [['', '', '', ''], ['a', 'b', 'c', ''], ['d', 'e', 'f', '']]
430 | assert newSheet.getRows(startRow=2, stopRow=4) == [['a', 'b', 'c', ''], ['d', 'e', 'f', '']]
431 |
432 | # Test invalid argumnets:
433 | with pytest.raises(TypeError):
434 | newSheet.updateRows('not a list or tuple')
435 | with pytest.raises(TypeError):
436 | newSheet.updateRows(['inner value not a list or tuple'])
437 | with pytest.raises(TypeError):
438 | newSheet.updateRows(startRow='invalid arg')
439 | with pytest.raises(TypeError):
440 | newSheet.updateRows(startRow=0)
441 | with pytest.raises(TypeError):
442 | newSheet.updateRows(startRow=9999)
443 |
444 | with pytest.raises(TypeError):
445 | newSheet.getRows(startRow='invalid arg')
446 | with pytest.raises(TypeError):
447 | newSheet.getRows(stopRow='invalid arg')
448 | with pytest.raises(ValueError):
449 | newSheet.getRows(startRow=0)
450 | with pytest.raises(ValueError):
451 | newSheet.getRows(startRow=-9999)
452 | with pytest.raises(ValueError):
453 | newSheet.getRows(stopRow=0)
454 |
455 | newSheet.delete()
456 |
457 |
458 |
459 | def test_updateColumns(init, checkPreAndPostCondition):
460 | newSheet = TEST_SS.createSheet(title='New Sheet 1', columnCount=4, rowCount=5)
461 |
462 | newSheet.updateColumns([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']])
463 | assert newSheet.getColumns() == [['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', ''], ['', '', '', '', '']]
464 | assert newSheet.getColumns(startColumn=2) == [['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', ''], ['', '', '', '', '']]
465 | assert newSheet.getColumns(stopColumn=4) == [['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', '']]
466 | assert newSheet.getColumns(startColumn=2, stopColumn=4) == [['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', '']]
467 |
468 | newSheet.clear()
469 | newSheet.updateColumns([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']], startColumn=2)
470 | assert newSheet.getColumns() == [['', '', '', '', ''], ['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', '']]
471 | assert newSheet.getColumns(startColumn=2) == [['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', ''], ['g', 'h', 'i', '', '']]
472 | assert newSheet.getColumns(stopColumn=4) == [['', '', '', '', ''], ['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', '']]
473 | assert newSheet.getColumns(startColumn=2, stopColumn=4) == [['a', 'b', 'c', '', ''], ['d', 'e', 'f', '', '']]
474 |
475 | newSheet.clear()
476 | newSheet.resize(columnCount=5, rowCount=4)
477 |
478 | newSheet.updateColumns([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']])
479 | assert newSheet.getColumns() == [['a', 'b', 'c', ''], ['d', 'e', 'f', ''], ['g', 'h', 'i', ''], ['', '', '', ''], ['', '', '', '']]
480 | assert newSheet.getColumns(startColumn=2) == [['d', 'e', 'f', ''], ['g', 'h', 'i', ''], ['', '', '', ''], ['', '', '', '']]
481 | assert newSheet.getColumns(stopColumn=4) == [['a', 'b', 'c', ''], ['d', 'e', 'f', ''], ['g', 'h', 'i', '']]
482 | assert newSheet.getColumns(startColumn=2, stopColumn=4) == [['d', 'e', 'f', ''], ['g', 'h', 'i', '']]
483 |
484 | newSheet.clear()
485 | newSheet.updateColumns([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']], startColumn=2)
486 | assert newSheet.getColumns() == [['', '', '', ''], ['a', 'b', 'c', ''], ['d', 'e', 'f', ''], ['g', 'h', 'i', ''], ['', '', '', '']]
487 | assert newSheet.getColumns(startColumn=2) == [['a', 'b', 'c', ''], ['d', 'e', 'f', ''], ['g', 'h', 'i', ''], ['', '', '', '']]
488 | assert newSheet.getColumns(stopColumn=4) == [['', '', '', ''], ['a', 'b', 'c', ''], ['d', 'e', 'f', '']]
489 | assert newSheet.getColumns(startColumn=2, stopColumn=4) == [['a', 'b', 'c', ''], ['d', 'e', 'f', '']]
490 |
491 | # Test invalid argumnets:
492 | with pytest.raises(TypeError):
493 | newSheet.updateColumns('not a list or tuple')
494 | with pytest.raises(TypeError):
495 | newSheet.updateColumns(['inner value not a list or tuple'])
496 | with pytest.raises(TypeError):
497 | newSheet.updateColumns(startRow='invalid arg')
498 | with pytest.raises(TypeError):
499 | newSheet.updateColumns(startRow=0)
500 | with pytest.raises(TypeError):
501 | newSheet.updateColumns(startRow=9999)
502 |
503 | with pytest.raises(TypeError):
504 | newSheet.getColumns(startColumn='invalid arg')
505 | with pytest.raises(TypeError):
506 | newSheet.getColumns(stopColumn='invalid arg')
507 | with pytest.raises(ValueError):
508 | newSheet.getColumns(startColumn=0)
509 | with pytest.raises(ValueError):
510 | newSheet.getColumns(startColumn=-9999)
511 | with pytest.raises(ValueError):
512 | newSheet.getColumns(stopColumn=0)
513 |
514 | newSheet.delete()
515 |
516 |
517 | def test_update_and_get(init, checkPreAndPostCondition):
518 | newSheet = TEST_SS.createSheet(title='New Sheet 1', columnCount=4, rowCount=4)
519 |
520 | # Update a cell with column/row coordinates:
521 | newSheet.update(1, 1, 'new value')
522 | assert newSheet.get(1, 1) == 'new value'
523 |
524 | # Update a cell with A1 coordinates:
525 | newSheet.update('B2', 'b2 value')
526 | assert newSheet.get('B2') == 'b2 value'
527 |
528 | # Update a column:
529 | newSheet.updateColumn(1, ['a', 'b', 'c'])
530 | assert newSheet.getColumn(1) == ['a', 'b', 'c', '']
531 | newSheet.updateColumn(1, ('A', 'B', 'C')) # send tuple instead of list
532 | assert newSheet.getColumn(1) == ['A', 'B', 'C', '']
533 |
534 | # Update a column:
535 | newSheet.updateColumn('C', ['x', 'y', 'z'])
536 | assert newSheet.getColumn('C') == ['x', 'y', 'z', '']
537 |
538 | # Update a row:
539 | newSheet.updateRow(1, ['d', 'e', 'f'])
540 | assert newSheet.getRow(1) == ['d', 'e', 'f', '']
541 | newSheet.updateRow(1, ('D', 'E', 'F')) # send tuple instead of list
542 | assert newSheet.getRow(1) == ['D', 'E', 'F', '']
543 |
544 | # Update all:
545 | newSheet.updateRows([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']])
546 | assert newSheet.getRows() == [['a', 'b', 'c', ''], ['d', 'e', 'f', ''], ['g', 'h', 'i', ''], ['', '', '', '']]
547 |
548 | newSheet.updateColumns([['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']])
549 | assert newSheet.getColumns() == [['a', 'b', 'c', ''], ['d', 'e', 'f', ''], ['g', 'h', 'i', ''], ['', '', '', '']]
550 |
551 | # Get a cell that is outside the original range of the rowCount and columnCount
552 | assert newSheet.get(9999, 1) == ''
553 | assert newSheet.get(1, 9999) == ''
554 | assert newSheet.get(9999, 9999) == ''
555 |
556 | # TODO test enlarging the sheet with an update*() call.
557 |
558 | # Test with invalid coordinate.
559 | with pytest.raises(TypeError):
560 | newSheet.get(1, 2, 3, 4, 5) # Test with too many arguments.
561 | with pytest.raises(TypeError):
562 | newSheet.get() # Test with too few arguments.
563 | with pytest.raises(TypeError):
564 | newSheet.get(4.2, 1) # Test with wrong argument type.
565 | with pytest.raises(TypeError):
566 | newSheet.get(1, 4.2) # Test with wrong argument type.
567 |
568 | with pytest.raises(TypeError):
569 | newSheet.update(1, 1) # Test with missing update value.
570 | with pytest.raises(TypeError):
571 | newSheet.update(1, 2, 3, 4, 5) # Test with too many arguments.
572 | with pytest.raises(TypeError):
573 | newSheet.update() # Test with too few arguments.
574 | with pytest.raises(TypeError):
575 | newSheet.update(4.2, 1) # Test with wrong argument type.
576 | with pytest.raises(TypeError):
577 | newSheet.update(1, 4.2) # Test with wrong argument type.
578 |
579 | # Test with bad indexes
580 | with pytest.raises(IndexError):
581 | newSheet.get(-1, 1) # Test with wrong argument type.
582 | with pytest.raises(IndexError):
583 | newSheet.get(1, -1) # Test with wrong argument type.
584 |
585 | with pytest.raises(IndexError):
586 | newSheet.update(-1, 1, 'value') # Test with wrong argument type.
587 | with pytest.raises(IndexError):
588 | newSheet.update(1, -1, 'value') # Test with wrong argument type.
589 | with pytest.raises(TypeError):
590 | newSheet.update('invalid', 1, 'value') # Test with wrong argument type.
591 | with pytest.raises(TypeError):
592 | newSheet.update(1, 'invalid', 'value') # Test with wrong argument type.
593 |
594 |
595 | # Test getRow() and getColumn() with invalid arguments.
596 | with pytest.raises(TypeError):
597 | newSheet.getRow('invalid arg')
598 | with pytest.raises(IndexError):
599 | newSheet.getRow(0)
600 | with pytest.raises(IndexError):
601 | newSheet.getRow(-9999)
602 | with pytest.raises(TypeError):
603 | newSheet.getColumn({})
604 | with pytest.raises(ValueError):
605 | newSheet.getColumn('AAAAinvalid arg')
606 | with pytest.raises(IndexError):
607 | newSheet.getColumn(0)
608 | with pytest.raises(IndexError):
609 | newSheet.getColumn(-9999)
610 |
611 | newSheet.delete()
612 |
613 |
614 | def test_sheet_getitem_setitem(init, checkPreAndPostCondition):
615 | newSheet = TEST_SS.createSheet(title='New Sheet 1', columnCount=4, rowCount=4)
616 |
617 | # Update a cell with column/row coordinates:
618 | newSheet[1, 1] = 'new value'
619 | assert newSheet[1, 1] == 'new value'
620 |
621 | # Update a cell with A1 coordinates:
622 | newSheet['B2'] = 'b2 value'
623 | assert newSheet['B2'] == 'b2 value'
624 |
625 | # Get a cell that is outside the original range of the rowCount and columnCount
626 | assert newSheet[9999, 1] == ''
627 | assert newSheet[1, 9999] == ''
628 | assert newSheet[9999, 9999] == ''
629 |
630 | # TODO test enlarging the sheet with an update*() call.
631 |
632 | # Test with invalid coordinate.
633 | with pytest.raises(TypeError):
634 | newSheet[1, 2, 3, 4, 5] # Test with too many arguments.
635 | with pytest.raises(TypeError):
636 | newSheet[1] # Test with too few arguments.
637 | with pytest.raises(TypeError):
638 | newSheet[4.2, 1] # Test with wrong argument type.
639 | with pytest.raises(TypeError):
640 | newSheet[1, 4.2] # Test with wrong argument type.
641 |
642 | with pytest.raises(TypeError):
643 | newSheet[1, 2, 3, 4] = 5 # Test with too many arguments.
644 | with pytest.raises(TypeError):
645 | newSheet[4.2, 1] = 5 # Test with wrong argument type.
646 | with pytest.raises(TypeError):
647 | newSheet[1, 4.2] = 5 # Test with wrong argument type.
648 |
649 | # Test with bad indexes
650 | with pytest.raises(IndexError):
651 | newSheet[-1, 1] # Test with wrong argument type.
652 | with pytest.raises(IndexError):
653 | newSheet[1, -1] # Test with wrong argument type.
654 |
655 | with pytest.raises(IndexError):
656 | newSheet[-1, 1] = 'value' # Test with wrong argument type.
657 | with pytest.raises(IndexError):
658 | newSheet[1, -1] = 'value' # Test with wrong argument type.
659 | with pytest.raises(TypeError):
660 | newSheet['invalid', 1] = 'value' # Test with wrong argument type.
661 | with pytest.raises(TypeError):
662 | newSheet[1, 'invalid'] = 'value' # Test with wrong argument type.
663 |
664 | newSheet.delete()
665 |
666 |
667 | def test_gridProperties_settersGetters(init, checkPreAndPostCondition):
668 | # Test rowCount
669 | sheet = TEST_SS[0]
670 |
671 | # Test setters and getters:
672 | sheet.rowCount = 10
673 | assert sheet.rowCount == 10
674 |
675 | # Test invalid arguments:
676 | with pytest.raises(TypeError):
677 | sheet.rowCount = 'invalid arg'
678 | with pytest.raises(TypeError):
679 | sheet.rowCount = 0
680 | with pytest.raises(TypeError):
681 | sheet.rowCount = -9999
682 |
683 | # Test columnCount
684 | # Test setters and getters:
685 | sheet.columnCount = 10
686 | assert sheet.columnCount == 10
687 |
688 | # Test invalid arguments:
689 | with pytest.raises(TypeError):
690 | sheet.columnCount = 'invalid arg'
691 | with pytest.raises(TypeError):
692 | sheet.columnCount = 0
693 | with pytest.raises(TypeError):
694 | sheet.columnCount = -9999
695 |
696 | # Test frozenRowCount
697 | # Test setters and getters:
698 | sheet.frozenRowCount = 1
699 | assert sheet.frozenRowCount == 1
700 |
701 | # Test invalid arguments:
702 | with pytest.raises(TypeError):
703 | sheet.frozenRowCount = 'invalid arg'
704 | with pytest.raises(TypeError):
705 | sheet.frozenRowCount = 0
706 | with pytest.raises(TypeError):
707 | sheet.frozenRowCount = -9999
708 |
709 | # Test frozenColumnCount
710 | # Test setters and getters:
711 | sheet.frozenColumnCount = 1
712 | assert sheet.frozenColumnCount == 1
713 |
714 | # Test invalid arguments:
715 | with pytest.raises(TypeError):
716 | sheet.frozenColumnCount = 'invalid arg'
717 | with pytest.raises(TypeError):
718 | sheet.frozenColumnCount = 0
719 | with pytest.raises(TypeError):
720 | sheet.frozenColumnCount = -9999
721 |
722 | # Test freezing all rows and columns
723 | with pytest.raises(ValueError):
724 | sheet.rowCount = 1
725 | with pytest.raises(ValueError):
726 | sheet.columnCount = 1
727 | with pytest.raises(ValueError):
728 | sheet.frozenRowCount = 10
729 | with pytest.raises(ValueError):
730 | sheet.frozenColumnCount = 10
731 |
732 | # Test hideGridlines
733 | sheet.hideGridlines = True
734 | assert sheet.hideGridlines == True
735 | sheet.hideGridlines = False
736 | assert sheet.hideGridlines == False
737 | sheet.hideGridlines = 'truthy value'
738 | assert sheet.hideGridlines == True
739 | sheet.hideGridlines = '' # Falsey value
740 | assert sheet.hideGridlines == False
741 |
742 | # Test rowGroupControlAfter
743 | sheet.rowGroupControlAfter = True
744 | assert sheet.rowGroupControlAfter == True
745 | sheet.rowGroupControlAfter = False
746 | assert sheet.rowGroupControlAfter == False
747 | sheet.rowGroupControlAfter = 'truthy value'
748 | assert sheet.rowGroupControlAfter == True
749 | sheet.rowGroupControlAfter = '' # Falsey value
750 | assert sheet.rowGroupControlAfter == False
751 |
752 | # Test columnGroupControlAfter
753 | sheet.columnGroupControlAfter = True
754 | assert sheet.columnGroupControlAfter == True
755 | sheet.columnGroupControlAfter = False
756 | assert sheet.columnGroupControlAfter == False
757 | sheet.columnGroupControlAfter = 'truthy value'
758 | assert sheet.columnGroupControlAfter == True
759 | sheet.columnGroupControlAfter = '' # Falsey value
760 | assert sheet.columnGroupControlAfter == False
761 |
762 |
763 | def test_updateRow_updateColumn(init, checkPreAndPostCondition):
764 | sheet = TEST_SS[0]
765 |
766 | with pytest.raises(TypeError):
767 | sheet.updateRow('invalid', [1, 2, 3])
768 | with pytest.raises(IndexError):
769 | sheet.updateRow(0, [1, 2, 3])
770 | with pytest.raises(TypeError):
771 | sheet.updateRow(1, 'invalid')
772 |
773 | with pytest.raises(TypeError):
774 | sheet.updateColumn(b'123', [1, 2, 3])
775 | with pytest.raises(IndexError):
776 | sheet.updateColumn(0, [1, 2, 3])
777 | with pytest.raises(TypeError):
778 | sheet.updateColumn(1, 'invalid')
779 | with pytest.raises(ValueError):
780 | sheet.updateColumn('123', [1, 2, 3]) # Not a valid column string.
781 |
782 |
783 | def test_resize(init, checkPreAndPostCondition):
784 | sheet = TEST_SS[0]
785 |
786 | # Test no-change resize
787 | sheet.resize()
788 |
789 | sheet.resize(rowCount=10)
790 | assert sheet.rowCount == 10
791 | sheet.resize(columnCount=10)
792 | assert sheet.columnCount == 10
793 |
794 | sheet.resize(columnCount='Z')
795 | assert sheet.columnCount == 26
796 |
797 | with pytest.raises(TypeError):
798 | sheet.resize(rowCount='invalid')
799 | with pytest.raises(TypeError):
800 | sheet.resize(columnCount=3.14)
801 | with pytest.raises(ValueError):
802 | sheet.resize(columnCount='invalid123')
803 |
804 | with pytest.raises(TypeError):
805 | sheet.resize(rowCount=0)
806 | with pytest.raises(TypeError):
807 | sheet.resize(columnCount=0)
808 |
809 |
810 | def test_convertAddress():
811 | assert ezsheets.convertAddress('A2') == (1, 2)
812 | assert ezsheets.convertAddress('B1') == (2, 1)
813 | assert ezsheets.convertAddress(1, 2) == 'A2'
814 | assert ezsheets.convertAddress((1, 2)) == 'A2'
815 | assert ezsheets.convertAddress(2, 1) == 'B1'
816 | assert ezsheets.convertAddress((2, 1)) == 'B1'
817 |
818 | with pytest.raises(TypeError):
819 | ezsheets.convertAddress()
820 | with pytest.raises(ValueError):
821 | ezsheets.convertAddress('A')
822 | with pytest.raises(ValueError):
823 | ezsheets.convertAddress('1')
824 | with pytest.raises(TypeError):
825 | ezsheets.convertAddress(0, 1)
826 | with pytest.raises(TypeError):
827 | ezsheets.convertAddress(1, 0)
828 |
829 | for col in range(1, 1000):
830 | for row in range(1, 101):
831 | assert ezsheets.convertAddress(ezsheets.convertAddress(col, row)) == (col, row)
832 |
833 |
834 |
835 |
836 |
837 | def test_getitem(init, checkPreAndPostCondition):
838 | pass # TODO LEFT OFF
839 |
840 |
841 | def test_restricted_and_link_viewable():
842 | # Restricted spreadsheet:
843 | ezsheets.Spreadsheet('https://docs.google.com/spreadsheets/d/16O3PLFhA8EUH7CdmSeNtxie03kitBfLoi_aOex93WIA/edit#gid=0')
844 |
845 | # Viewable by anyone with the link:
846 | ezsheets.Spreadsheet('https://docs.google.com/spreadsheets/d/1WCKpKAgUjVJv2RM23dc4LHj9mOonK8VsvSXi_U4eqLk/edit#gid=0')
847 |
848 |
849 | def test_eq():
850 | ss1 = ezsheets.Spreadsheet('https://autbor.com/examplegs')
851 | ss2 = ezsheets.Spreadsheet('https://docs.google.com/spreadsheets/d/1TzOJxhNKr15tzdZxTqtQ3EmDP6em_elnbtmZIcyu8vI/')
852 | ss3 = ezsheets.Spreadsheet('1TzOJxhNKr15tzdZxTqtQ3EmDP6em_elnbtmZIcyu8vI')
853 |
854 | other_ss = ezsheets.Spreadsheet('https://docs.google.com/spreadsheets/d/1WCKpKAgUjVJv2RM23dc4LHj9mOonK8VsvSXi_U4eqLk/edit#gid=0')
855 |
856 | assert ss1 == ss2 == ss3
857 | assert ss1 != other_ss
858 |
859 | assert ss1[0].id == ss1[0].sheetId
860 |
861 |
862 |
863 |
864 |
--------------------------------------------------------------------------------
/tox.ini:
--------------------------------------------------------------------------------
1 | # tox (https://tox.readthedocs.io/) is a tool for running tests
2 | # in multiple virtualenvs. This configuration file will run the
3 | # test suite on all supported python versions. To use it, "pip install tox"
4 | # and then run "tox" from this directory.
5 |
6 | [tox]
7 | envlist = py34, py35, py36, py37, py38
8 |
9 | [testenv]
10 | deps =
11 | pytest
12 | commands =
13 | pytest
14 |
--------------------------------------------------------------------------------