import csv
import requests


def deactivateUsers(filename: str) -> None:
    """
    Looks at each row in the CSV and deactivates any user who hasn't accessed either Jira or Confluence.
    The CSV can be generated by running an export on the users in the cloud admin portal.
    input: filename of a CSV used to find "active" users that should be deactivated
    output: None
    """
    auth_cookie = ''#TODO: INSERT YOUR ACTUAL COOKIE
    s = requests.Session()
    s.headers.update({'Cookie': auth_cookie})
    count = 0
    with open(filename) as f:
        csv_reader = csv.DictReader(f, delimiter=',')
        for row in csv_reader:
            if row['Last seen in Jira Software - nypublicradio-digital'] == 'Never accessed' and row['Last seen in Confluence - nypublicradio-digital'] == 'Never accessed':
                userID = row['User id']
                requestURL = f'https://admin.atlassian.com/gateway/api/adminhub/um/site/71009519-b8a1-47cf-b4d5-7a3e6fafe609/users/{userID}/deactivate'
                s.post(requestURL)
                count += 1
                print(f"Deactivated {row['User name']}")
    print(f'{count} users deactivated')

if __name__ == "__main__":
    deactivateUsers('export-users.csv')
