#![allow(unused_assignments)] static USAGE: &str = r#" Fetches data from web services for every row using HTTP Get. Fetch is integrated with `jql` to directly parse out values from an API JSON response. CACHE OPTIONS: Fetch caches responses to minimize traffic and maximize performance. It has four mutually-exclusive caching options: 1. In memory cache (the default) 2. Disk cache 3. Redis cache 4. No cache In memory Cache: In memory cache is the default and is used if no caching option is set. It uses a non-persistent, in-memory, 2 million entry Least Recently Used (LRU) cache for each fetch session. To change the maximum number of entries in the cache, set the --mem-cache-size option. Disk Cache: For persistent, inter-session caching, a DiskCache can be enabled with the --disk-cache flag. By default, it will store the cache in the directory ~/.qsv/cache/fetch, with a cache expiry Time-to-Live (TTL) of 2,419,200 seconds (28 days), and cache hits NOT refreshing the TTL of cached values. Set the --disk-cache-dir option and the environment variables QSV_DISKCACHE_TTL_SECS and QSV_DISKCACHE_TTL_REFRESH to change default DiskCache settings. Redis Cache: Another persistent, inter-session cache option is a Redis cache enabled with the --redis flag. By default, it will connect to a local Redis instance at redis://127.0.0.1:6379/1, with a cache expiry Time-to-Live (TTL) of 2,419,200 seconds (28 days), and cache hits NOT refreshing the TTL of cached values. Set the environment variables QSV_REDIS_CONNSTR, QSV_REDIS_TTL_SECONDS and QSV_REDIS_TTL_REFRESH to change default Redis settings. If you don't want responses to be cached at all, use the --no-cache flag. NETWORK OPTIONS: Fetch recognizes RateLimit and Retry-After headers and dynamically throttles requests to be as fast as allowed. The --rate-limit option sets the maximum number of queries per second (QPS) to be made. The default is 0, which means to go as fast as possible, automatically throttling as required. To use a proxy, set the environment variables HTTP_PROXY, HTTPS_PROXY or ALL_PROXY (e.g. export HTTPS_PROXY=socks5://127.0.0.1:1086). qsv fetch supports brotli, gzip and deflate automatic decompression for improved throughput and performance, preferring brotli over gzip over deflate. It automatically upgrades its connection to the much faster and more efficient HTTP/2 protocol with adaptive flow control if the server supports it. See https://www.cloudflare.com/learning/performance/http2-vs-http1.1/ and https://medium.com/coderscorner/http-2-flow-control-77e54f7fd518 for more info. URL OPTIONS: needs to be a fully qualified URL path. Alternatively, you can dynamically construct URLs for each CSV record with the --url-template option (see Examples below). EXAMPLES USING THE URL-COLUMN ARGUMENT: data.csv URL https://api.zippopotam.us/us/90210 https://api.zippopotam.us/us/94105 https://api.zippopotam.us/us/92802 Given the data.csv above, fetch the JSON response. $ qsv fetch URL data.csv Note the output will be a JSONL file - with a minified JSON response per line, not a CSV file. Now, if we want to generate a CSV file with the parsed City and State, we use the new-column and jql options. (See https://github.com/yamafaktory/jql#%EF%B8%8F-usage for more info on how to use the jql JSON Query Language) $ qsv fetch URL --new-column CityState --jql '"places"[0]"place name","places"[0]"state abbreviation"' data.csv > data_with_CityState.csv data_with_CityState.csv URL, CityState, https://api.zippopotam.us/us/90210, "[\"Beverly Hills\",\"CA\"]" https://api.zippopotam.us/us/94105, "[\"San Francisco\",\"CA\"]" https://api.zippopotam.us/us/92802, "[\"Anaheim\",\"CA\"]" As you can see, entering jql selectors on the command line is error prone and can quickly become cumbersome. Alternatively, the jql selector can be saved and loaded from a file using the --jqlfile option. $ qsv fetch URL --new-column CityState --jqlfile places.jql data.csv > datatest.csv EXAMPLES USING THE --URL-TEMPLATE OPTION: Instead of using hardcoded URLs, you can also dynamically construct the URL for each CSV row using CSV column values in that row. Exanple 1: For example, we have a CSV with four columns and we want to geocode against the geocode.earth API that expects latitude and longitude passed as URL parameters. addr_data.csv location, description, latitude, longitude Home, "house is not a home when there's no one there", 40.68889829703977, -73.99589368107037 X, "marks the spot", 40.78576117777992, -73.96279560368552 work, "moolah", 40.70692672280804, -74.0112264146281 school, "exercise brain", 40.72916494539206, -73.99624185993626 gym, "exercise muscles", 40.73947342617386, -73.99039923885411 Geocode addresses in addr_data.csv, pass the latitude and longitude fields and store the response in a new column called response into enriched_addr_data.csv. $ qsv fetch --url-template "https://api.geocode.earth/v1/reverse?point.lat={latitude}&point.lon={longitude}" addr_data.csv -c response > enriched_addr_data.csv Example 2: Geocode addresses in addresses.csv, pass the "street address" and "zip-code" fields and use jql to parse placename from the JSON response into a new column in addresses_with_placename.csv. Note how field name non-alphanumeric characters (space and hyphen) in the url-template were replaced with _. $ qsv fetch --jql '"features"[0]"properties","name"' addresses.csv -c placename --url-template "https://api.geocode.earth/v1/search/structured?address={street_address}&postalcode={zip_code}" > addresses_with_placename.csv USING THE HTTP-HEADER OPTION: The --http-header option allows you to append arbitrary key value pairs (a valid pair is a key and value separated by a colon) to the HTTP header (to authenticate against an API, pass custom header fields, etc.). Note that you can pass as many key-value pairs by using --http-header option repeatedly. For example: $ qsv fetch URL data.csv --http-header "X-Api-Key:TEST_KEY" -H "X-Api-Secret:ABC123XYZ" -H "Accept-Language: fr-FR" For more extensive examples, see https://github.com/jqnatividad/qsv/blob/master/tests/test_fetch.rs. Usage: qsv fetch [ | --url-template