<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Create JSON file using Python Script and reading it from the script in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Create-JSON-file-using-Python-Script-and-reading-it-from-the/m-p/685502#M19331</link>
    <description>&lt;P&gt;I am developing an API integration to use it on Power BI. The problem is that I have done this integration in a Python Script.&lt;BR /&gt;&lt;BR /&gt;Here is the code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;import requests
import json

app_key = "1560731700"#EXAMPLE APP KEY
app_secret = "226dcf372489bb45ceede61bfd98f0f1" #EXAMPLE APP SECRET

response = requests.get('https://app.omie.com.br/api/v1/financas/contapagar/?JSON={"call":"ListarContasPagar","app_key":"%s","app_secret":"%s","param":[{"pagina":1,"registros_por_pagina":100,"apenas_importado_api":"N"}]}'%(app_key,app_secret)).status_code
if response != 200:
    print("Invalid Parameters")
else:
    response = requests.get('https://app.omie.com.br/api/v1/financas/contapagar/?JSON={"call":"ListarContasPagar","app_key":"%s","app_secret":"%s","param":[{"pagina":1,"registros_por_pagina":100,"apenas_importado_api":"N"}]}'%(app_key,app_secret)).json()
    total = response["total_de_paginas"]
    contas_pagar = response["conta_pagar_cadastro"]
    for i in range(1, total + 1):
        response = requests.get('https://app.omie.com.br/api/v1/financas/contapagar/?JSON={"call":"ListarContasPagar","app_key":"%s","app_secret":"%s","param":[{"pagina":%s,"registros_por_pagina":100,"apenas_importado_api":"N"}]}'%(app_key,app_secret,i)).json()
        
        with open("teste.json", "w") as teste: #I created a file called teste.json to dump the initial json.
            json.dump(contas_pagar,teste,indent=4)
            
        
        with open("teste.json", "r") as teste: #then I recall it, with readlines
            lines = teste.readlines()
        
        if i == 1:
            mode = "w"
        else:
            mode = "a"
            
        if i != total:
            with open("resultado.json", mode) as teste: #and write it down on another one!
                for b in range(len(lines)-1):
                    if b == 0 and mode == "a":
                        pass
                    elif b == len(lines) - 2:
                        teste.write(str(lines[b]).rstrip("\n") + ",")
                    else:
                        teste.write(lines[b])
                
        if i == total:
            with open("resultado.json", mode) as teste:
                for b in range(len(lines)-1):
                    if b == 0 and mode == "a":
                        pass
                    else:
                        teste.write(lines[b])
                teste.write("]")

        print("Page completed: %s" %i)&lt;/PRE&gt;&lt;P&gt;The problem is that my code generates 2 new json files while executing and I can't use dataset=teste on the code, because Power BI doesn't recognize it.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Is there anyway I can read the resultado.json file on Power BI generated on Python Script?&lt;BR /&gt;&lt;BR /&gt;PS: I have to run this code on PBI, to keep the flow automatically&lt;/P&gt;</description>
    <pubDate>Tue, 07 May 2019 13:21:48 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-05-07T13:21:48Z</dc:date>
    <item>
      <title>Create JSON file using Python Script and reading it from the script</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Create-JSON-file-using-Python-Script-and-reading-it-from-the/m-p/685502#M19331</link>
      <description>&lt;P&gt;I am developing an API integration to use it on Power BI. The problem is that I have done this integration in a Python Script.&lt;BR /&gt;&lt;BR /&gt;Here is the code:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;import requests
import json

app_key = "1560731700"#EXAMPLE APP KEY
app_secret = "226dcf372489bb45ceede61bfd98f0f1" #EXAMPLE APP SECRET

response = requests.get('https://app.omie.com.br/api/v1/financas/contapagar/?JSON={"call":"ListarContasPagar","app_key":"%s","app_secret":"%s","param":[{"pagina":1,"registros_por_pagina":100,"apenas_importado_api":"N"}]}'%(app_key,app_secret)).status_code
if response != 200:
    print("Invalid Parameters")
else:
    response = requests.get('https://app.omie.com.br/api/v1/financas/contapagar/?JSON={"call":"ListarContasPagar","app_key":"%s","app_secret":"%s","param":[{"pagina":1,"registros_por_pagina":100,"apenas_importado_api":"N"}]}'%(app_key,app_secret)).json()
    total = response["total_de_paginas"]
    contas_pagar = response["conta_pagar_cadastro"]
    for i in range(1, total + 1):
        response = requests.get('https://app.omie.com.br/api/v1/financas/contapagar/?JSON={"call":"ListarContasPagar","app_key":"%s","app_secret":"%s","param":[{"pagina":%s,"registros_por_pagina":100,"apenas_importado_api":"N"}]}'%(app_key,app_secret,i)).json()
        
        with open("teste.json", "w") as teste: #I created a file called teste.json to dump the initial json.
            json.dump(contas_pagar,teste,indent=4)
            
        
        with open("teste.json", "r") as teste: #then I recall it, with readlines
            lines = teste.readlines()
        
        if i == 1:
            mode = "w"
        else:
            mode = "a"
            
        if i != total:
            with open("resultado.json", mode) as teste: #and write it down on another one!
                for b in range(len(lines)-1):
                    if b == 0 and mode == "a":
                        pass
                    elif b == len(lines) - 2:
                        teste.write(str(lines[b]).rstrip("\n") + ",")
                    else:
                        teste.write(lines[b])
                
        if i == total:
            with open("resultado.json", mode) as teste:
                for b in range(len(lines)-1):
                    if b == 0 and mode == "a":
                        pass
                    else:
                        teste.write(lines[b])
                teste.write("]")

        print("Page completed: %s" %i)&lt;/PRE&gt;&lt;P&gt;The problem is that my code generates 2 new json files while executing and I can't use dataset=teste on the code, because Power BI doesn't recognize it.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Is there anyway I can read the resultado.json file on Power BI generated on Python Script?&lt;BR /&gt;&lt;BR /&gt;PS: I have to run this code on PBI, to keep the flow automatically&lt;/P&gt;</description>
      <pubDate>Tue, 07 May 2019 13:21:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Create-JSON-file-using-Python-Script-and-reading-it-from-the/m-p/685502#M19331</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-05-07T13:21:48Z</dc:date>
    </item>
  </channel>
</rss>

