base_url = sys.argv[0]
addon_handle = int(sys.argv[1])

institutionspath = os.path.join(path, 'resources', 'data', "institutions.csv")  # local csv = data/institutions.csv
mainfanart = os.path.join(path,'fanart.jpg')
citiesicon = os.path.join(path, 'resources', 'media', "cities.png")
countriesicon = os.path.join(path, 'resources', 'media', "countries.png")

#debugfile3 = open(os.path.join(path, 'resources', 'data', "debugfile3.txt"), 'w')
#debugfile3.write("splitlist="+str(sl)+"\n\n")
#debugfile3.close()

# Name of institution, City, Countrycode, Youtube channel ID, abbreviation of institute (for icons and fanart)
# Put in in list chi[]
chi = []
chi = plugintools.read_local_csv(institutionspath)
# Break down chi[]. Set OrganisationName, city, countrycode,YoutubeChannel-ID, abbreviation, local thumb and local fanart for every CH institution
chi_name, chi_city, chi_countrycode, chi_countryname, chi_YOUTUBE_CHANNEL, chi_abbrev, chi_twitterHandle, chi_thumb, chi_fanart = (
    [] for i in range(9))

# Strip leading and traling blanks from list entries, as well as multiple inner spaces
# See http://bytes.com/topic/python/answers/590441-how-strip-mulitiple-white-spaces
for i in range(len(chi)):
    chi_name.append(" ".join(chi[i][0].split()))
    chi_city.append(" ".join(chi[i][1].split()))
    chi_countrycode.append(chi[i][2].strip())
    chi_countryname.append(
        plugintools.lookup_countryname(chi_countrycode[i].strip()))
    chi_YOUTUBE_CHANNEL.append(chi[i][3].strip())
    chi_abbrev.append(chi[i][4].strip())
    chi_thumb.append(
import sys
import plugintools
import xbmcaddon
from addon.common.addon import Addon

addonID = 'plugin.video.heritagechannel'
addon = Addon(addonID, sys.argv)
local = xbmcaddon.Addon(id=addonID)
path = local.getAddonInfo('path')

localfilepath = os.path.join(path, 'resources', 'data', "institutions.csv")  # local csv = data/institutions.csv

# Name of institution, City, Countrycode, Youtube channel ID, abbreviation of institute (for icons and fanart)
# Put in in list chi[]
chi = []
chi = plugintools.read_local_csv(localfilepath)
# Break down chi[]. Set OrganisationName, city, countrycode,YoutubeChannel-ID, abbreviation, local thumb and local fanart for every CH institution
chi_name, chi_city, chi_countrycode, chi_countryname, chi_YOUTUBE_CHANNEL, chi_abbrev, chi_twitterHandle, chi_thumb, chi_fanart = (
    [] for i in range(9))

# Strip leading and traling blanks from list entries, as well as multiple inner spaces
# See http://bytes.com/topic/python/answers/590441-how-strip-mulitiple-white-spaces
for i in range(len(chi)):
    chi_name.append(" ".join(chi[i][0].split()))
    chi_city.append(" ".join(chi[i][1].split()))
    chi_countrycode.append(chi[i][2].strip())
    chi_countryname.append(
        plugintools.lookup_countryname("countrydata.csv", chi_countrycode[i].strip()))
    chi_YOUTUBE_CHANNEL.append(chi[i][3].strip())
    chi_abbrev.append(chi[i][4].strip())
    chi_thumb.append(