Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add mapping for country codes
Browse files Browse the repository at this point in the history
keyn4 committed Jan 28, 2025
1 parent 2e0b0e3 commit e1a3932
Showing 3 changed files with 266 additions and 5 deletions.
25 changes: 24 additions & 1 deletion target_salesforce_v3/client.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,11 @@

from target_hotglue.sinks import HotglueSink

import os
import json

__location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))


class TargetSalesforceQuotaExceededException(Exception):
pass
@@ -439,4 +444,22 @@ def map_only_empty_fields(self, mapping, sobject_name, lookup_field):
)
if data:
mapping = {k:v for k,v in mapping.items() if not data[0].get(k) or k == "Id"}
return mapping
return mapping

def read_json_file(self, filename):
# read file
with open(os.path.join(__location__, f"{filename}"), "r") as filetoread:
data = filetoread.read()

# parse file
content = json.loads(data)

return content

def map_country(self, country):
if country:
countries = self.read_json_file("countries.json")
mapped_country = countries.get(country) or (country if country in countries.values() else None)
if not mapped_country:
self.logger.info(f"Country '{country}' is not a valid value, not sending country in the payload.")
return mapped_country
238 changes: 238 additions & 0 deletions target_salesforce_v3/countries.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
{
"AF": "Afghanistan",
"AL": "Albania",
"DZ": "Algeria",
"AS": "American samoa",
"AD": "Andorra",
"AO": "Angola",
"AI": "Anguilla",
"AQ": "Antarctica",
"AG": "Antigua and barbuda",
"AR": "Argentina",
"AM": "Armenia",
"AW": "Aruba",
"AU": "Australia",
"AT": "Austria",
"AZ": "Azerbaijan",
"BS": "Bahamas",
"BH": "Bahrain",
"BD": "Bangladesh",
"BB": "Barbados",
"BY": "Belarus",
"BE": "Belgium",
"BZ": "Belize",
"BJ": "Benin",
"BM": "Bermuda",
"BT": "Bhutan",
"BO": "Bolivia",
"BA": "Bosnia and herzegovina",
"BW": "Botswana",
"BV": "Bouvet island",
"BR": "Brazil",
"IO": "British indian ocean territory",
"BN": "Brunei darussalam",
"BG": "Bulgaria",
"BF": "Burkina faso",
"BI": "Burundi",
"KH": "Cambodia",
"CM": "Cameroon",
"CA": "Canada",
"CV": "Cape verde",
"KY": "Cayman islands",
"CF": "Central african republic",
"TD": "Chad",
"CL": "Chile",
"CN": "China",
"CX": "Christmas island",
"CC": "Cocos (keeling) islands",
"CO": "Colombia",
"KM": "Comoros",
"CG": "Congo",
"CD": "Congo, the democratic republic of",
"CK": "Cook islands",
"CR": "Costa rica",
"CI": "C\u00e3\u201dte d'ivoire",
"HR": "Croatia",
"CU": "Cuba",
"CY": "Cyprus",
"CZ": "Czech republic",
"DK": "Denmark",
"DJ": "Djibouti",
"DM": "Dominica",
"DO": "Dominican republic",
"EC": "Ecuador",
"EG": "Egypt",
"SV": "El salvador",
"GQ": "Equatorial guinea",
"ER": "Eritrea",
"EE": "Estonia",
"ET": "Ethiopia",
"FK": "Falkland islands (malvinas)",
"FO": "Faroe islands",
"FJ": "Fiji",
"FI": "Finland",
"FR": "France",
"GF": "French guiana",
"PF": "French polynesia",
"TF": "French southern territories",
"GA": "Gabon",
"GM": "Gambia",
"GE": "Georgia",
"DE": "Germany",
"GH": "Ghana",
"GI": "Gibraltar",
"GR": "Greece",
"GL": "Greenland",
"GD": "Grenada",
"GP": "Guadeloupe",
"GU": "Guam",
"GT": "Guatemala",
"GN": "Guinea",
"GW": "Guinea",
"GY": "Guyana",
"HT": "Haiti",
"HM": "Heard island and mcdonald islands",
"HN": "Honduras",
"HK": "Hong kong",
"HU": "Hungary",
"IS": "Iceland",
"IN": "India",
"ID": "Indonesia",
"IR": "Iran, islamic republic of",
"IQ": "Iraq",
"IE": "Ireland",
"IL": "Israel",
"IT": "Italy",
"JM": "Jamaica",
"JP": "Japan",
"JO": "Jordan",
"KZ": "Kazakhstan",
"KE": "Kenya",
"KI": "Kiribati",
"KP": "Korea, democratic people's republic of",
"KR": "Korea, republic of",
"KW": "Kuwait",
"KG": "Kyrgyzstan",
"LA": "Lao people's democratic republic",
"LV": "Latvia",
"LB": "Lebanon",
"LS": "Lesotho",
"LR": "Liberia",
"LY": "Libyan arab jamahiriya",
"LI": "Liechtenstein",
"LT": "Lithuania",
"LU": "Luxembourg",
"MO": "Macao",
"MK": "Macedonia, the former yugoslav republic of",
"MG": "Madagascar",
"MW": "Malawi",
"MY": "Malaysia",
"MV": "Maldives",
"ML": "Mali",
"MT": "Malta",
"MH": "Marshall islands",
"MQ": "Martinique",
"MR": "Mauritania",
"MU": "Mauritius",
"YT": "Mayotte",
"MX": "Mexico",
"FM": "Micronesia, federated states of",
"MD": "Moldova, republic of",
"MC": "Monaco",
"MN": "Mongolia",
"MS": "Montserrat",
"MA": "Morocco",
"MZ": "Mozambique",
"MM": "Myanmar",
"NA": "Namibia",
"NR": "Nauru",
"NP": "Nepal",
"NL": "Netherlands",
"AN": "Netherlands antilles",
"NC": "New caledonia",
"NZ": "New zealand",
"NI": "Nicaragua",
"NE": "Niger",
"NG": "Nigeria",
"NU": "Niue",
"NF": "Norfolk island",
"MP": "Northern mariana islands",
"NO": "Norway",
"OM": "Oman",
"PK": "Pakistan",
"PW": "Palau",
"PS": "Palestinian territory, occupied",
"PA": "Panama",
"PG": "Papua new guinea",
"PY": "Paraguay",
"PE": "Peru",
"PH": "Philippines",
"PN": "Pitcairn",
"PL": "Poland",
"PT": "Portugal",
"PR": "Puerto rico",
"QA": "Qatar",
"RE": "R\u00e3\u2030union",
"RO": "Romania",
"RU": "Russian federation",
"RW": "Rwanda",
"SH": "Saint helena",
"KN": "Saint kitts and nevis",
"LC": "Saint lucia",
"PM": "Saint pierre and miquelon",
"VC": "Saint vincent and the grenadines",
"WS": "Samoa",
"SM": "San marino",
"ST": "Sao tome and principe",
"SA": "Saudi arabia",
"SN": "Senegal",
"CS": "Serbia and montenegro",
"SC": "Seychelles",
"SL": "Sierra leone",
"SG": "Singapore",
"SK": "Slovakia",
"SI": "Slovenia",
"SB": "Solomon islands",
"SO": "Somalia",
"ZA": "South africa",
"GS": "South georgia and south sandwich islands",
"ES": "Spain",
"LK": "Sri lanka",
"SD": "Sudan",
"SR": "Suriname",
"SJ": "Svalbard and jan mayen",
"SZ": "Swaziland",
"SE": "Sweden",
"CH": "Switzerland",
"SY": "Syrian arab republic",
"TW": "Taiwan, province of china",
"TJ": "Tajikistan",
"TZ": "Tanzania, united republic of",
"TH": "Thailand",
"TL": "Timor",
"TG": "Togo",
"TK": "Tokelau",
"TO": "Tonga",
"TT": "Trinidad and tobago",
"TN": "Tunisia",
"TR": "Turkey",
"TM": "Turkmenistan",
"TC": "Turks and caicos islands",
"TV": "Tuvalu",
"UG": "Uganda",
"UA": "Ukraine",
"AE": "United arab emirates",
"GB": "United kingdom",
"US": "United states",
"UM": "United states minor outlying islands",
"UY": "Uruguay",
"UZ": "Uzbekistan",
"VU": "Vanuatu",
"VN": "Viet nam",
"VG": "Virgin islands, british",
"VI": "Virgin islands, u.s.",
"WF": "Wallis and futuna",
"EH": "Western sahara",
"YE": "Yemen",
"ZW": "Zimbabwe"
}
8 changes: 4 additions & 4 deletions target_salesforce_v3/sinks.py
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ def preprocess_record(self, record: dict, context: dict):
mapping[f"{_prefix}City"] = address.get("city")
mapping[f"{_prefix}State"] = address.get("state")
mapping[f"{_prefix}PostalCode"] = address.get("postal_code")
mapping[f"{_prefix}Country"] = address.get("country")
mapping[f"{_prefix}Country"] = self.map_country(address.get("country"))

