Search code examples
xmlweb-scrapingfeedgoogle-trends

How should I store these Google country IDs for Search Trends in my feed wrapper?


I apologize if the question could have been worded or tagged any better.

I'm looking at this page and making a Node.js module to parse their feed data into JSON. My module will also allow the user to select the country for their data, but the website refers to countries via IDs. I can manually hard code them into the module, but I'll never be sure if they ever change.

Hardcoding seems like the best option, but is there a recommended way of doing this? Or is there a list of Google's standard country IDs somewhere?


Solution

  • I wouldn't hard code them. At least put them in a resource file that your module references. Since you're using javascript anyway, make the resource file a JSON object itself.

    [
     {"United States" : "p1"},
     {"someothercountry" : "p2"},
     ...etc...
    ]
    

    Then to load the resource file:

    var countryCodeMap = require('./countryCodes.json');