Skip to content

Instantly share code, notes, and snippets.

@jarvisms
Last active June 15, 2019 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarvisms/708d33a4bf546eb518d419fc258fe2e2 to your computer and use it in GitHub Desktop.
Save jarvisms/708d33a4bf546eb518d419fc258fe2e2 to your computer and use it in GitHub Desktop.
Bulk rename DCS Meters according to a CSV file
# 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:
id = int(id)
meter = dcs.get_meters(id) # Get the current copy (Read-Modify-Write)
backup[meter["id"]] = meter.copy() # Keep a backup
meter["name"] = name # Just edit this, keep all other details the same
meter = dcs.update_meter(meter) # Push it back to the server
print(meter["id"], meter["name"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment