{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'/Users/berhe/Rmoji/R/emoji_flags_masterlist_flags.R'"
      ]
     },
     "execution_count": null,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Prepare a full list of country codes and their corresponding flag emojis\n",
    "import pycountry\n",
    "\n",
    "# Generate the emoji from the ISO alpha_2 country code\n",
    "def country_flag_emoji(country_code):\n",
    "    OFFSET = 0x1F1E6\n",
    "    return ''.join([chr(OFFSET + ord(c) - ord('A')) for c in country_code])\n",
    "\n",
    "# Create a dictionary with country names and their flag emoji Unicode strings\n",
    "emoji_dict = {}\n",
    "for country in pycountry.countries:\n",
    "    try:\n",
    "        emoji = country_flag_emoji(country.alpha_2)\n",
    "        unicode_str = '\\\\U' + '\\\\U'.join(f\"{ord(char):08X}\" for char in emoji)\n",
    "        emoji_dict[country.name.replace(\" \", \"_\").replace(\",\", \"\")] = unicode_str\n",
    "    except AttributeError:\n",
    "        continue\n",
    "\n",
    "# Sort by country name\n",
    "emoji_dict = dict(sorted(emoji_dict.items()))\n",
    "\n",
    "# Create an R-style assignment string for the emoji_masterlist\n",
    "r_entries = [f'{key} = \"{value}\"' for key, value in emoji_dict.items()]\n",
    "r_content = \"emoji_masterlist <- list(\\n  \" + \",\\n  \".join(r_entries) + \"\\n)\"\n",
    "\n",
    "# Save to a text file\n",
    "file_path = \"/Users/berhe/Rmoji/R/emoji_flags_masterlist_flags.R\"\n",
    "with open(file_path, \"w\") as f:\n",
    "    f.write(r_content)\n",
    "\n",
    "file_path\n"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
