Skip to content

Instantly share code, notes, and snippets.

@boochow
Created October 14, 2017 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boochow/4947028327f6723b542484b0e7572d42 to your computer and use it in GitHub Desktop.
Save boochow/4947028327f6723b542484b0e7572d42 to your computer and use it in GitHub Desktop.
def main():
import network, socket, ujson
from machine import Pin
nic = network.WIZNET5K(pyb.SPI(2), Pin('PB12'), Pin('PC8'))
addr = socket.getaddrinfo('api.fixer.io',80)[0][-1]
s = socket.socket()
s.connect(addr)
s.send(bytes('GET /latest?base=USD&symbols=JPY HTTP/1.0\r\nHost: api.fixer.io\r\n\r\n', 'utf8'))
result = s.recv(1000)
s.close()
lines = result.splitlines()
pos = lines.index(b'')
parsed = ujson.loads(lines[pos + 1])
print(parsed["date"])
print("JPY/" + parsed["base"] + ": " + str(parsed["rates"]["JPY"]))
@boochow
Copy link
Author

boochow commented Oct 14, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment