繁体   English   中英

如何查询Monson API的Json数据? -Python

[英]How do I query Json data fron Monzo API? - Python

我正在尝试从要提取的Monzo数据中提取“创建的内容”。

我使用以下代码调用了Monzo api:

from monzo.monzo import Monzo

client = Monzo(INSERT API KEY)
data = client.get_transactions("INSERT ACCOUNT NUMBER")

print (data)

而且我无法完全获得所需的数据,如下所示:

d': 'merch_000094MPASVBf7xCdrZOz3', 'created': '2016-01-20T21: 26: 33.985Z', 'name': 'DelicedeFrance', 'logo': 'https: //mondo-logo-cache.appspot.com/twitter/deliceuk/?size=large', 'emoji': '🇫🇷', 'category': 'eating_out', 'online': False, 'atm': False, 'address': {'short_formatted': 'LiverpoolStreetStation,
LondonEC2M7PY', 'formatted': 'LiverpoolStreetStation,
LondonEC2M7PY,
UnitedKingdom', 'address': 'LiverpoolStreetStation', 'city': 'London', 'region': 'GreaterLondon', 'country': 'GBR', 'postcode': 'EC2M7PY', 'latitude': 51.518159172221615, 'longitude': -0.08210659649555102, 'zoom_level': 17, 'approximate': False}, 'updated': '2016-02-02T14: 10: 48.664Z', 'metadata': {'foursquare_category': 'Restaurant', 'foursquare_category_icon': 'https: //ss3.4sqi.net/img/categories_v2/food/default_88.png','foursquare_website': '', 'google_places_icon': 'https: //maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png', 'google_places_name': 'DelicedeFrance', 'suggested_name': 'DelicedeFrance', 'suggested_tags': '#food', 'twitter_id': ''}, 'disable_feedback': False}, 'notes': '', 'metadata': {}, 'account_balance': 3112, 'attachments': [], 'category': 'eating_out', 'is_load': False, 'settled': '2017-04-28T04: 54: 18.167Z', 'local_amount': -199, 'local_currency': 'GBP', 'updated': '2017-04-28T06: 15: 06.095Z',  'counterparty': {}, 'originator': False, 'include_in_spending': True}, {'created': '2017-04-28T08: 54: 10.917Z','amount': -130, 'currency': 'GBP', 'merchant': {'created': '2016-04-21T08: 02: 13.537Z','logo': 'https: //mondo-logo-cache.appspot.com/twitter/MCSaatchiLondon/?size=large', 'emoji': '🍲', 'category': 'eating_out', 'online': False, 'atm': False...

如何拉“创建”日期?

尝试这个:

#!/usr/bin/env python
import csv

from pymonzo import MonzoAPI


if __name__ == '__main__':
    monzo_api = MonzoAPI()
    monzo_transactions = monzo_api.transactions()

    with open('monzo_transactions.csv', 'w') as csvfile:
        writer = csv.writer(csvfile)

        for transaction in monzo_transactions:
            writer.writerow([
                transaction.amount, transaction.description, 
transaction.created,
            ])

    print('All done!')

如果这实际上是正确的json代码,并且您只是存在粘贴错误,则可以使用python libary json:

import json
data = json.loads(datastring)

如果不是json代码,则可能必须自己编写一个解析器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM