sc_crawler.cli
The sc-crawler CLI functions.
Check sc-crawler --help for more details.
Functions:
- create – Print the database schema in a SQL dialect.
- current – Show current database revision.
- upgrade – Upgrade the database schema to a given (default: most recent) revision.
- downgrade – Downgrade the database schema to a given (default: previous) revision.
- stamp – Set the migration revision mark in the database to a specified revision. Set to "heads" if the database schema is up-to-date.
- autogenerate – Autogenerate a migrations script based on the current state of a database.
- metadata_set – Write metadata key/value pairs into the database.
- metadata_get – Print all metadata key/value pairs stored in the database.
- metadata_delete – Delete one or more metadata entries by key.
- hash_command – Print the hash of the content of a database.
- copy – Copy the standard Crawler tables of a database into a blank database.
- sync – Sync a database to another one.
- dump – Export database records to JSONJSON: JavaScript Object NotationA text format for structured data, built from objects (key-value pairs), arrays, strings, numbers, booleans, and null. Most languages and tools read and write it, which makes it a common format for API responses and benchmark output.JSONGlossary files organized by primary keys.
- pull – Pull data from available vendor APIs and store in a database.
- archived_by_command – List the archive rules that archive a record.
func create cli.py:131–170
create(connection_string=None, dialect=None, scd=False)
Print the database schema in a SQL dialect.
Either connection_string or dialect is to be provided to decide
what SQL dialect to use to generate the CREATE TABLE (and related)
SQL statements.
func current cli.py:173–183
current(connection_string='sqlite:///sc-data-all.db', scd=False)
Show current database revision.
func upgrade cli.py:186–198
upgrade(connection_string='sqlite:///sc-data-all.db', revision='heads', scd=False, sql=False)
Upgrade the database schema to a given (default: most recent) revision.
func downgrade cli.py:201–213
downgrade(connection_string='sqlite:///sc-data-all.db', revision='-1', scd=False, sql=False)
Downgrade the database schema to a given (default: previous) revision.
func stamp cli.py:216–228
stamp(connection_string='sqlite:///sc-data-all.db', revision='heads', scd=False, sql=False)
Set the migration revision mark in the database to a specified revision. Set to "heads" if the database schema is up-to-date.
func autogenerate cli.py:231–248
autogenerate(connection_string='sqlite:///sc-data-all.db', message='empty message')
Autogenerate a migrations script based on the current state of a database.
func metadata_set cli.py:251–288
metadata_set(entries=None, connection_string='sqlite:///sc-data-all.db')
Write metadata key/value pairs into the database.
Always sets sc_crawler_version and published_at. When running in a GitHub
Actions workflow, also sets published_by to the GitHub Actions run URLURL: Uniform Resource LocatorThe address of a resource on the web or a network, such as https://sparecores.com/, made of a scheme, a host, and a path.Glossary.
Additional key/value pairs can be passed as positional arguments.
func metadata_get cli.py:299–311
metadata_get(connection_string='sqlite:///sc-data-all.db')
Print all metadata key/value pairs stored in the database.
func metadata_delete cli.py:314–328
metadata_delete(keys, connection_string='sqlite:///sc-data-all.db')
Delete one or more metadata entries by key.
func hash_command cli.py:331–336
hash_command(connection_string='sqlite:///sc-data-all.db')
Print the hash of the content of a database.
func copy cli.py:339–416
copy(source, target, exclude_status=[])
Copy the standard Crawler tables of a database into a blank database.
All rows are copied by default. Use --exclude-status to leave out rows,
e.g. the archived records that are kept only for history. Rows referencing
a left out row (e.g. the zones of an excluded regionregionA geographic area where a cloud vendor runs its data centers, such as Frankfurt or Northern Virginia, made up of one or more availability zones. A server type is offered in some regions only, and its price can differ by region; a region's ID, such as eu-central-1, is unique only within its vendor.Glossary) are also left out.
func sync cli.py:419–674
sync(source, target, dry_run=False, scd=False, sync_tables=table_names, log_changes_path=None, log_changes_tables=table_names)
Sync a database to another one.
Hashing both the source and the target databases, then
comparing hashes and marking for syncing the following records:
-
new (rows with primary keys found in
source, but not found intarget) -
update (rows with different values in
sourceand intarget). -
inactive (rows with primary keys found in
target, but not found insource). Rows already archived intargetare left unchanged, and rows matching an archive rule are marked as archived instead of inactive.
The archive rules (see sc_crawler.archive_rules) are also checked: the
rules of the synced tables referring to records found in neither database
are reported.
The records marked for syncing are written to the target database's
standard or SCD tables. When updating the SCD tables, the hashing still
happens on the standard tables/views, which are probably based on the
most recent records of the SCD tables.
func dump cli.py:677–833
dump(connection_string, output_directory=Path('.'), dump_tables=None, ignored=['observed_at'])
Export database records to JSON files organized by primary keys.
Each record is written as a pretty-printed JSON file in a folder
hierarchy based on the primary key values. For example, a server
record with vendor_id='aws' and server_id='t3.small' would be
written to: output_directory/server/aws/t3.small.json
func pull cli.py:836–1040
pull(connection_string='sqlite:///sc-data-all.db', include_vendor=[v.vendor_id for v in supported_vendors], exclude_vendor=[], include_records=supported_records, exclude_records=[], log_level=LogLevels.INFO, cache=False, cache_ttl=60 * 24)
Pull data from available vendor APIs and store in a database.
As the last step, the archive rules (see sc_crawler.archive_rules) are
stored in the database, and the records they match are marked as archived.
Vendor APIAPI: Application Programming InterfaceA defined set of requests and responses through which one program uses another, such as a web service's HTTP endpoints or a library's functions.WikipediaGlossary calls are optionally cached as Pickle objects in ~/.cachier.
func archived_by_command cli.py:1043–1104
archived_by_command(table_name, primary_key, connection_string='sqlite:///sc-data-all.db')
List the archive rules that archive a record.
Looks up the rules stored in the archive_rule table of the database,
including the removed (inactive) rules and the rules on the parent tables
of the record (e.g. the region of a server price). The first observation
of each rule is read from the archive_rule_scd table, if that exists:
compare it with the first archived version of the record to tell when it
was archived.