Last active
June 15, 2019 20:21
-
-
Save jarvisms/708d33a4bf546eb518d419fc258fe2e2 to your computer and use it in GitHub Desktop.
Bulk rename DCS Meters according to a CSV file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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