forked from fnux/rt2zammad
[rt2zammad] update range and except duplicated ticket
This commit is contained in:
parent
e3c375a29e
commit
06b42d042b
2 changed files with 11 additions and 2 deletions
|
@ -169,7 +169,6 @@ def create_zammad_ticket(id, zammad, h2t, retries=3):
|
|||
zammad_ticket = zammad.ticket.create(zammad_ticket_template)
|
||||
|
||||
print(f"Created Zammad ticket {zammad_ticket['id']} for {label}")
|
||||
|
||||
if rt_ticket["ticket"]["Owner"] and rt_ticket["ticket"]["Owner"] != "Nobody":
|
||||
zammad_owner_id = maybe_create_zammad_user(rt_ticket["ticket"]["Owner"], zammad, "id")
|
||||
zammad.ticket.update(
|
||||
|
@ -281,6 +280,9 @@ if not os.path.exists("rt2zammad.json"):
|
|||
with open("rt2zammad.json") as handle:
|
||||
config = json.load(handle)
|
||||
|
||||
rt_start = config["rt_start"]
|
||||
rt_end = config["rt_end"]
|
||||
|
||||
h2t = html2text.HTML2Text()
|
||||
zammad = get_zammad_session()
|
||||
|
||||
|
@ -294,9 +296,14 @@ ticket_ids = os.listdir("tickets/")
|
|||
print(f"Found {len(ticket_ids)} tickets on filesystem.")
|
||||
ticket_ids = list(map(int, ticket_ids))
|
||||
ticket_ids.sort()
|
||||
ticket_ids = list(map(int, ticket_ids[rt_start:rt_end]))
|
||||
|
||||
for id in ticket_ids:
|
||||
try:
|
||||
matching_zammad_tickets= zammad.ticket.search(f"title: \"\[RT-{id}\]*\"")
|
||||
if len(matching_zammad_tickets) >= 1:
|
||||
print(f"Found duplicates: {id}")
|
||||
continue
|
||||
zammad_ticket_id = create_zammad_ticket(id, zammad, h2t, 5)
|
||||
dumpfile = f"processed/{id}"
|
||||
with open(dumpfile, "w") as handle:
|
||||
|
|
|
@ -59,11 +59,13 @@ def get_zammad_session(impersonated_user=None):
|
|||
def remove_duplicates_for(rt_id, zammad, retries=0):
|
||||
try:
|
||||
matching_zammad_tickets= zammad.ticket.search(f"title: \"\[RT-{rt_id}\]*\"")
|
||||
#matching_zammad_tickets= zammad.ticket.search('number:16014')
|
||||
print(matching_zammad_tickets[0])
|
||||
matching_zammad_ids = []
|
||||
if len(matching_zammad_tickets) >= 2:
|
||||
print(f"Found duplicates:")
|
||||
for zt in matching_zammad_tickets:
|
||||
print(f"{zt["id"]} {zt["title"]}")
|
||||
#print(f"{zt["rt_id"]} {zt["title"]}")
|
||||
matching_zammad_ids.append(zt["id"])
|
||||
|
||||
if len(matching_zammad_ids) >= 2:
|
||||
|
|
Loading…
Reference in a new issue