-
Notifications
You must be signed in to change notification settings - Fork 52
/
mass_delete_overrides.py
executable file
·36 lines (32 loc) · 1.27 KB
/
mass_delete_overrides.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
import argparse
import csv
import requests
import pdpyras
def main():
parser = argparse.ArgumentParser(description="Deletes overrides listed "\
"in a CSV file. The first column should be the schedule ID and the "\
"second should be the override ID. More columns can be included after "
"the first.")
parser.add_argument('-k', '--api-key', type=str, required=True,
dest='api_key', help="REST API key")
parser.add_argument('-f', '--csv-file', type=argparse.FileType('r'),
dest="csv_file", help="Path to input CSV file. Data should begin in "\
"the very first row; no column names.")
args = parser.parse_args()
session = pdpyras.APISession(args.api_key)
for row in csv.reader(args.csv_file):
schedule_id, override_id = row[:2]
try:
session.rdelete('/schedules/%s/overrides/%s'%(
schedule_id, override_id
))
print("Deleted override "+override_id)
except pdpyras.PDClientError as e:
error = 'Network error'
if e.response is not None:
error = e.response.text
print("Could not delete override %s; %s"%(override_id, error))
continue
if __name__ == '__main__':
main()