Help with reading graph from txt

0

I need help with implementing a code that does the same thing as the following:

import math, urllib2, json, re

def download():
    graph = {}
    page = urllib2.urlopen("http://fx.priceonomics.com/v1/rates/?q=1")
    jsrates = json.loads(page.read())

    pattern = re.compile("([A-Z]{3})_([A-Z]{3})")
    for key in jsrates:
        matches = pattern.match(key)
        conversion_rate = -math.log(float(jsrates[key]))
        from_rate = matches.group(1).encode('ascii','ignore')
        to_rate = matches.group(2).encode('ascii','ignore')
            if from_rate != to_rate:
            if from_rate not in graph:
                graph[from_rate] = {}
            graph[from_rate][to_rate] = float(conversion_rate)
    return graph

But using a .txt file like this:

    
asked by Matias Arriagada Juliá 05.11.2018 в 20:02
source

0 answers