Skip to content

Instantly share code, notes, and snippets.

@brettkelly
Forked from JeffPaine/us_state_abbreviations.py
Last active July 13, 2022 21:58
Show Gist options
  • Save brettkelly/d5ac74c0b844fe5c1c227810e47f4a95 to your computer and use it in GitHub Desktop.
Save brettkelly/d5ac74c0b844fe5c1c227810e47f4a95 to your computer and use it in GitHub Desktop.
A python list of all US state abbreviations.
states = {
'AK': 'Alaska',
'AL': 'Alabama',
'AR': 'Arkansas',
'AZ': 'Arizona',
'CA': 'California',
'CO': 'Colorado',
'CT': 'Connecticut',
'DC': 'District of Columbia',
'DE': 'Delaware',
'FL': 'Florida',
'GA': 'Georgia',
'HI': 'Hawaii',
'IA': 'Iowa',
'ID': 'Idaho',
'IL': 'Illinois',
'IN': 'Indiana',
'KS': 'Kansas',
'KY': 'Kentucky',
'LA': 'Louisiana',
'MA': 'Massachusetts',
'MD': 'Maryland',
'ME': 'Maine',
'MI': 'Michigan',
'MN': 'Minnesota',
'MO': 'Missouri',
'MS': 'Mississippi',
'MT': 'Montana',
'NC': 'North Carolina',
'ND': 'North Dakota',
'NE': 'Nebraska',
'NH': 'New Hampshire',
'NJ': 'New Jersey',
'NM': 'New Mexico',
'NV': 'Nevada',
'NY': 'New York',
'OH': 'Ohio',
'OK': 'Oklahoma',
'OR': 'Oregon',
'PA': 'Pennsylvania',
'RI': 'Rhode Island',
'SC': 'South Carolina',
'SD': 'South Dakota',
'TN': 'Tennessee',
'TX': 'Texas',
'UT': 'Utah',
'VA': 'Virginia',
'VT': 'Vermont',
'WA': 'Washington',
'WI': 'Wisconsin',
'WV': 'West Virginia',
'WY': 'Wyoming'
}
qtemplate_head = f"UPDATE wp_usermeta set `meta_value` = CASE `meta_key`"
qtemplate_end = "END where `meta_key` = 'billing_state'"
conditions = []
for abbr, name in states.items():
# print(f"{abbr} points to {name}")
s = f"WHEN '{name}' then '{abbr}'"
conditions.append(s)
query_conditions = '\n'.join([x for x in conditions])
print(f"""{qtemplate_head}
{query_conditions}
{qtemplate_end}""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment