~linuxgoose/Inque

ref: 60cef48409b7251b0c90ddb1b26d4f07e600ec2a Inque/inque/tickets/management/commands/fetch_emails.py -rw-r--r-- 643 bytes
60cef484Jordan Robinson add license 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from django.core.management.base import BaseCommand
from tickets.imap_reader import fetch_emails

class Command(BaseCommand):
    help = "Fetch new emails and create/update tickets"

    def handle(self, *args, **kwargs):
        created, updated = fetch_emails()
        self.stdout.write(self.style.SUCCESS(
            f"Fetched emails successfully. Tickets created: {len(created)}, updated: {len(updated)}"
        ))
        for ticket in created:
            self.stdout.write(f"Created Ticket #{ticket.id}: {ticket.subject}")
        for ticket in updated:
            self.stdout.write(f"Updated Ticket #{ticket.id}: {ticket.subject}")