Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- def extract_time(json):
- try:
- return int(json[1]["updated"])
- except KeyError:
- return 0
- def main():
- response = requests.get('https://api.exmo.com/v1/ticker/')
- json_data = json.loads(response.content.decode('utf-8'))
- json2 = []
- for s in json_data.items():
- json2.append(s)
- json2.sort(key=extract_time, reverse=True)
- fieldnames = ["symbol", "buy_price", "sell_price", "last_trade",
- "high", "low", "avg", "vol", "vol_curr", "updated"]
- with open('json_data.csv', "w") as out_file:
- out_file.write(';'.join(fieldnames) + '\n')
- for s in json2:
- s1 = s[0] + ';'
- s2 = ';'.join(map(str, s[1].values()))
- out_file.write(s1 + s2 + '\n')
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement