Skip to content

Instantly share code, notes, and snippets.

Mark Jarvis jarvisms

View GitHub Profile
@jarvisms
jarvisms / getSQLdata.py
Created Feb 28, 2020
pywws sqlite3 direct data access
View getSQLdata.py
import sqlite3
from datetime import datetime
# Connect directly with the database file and make a "connection" object
conn = sqlite3.connect(r"/home/pywws/weather-data/pywws.db")
start = datetime(2020,1,1).timestamp() # Timestamp in seconds 1577836800.0
end = datetime(2020,2,1).timestamp() # Timestamp in seconds 1580515200.0
# SQL query with named variables :start and :end which are supplied by a dictionary and substituted in place.
@jarvisms
jarvisms / buster-full-packages
Created Jun 30, 2019
Lists of packages installed in Rasbian Buster 2019-06-20
View buster-full-packages
Listing...
adduser/now 3.118 all [installed,local]
adwaita-icon-theme/now 3.30.1-1 all [installed,local]
alacarte/now 3.11.91-4+rpt1 all [installed,local]
alsa-base/now 1.0.27+1 all [installed,local]
alsa-utils/now 1.1.8-2 armhf [installed,local]
ant-contrib/now 1.0~b3+svn177-10 all [installed,local]
ant-optional/now 1.10.5-2 all [installed,local]
ant/now 1.10.5-2 all [installed,local]
apparmor/now 2.13.2-10 armhf [installed,local]
View DCSBulkMeterDetails.py
import pythondcs # From https://github.com/jarvisms/pythondcs
import csv # Standard Library
dcs = pythondcs.DCSSession(DCSURL,USERNAME,PASSWORD) # Credentials as needed
targets = [123,456,789] # List of meters you want details for
with open(r"MetersDetails.csv", "w", newline="") as outputcsv: # Adjust file as needed
csvwriter = csv.writer(outputcsv)
for id in targets:
meter = dcs.get_meters(id)
@jarvisms
jarvisms / PruneBackups.py
Last active Nov 5, 2019
rsync incremental backup time machine to remote server of entire root tree
View PruneBackups.py
#!/usr/bin/env python3
import datetime
import os
import os.path
import shutil
def striptime(dt):
try:
return datetime.datetime.strptime(dt,"%Y-%m-%dT%H-%M-%S") # Convert it
except ValueError: # If it doesn't look like a date, return None (boolean False)
@jarvisms
jarvisms / DCSBulkMeterRename.py
Last active Jun 15, 2019
Bulk rename DCS Meters according to a CSV file
View DCSBulkMeterRename.py
# Note this uses advanced (and unsupported) features, hence pythondcsPRO
import pythondcspro as pythondcs # From https://github.com/jarvisms/pythondcs
import csv # Standard Library
dcs = pythondcs.DCSSession(DCSURL,USERNAME,PASSWORD) # Credentials as needed
backup={} # Keep original copies as backup
with open("input.csv", newline="") as inputcsv: # Adjust file as needed
# File format is literally just "<id>,<name>" on each row
csvreader = csv.reader(inputcsv)
for id,name in csvreader:
@jarvisms
jarvisms / DCStoCSV.py
Last active May 1, 2019
Downloading DCS meter readings to a CSV file
View DCStoCSV.py
import pythondcs # From https://github.com/jarvisms/pythondcs
import csv # Standard Library
from datetime import date
dcs = pythondcs.DCSSession(DCSURL,USERNAME,PASSWORD) # Credentials as needed
targetmeters = [123,456,789] # List as many IDs as you need. In this case all assumed to be registers.
with open("output.csv", "w", newline="") as outputcsv: # Adjust file as needed
csvwriter = csv.writer(outputcsv)
### Output in "Periodic Channel Export" format as needed to import into TEAM Sigma aM&T software, coloumns are:
You can’t perform that action at this time.