-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdelete-api-key.py
executable file
·57 lines (50 loc) · 1.5 KB
/
delete-api-key.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!python3
# delete-api-key.py
import getopt
from cal_settings import cal_api_key_table_name,cal_api_key_columns,cal_api_key_columns,select_column_with_cursor, cal_api_key_table_primary_key
from mysql_db import get_mysql_connection, close_connection,insert_or_update_db_row_cursor ,insert_csv_list_to_db, delete_row_with_cursor
import sys
debug = False
def usage():
print(sys.argv[0]+" [-h] | publisher_id [ publisher_id ]")
try:
opts, args = getopt.getopt(sys.argv[1:], "Dh")
except getopt.GetoptError as err:
# print help information and exit:
print(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
output = None
for o, a in opts:
if o == "-D":
debug = True
elif o in ("-h", "--help"):
usage()
sys.exit()
else:
assert False, "unhandled option"
auth_table = cal_api_key_table_name()
where_column = cal_api_key_table_primary_key()
db_conn = get_mysql_connection()
if db_conn == None:
print("Error cannot connect to MySQL database")
cursor = db_conn.cursor()
if len(args) == 0:
columns = ",".join(cal_api_key_columns() )
data = select_column_with_cursor(cursor,auth_table,columns)
if data == None or len(data) == 0:
print("no data in table")
else:
for item in data:
print(item[0],":",item[1])
else:
# iterate args and delete from DB
for value in args:
if debug == True:
print(id," : ",key)
result = delete_row_with_cursor(cursor,auth_table,where_column,value,debug=False)
db_conn.commit()
if debug == True:
print(data)
cursor.close()
db_conn.close()