Download the PHP package xmlsquad/capture-lookups without Composer
On this page you can find all versions of the php package xmlsquad/capture-lookups. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download xmlsquad/capture-lookups
More information about xmlsquad/capture-lookups
Files in xmlsquad/capture-lookups
Package capture-lookups
Short Description Grabs Google Sheets and stores their data as CSV files
License Apache-2.0
Informations about the package capture-lookups
capture-lookups
A Symfony Console command. Searches for configuration file that lists URLs of Google Sheets, grabs the Sheets and stores their data locally as CSV files.
Designed be used in the context of the Symfony Console application at https://github.com/xmlsquad/xml-authoring-tools which, in turn, is used in the context of a known directory structure which is based on xml-authoring-project.
Usage instructions
Specifying the Lookup tables to collect
We assume this command is run in the context of an xml-authoring-project. ie. the key aspects of the structure of the directory is known.
Use the mapping.yaml configuration file which defines the locations of the Google Sheets we must collect.
Example mapping.yaml
Using the command
- Checkout the repository
- Install dependencies with
composer install - Put a
gApiServiceAccountCredentials.jsonfile in the project root or anywhere in any of the parent directories accessible to PHP - Issue
bin/capture-lookupsto see all available mappings - Issue
bin/capture-lookups --sheet=LookupTableAto run the command interactively - Issue
bin/capture-lookups --sheet=LookupTableA --no-interactionto run the command without any prompts, skipping risky file names or existing files - Issue
bin/capture-lookups --sheet=LookupTableA --no-interaction --forceto run the command without any prompts, overwriting existing files and using sanitised file names
Unit testing
- Install dependencies
- Run
./vendor/bin/phpunit
Skipped Tabs - Naming convention
By Google Sheet tab I mean one of the sheets within a workbook.
Any Google Sheet tab which has a trailing underscore will be considered to be skipped.
foo_is skipped.foois not skipped._foois not skipped either.
Connecting to GSuite
The file that Google Api uses to authenticate access to GSuite should be in the root of the xml-authoring-project.
The ping-drive project explains how to get set up to connect to GSuite.
Run the command
When the command is run, it will:
- Search for the XmlAuthoringProjectSettings.yaml in the current working directory, if not found it will look in the parent recursively until a file named XmlAuthoringProjectSettings.yaml is found.
- Determine the
DestinationDirectoryto write-to:- If
DestinationDirectoryoption is passed to command, use that. - If no
DestinationDirectoryoption is passed to command, set it to the defaultDestinationDirectory(see below). - The default
DestinationDirectoryis the working directory in which the command was invoked.
- If
- For each Lookup table specified in the configuration file:
- Go to the Google Sheet on GSuite
- Determine and note the name of the Google Sheet
- For each tab in that sheet:
- If the tab's name indicates it should be ignored (has a trailing underscore), ignore that tab, skip and move on to the next tab.
- Else, note the tab name
- Combine the Google Sheet name with the tab name to set the resulting CSV file's name:
<GoogleSheetName>-<TabName>.csv. - Check the name to ensure it is made of only alphanumeric characters, dot, hyphen or underscore. (i.e the name is less likely to cause issues if used as a filename on Windows or MacOS)
- If the name contains invalid characters, write a meaningful error message to STD_OUT and STD_ERR and exit with an error code.
- Check to see if a CSV file matching that name is already stored in the destination directory
- If it is already present and the
-f(--force) flag is NOT set, ask user "Permission to overwrite the file y/n?". With the suggested default prompt being no,[n]. - If it is already present and the -f (--force) flag is set, overwrite the existing file without prompting the user.
- Else, create a CSV file with the chosen name.
- Write the contents of the Google Sheet Tab as a CSV file. (comma delimeter, double quotes used to encapsulate strings)
TODO
- Code reuse with
AbstractCommand
All versions of capture-lookups with dependencies
symfony/console Version ^3.4
symfony/filesystem Version ^3.4
symfony/yaml Version ^3.4
google/apiclient Version ^2.0
xmlsquad/xml-authoring-library Version 0.3.3