Bank database program I have been trying to improve my Python coding and was just wondering if there was a more pythonic way to perform what I have done so far, namely around the date in the main() function.
import datetime
import sybase

account_list = []

def get_date(): # Date -1 day unless Monday then -3 days
    d = datetime.date.today()
    if d.weekday() == 0:
        date = d - datetime.timedelta(days=3)
        return date
    else:
        date = d - datetime.timedelta(days=1)
        return date


def get_unique_accounts(date):
    conn = sybase.Connection('')
    c = conn.cursor()
    c.execute(&quot;SELECT DISTINCT acct from accounts WHERE date = @date&quot;, {&quot;@date&quot;: date})
    result = c.fetchall()
    for row in result:
        account_list.append(row[0])
    c.close()
    conn.close()


def check_balance(date):
    conn = sybase.Connection('')
    c = conn.cursor()
    c.execute(&quot;SELECT TOP 1 name,balance from balance WHERE date = @date&quot;, {&quot;@date&quot;: date})
    result = c.fetchone()
    c.close()
    conn.close()
    return result


def main():
    date = get_date()
    get_unique_accounts(date) # This will be used for future functions
    check_balance(date)
    

if __name__ == &quot;__main__&quot;:
    main()
I will focus on the get_date() method. First of all, what sort of date is it? Currently the name makes me think it will get the current date, but it's sort of a banking date? Something along the lines of get_last_banking_day() would be more descriptive?
You can move the return to the end of the function as that is the same in both blocks of the if/else:
def get_last_banking_day(): # Date -1 day unless Monday then -3 days
    d = datetime.date.today()

    if d.weekday() == 0:
        date = d - datetime.timedelta(days=3)
    else:
        date = d - datetime.timedelta(days=1)
    
    return date

You could clean up the import and only import the 2 things needed from datetime, date and timedelta.:
from datetime import date, timedelta

The function would become:
def get_last_banking_day(): # Date -1 day unless Monday then -3 days
    d = date.today()

    if d.weekday() == 0:
        date = d - timedelta(days=3)
    else:
        date = d - timedelta(days=1)
    
    return date

Now we can look at variable names and do some cleanup, especially the d variable. Always try to avoid non-descriptive names:
def get_last_banking_day(): # Date -1 day unless Monday then -3 days
    today = date.today()

    if today.weekday() == 0:
        last_banking_day = today - timedelta(days=3)
    else:
        last_banking_day = today - timedelta(days=1)
    
    return last_banking_day

As the today - timedelta(days=1) is the default we use it as such and set the value to this and only use an if-statement to set the exception:
def get_last_banking_day(): # Date -1 day unless Monday then -3 days
    today = date.today()
    last_banking_day = today - timedelta(days=1)

    if today.weekday() == 0:
        last_banking_day = today - timedelta(days=3)

    return last_banking_day