if record.get("addresses") and len(record["addresses"]) >= 2 and self.contact_type == 'Contact':
# Leads only have one address
@@ -162,7 +162,7 @@ def preprocess_record(self, record: dict, context: dict):
mapping["OtherCity"] = address.get("city")
mapping["OtherState"] = address.get("state")
mapping["OtherPostalCode"] = address.get("postal_code")
mapping["OtherCountry"] = address.get("country")
mapping["OtherCountry"] = self.map_country(address.get("country"))

phone_types = {
"Phone": ["primary"],
@@ -525,7 +525,7 @@ def preprocess_record(self, record, context):
mapping["BillingCity"] = address.get("city")
mapping["BillingState"] = address.get("state")
mapping["BillingPostalCode"] = address.get("postal_code")
mapping["BillingCountry"] = address.get("country")
mapping["BillingCountry"] = self.map_country(address.get("country"))

if record.get("addresses") and len(record["addresses"]) >= 2:
address = record["addresses"][1]
@@ -534,7 +534,7 @@ def preprocess_record(self, record, context):
mapping["ShippingCity"] = address.get("city")
mapping["ShippingState"] = address.get("state")
mapping["ShippingPostalCode"] = address.get("postal_code")
mapping["ShippingCountry"] = address.get("country")
mapping["ShippingCountry"] = self.map_country(address.get("country"))

phone_types = {"Phone": ["primary"], "Fax": ["fax"]}

0 comments on commit e1a3932

Please sign in to comment.