def isSynced():
    old_sheet_data = retTotalData('old')
    new_sheet_data = retTotalData('new')

    old_infected_count = new_infected_count = 0
    old_dead_count = new_dead_count = 0

    for state in old_sheet_data:
        for district in old_sheet_data[state]:
            old_infected_count += old_sheet_data[state][district]["infected"]
            old_dead_count += old_sheet_data[state][district]["dead"]

    for state in new_sheet_data:
        for district in new_sheet_data[state]:
            new_infected_count += new_sheet_data[state][district]["infected"]
            new_dead_count += new_sheet_data[state][district]["dead"]

    if (old_infected_count == new_infected_count
            and old_dead_count == new_dead_count):
        return 'Old and new sheets match perfectly!'

    else:

        if (old_infected_count >= new_infected_count):

            if (old_dead_count > new_dead_count):
                return 'Old sheet has {} more infected cases and {} more death cases'.format(
                    old_infected_count - new_infected_count,
                    old_dead_count - new_dead_count)

            elif (old_dead_count == new_dead_count):
                return 'Old sheet has {} more infected cases. Death count matches'.format(
                    old_infected_count - new_infected_count)

            else:
                return 'Old sheet has {} more infected cases and a deficit of {} death cases'.format(
                    old_infected_count - new_infected_count,
                    new_dead_count - old_dead_count)

        else:

            if (new_dead_count > new_dead_count):
                return 'New sheet has {} more infected cases and {} more death cases'.format(
                    new_infected_count - old_infected_count,
                    new_dead_count - old_dead_count)

            elif (new_dead_count == new_dead_count):
                return 'New sheet has {} more infected cases. Death count matches'.format(
                    new_infected_count - old_infected_count)

            else:
                return 'New sheet has {} more infected cases and a deficit of {} death cases'.format(
                    new_infected_count - old_infected_count,
                    new_dead_count - old_dead_count)
def districtData(sheet='old'):
    totalData = retTotalData(sheet)
    districtText = ''
    for state in totalData:
        districtText += '{} :\n'.format(state)
        for district in totalData[state]:
            districtText += district + ':\nInfected : {}'.format(
                totalData[state][district]["infected"]
            ) + '\nDead : {}\n\n'.format(totalData[state][district]["dead"])
    return districtText
def distNAstate(stateName, sheet='old'):
    totalData = retTotalData(sheet)
    text = 'DIST_NAs in {} :\n'.format(stateName)
    if (stateName in totalData):
        if ("DIST_NA" in totalData[stateName]):
            text += 'Infected : {}\nDeath : {}'.format(
                totalData[stateName]['DIST_NA']["infected"],
                totalData[stateName]['DIST_NA']["dead"])
            return text
    return "Good news! No DIST_NA for {}".format(stateName)
def stateData(sheet='old'):
    totalData = retTotalData(sheet)
    stateText = ''
    for state in totalData:
        infectedStateSum = 0
        deadStateSum = 0
        for district in totalData[state]:
            infectedStateSum += totalData[state][district]["infected"]
            deadStateSum += totalData[state][district]["dead"]
        stateText += state + '\nInfected : {}'.format(
            infectedStateSum) + '\nDead : {}\n\n'.format(deadStateSum)
    return stateText
def findDistrict(districtName, sheet='old'):
    totalData = retTotalData(sheet)
    districtText = ''
    if (districtName == 'DIST_NA'):
        return 'Use !distnatot to get all DIST_NA, or !distnastate statename for a particular state'
    for state in totalData:
        if districtName in totalData[state]:
            districtText = 'Values for {}, {}:\n'.format(
                districtName, state) + '\nInfected : {}'.format(
                    totalData[state][districtName]
                    ["infected"]) + '\nDead : {}'.format(
                        totalData[state][districtName]["dead"])
            return districtText
    return ('{} not found, check spelling and try again'.format(districtName))
def findState(stateName, sheet='old'):
    totalData = retTotalData(sheet)
    stateText = ''
    if stateName in totalData:
        infectedStateSum = 0
        deadStateSum = 0
        for district in totalData[stateName]:
            infectedStateSum += totalData[stateName][district]["infected"]
            deadStateSum += totalData[stateName][district]["dead"]
        stateText = 'Values for {}:\n'.format(
            stateName) + 'Infected : {}\nDead : {}'.format(
                infectedStateSum, deadStateSum)
        return stateText
    return ('{} not found, check spelling and try again'.format(stateName))
def stateDists(stateName, sheet='old'):
    totalData = retTotalData(sheet)
    infectedSum = 0
    deadSum = 0
    stateDistrictsText = 'Districts with numbers in {}:\n'.format(stateName)
    if stateName in totalData:
        for district in totalData[stateName]:
            infectedSum += totalData[stateName][district]["infected"]
            deadSum += totalData[stateName][district]["dead"]
            stateDistrictsText += district + '\nInfected : {}\nDead : {}\n\n'.format(
                totalData[stateName][district]["infected"],
                totalData[stateName][district]["dead"])
        stateDistrictsText += 'Total infected : {}\nTotal dead : {}'.format(
            infectedSum, deadSum)
        return stateDistrictsText
    return "Found nothing for {}".format(stateName)
def totDistNA(sheet='old'):
    totalData = retTotalData(sheet)
    retText = 'DIST_NAs statewise :\n'
    distNAinfected = 0
    distNAdead = 0
    for state in totalData:
        for district in totalData[state]:
            if (district == 'DIST_NA'):
                retText += 'In {}:\n'.format(
                    state) + 'Infected : {}\nDead : {}\n\n'.format(
                        totalData[state][district]["infected"],
                        totalData[state][district]["dead"])
                distNAinfected += totalData[state][district]["infected"]
                distNAdead += totalData[state][district]["dead"]
    if (distNAdead != 0 and distNAinfected != 0):
        retText += 'Total DIST_NA count :\nInfected : {}\nDead : {}'.format(
            distNAinfected, distNAdead)
        return retText
    return 'Good News, ALL DIST_NA CLEARED!!! Party time'