Пример #1
0
def _downloadDictFile(dictFileName):
    fileURL = Settings.sources["eurostat"]["dictURL"] + dictFileName
    try:
        response = urlopen(fileURL)
    except:
        error("Downloading Dictionary " + dictFileName + " (" + fileURL + ")")
        return False

    try:
        with open(os.path.join(Settings.dictPath, dictFileName), 'wb') as outfile:
            outfile.write(response.read())
    except:
        error("Saving Dictionary " + dictFileName)
        return False
Пример #2
0
def _getDict(title):
    d = {}

    try:
        dictFileName = os.path.join(Settings.dictPath, title + ".dic" )            #open dict that is equal to the TAbtitle

        with open(dictFileName, "r") as dictFile:
            dictReader = csv.reader(dictFile, delimiter = "\t")
            for row in dictReader:                           #search every row of the dict for the short
                d[row[0]] = row[1]
        return d
    except:
        error("in Dic File opening: " + dictFileName)
        return False
Пример #3
0
def _findInDict(title, shorty):
    if title.upper() == "TIME":    #TIME is the only title without long-text
        return shorty

    longy = ""

    try:
        dictFileName = os.path.join(Settings.dictPath, title + ".dic" )            #open dict that is equal to the TAbtitle

        with open(dictFileName, "r") as dictFile:
            dictReader = csv.reader(dictFile, delimiter = "\t")
            for row in dictReader:                           #search every row of the dict for the short
                if row[0] == shorty:                              #if they match
                    longy = row[1]                           #append to long
                    return str(longy)
        return "n.a."
    except:
        error("in Dic File opening: " + dictFileName)
        return False