Skip to main content

Tools we use at Somenergia and can be useful

Project description

This module includes different Python modules and scripts ubiquiously used on scripts in SomEnergia cooperative but with no entity by themselves to have their own repository.

  • venv: run a command under a Python virtual enviroment

  • sql2csv.py: script to run parametrized sql queries and get the result as (tab separated) csv.

  • dbutils.py: module with db related functions

    • fetchNs: a generator that wraps db cursors to fetch objects with attributes instead of psycopg arrays

    • nsList: uses the former to build a list of such object (slower but maybe convinient)

    • csvTable: turns the results of a query into a tab separated table with proper header names

  • sheetfetcher.py: convenience class to retrieve data from gdrive spreadshets

venv script

This script is useful to run Python scripts under a given virtual environment. It is specially useful to run Python scripts from crontab lines.

usage: venv /PATH/TO/PYTHON/VIRTUALENV COMMAND [PARAM1 [PARAM2...]]

sql2csv.py script

Runs an SQL file and outputs the result of the query as tabulator separated csv.a

You can provide query parameters either as yamlfile or as commandline options.

sql2csv.py <sqlfile> [<yamlfile>] [--<var1> <value1> [--<var2> <value2> ..] ]

dbutils Python module

Convenient cursor wrappers to make the database access code more readable.

Example:

import psycopg2, dbutils
db = psycopg2.connect(**dbconfiguration)
with db.cursor() as cursor :
    cursor.execute("SELECT name, age FROM people")
    for person as dbutils.fetchNs(cursor):
        if person.age < 21: continue
        print("{name} is {age} years old".format(person))

sheetfetcher Python module

Convenient wraper for gdrive.

from sheetfetcher import SheetFetcher

fetcher = SheetFetcher(
    documentName='My Document',
    credentialFilename='drive-certificate.json',
    )
table = fetcher.get_range("My Sheet", "A2:F12")
fulltable = fetcher.get_fullsheet("My Sheet")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

somutils-1.3.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file somutils-1.3.tar.gz.

File metadata

  • Download URL: somutils-1.3.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for somutils-1.3.tar.gz
Algorithm Hash digest
SHA256 bdf853f64e22d942f61406ff297dd03b16a21b9d7f59df17655e04d1d2d711ef
MD5 67f5d1022e44e4b6fb7e292bb13beb1f
BLAKE2b-256 e9caa0ba5c9bf59d5d390f0275b8ca49edd50662ce29b38b75fa265e8b889cd8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page