Tm1py: Retrieve all applications from tm1 instance

Created on 14 Jan 2021  Â·  9Comments  Â·  Source: cubewise-code/tm1py

I want to get a list with all applications on the server. Neither could I find a function in tm1py nor could I find out to get it directly from the api. Anyone any idea how to achieve that or did I overlook something?

question

All 9 comments

Its there under Utils

from TM1py.Utils import Utils

# get a list of servers under a particular admin host
servers = Utils.get_all_servers_from_adminhost(adminhost='localhost')

Thanks but I meant applications like Excel files. Stored under applications in a tm1 instance aka tm1 server aka tm1 database. I think wording here is confusing.

Use application service. I have just done one recently.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Christoph Hein notifications@github.com
Sent: Thursday, January 14, 2021 4:25:05 PM
To: cubewise-code/tm1py tm1py@noreply.github.com
Cc: Subscribed subscribed@noreply.github.com
Subject: Re: [cubewise-code/tm1py] Retrieve all applications from tm1 instance (#458)

Thanks but I meant applications like Excel files. Stored under applications in a tm1 instance aka tm1 server aka tm1 database. I think wording here is confusing.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://github.com/cubewise-code/tm1py/issues/458#issuecomment-759955614, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAZQV7IQUBQD2KSDPXE3NHDSZ2E4DANCNFSM4WB5CLLQ.

The application services unfortunately provides no function to retrieve all files stored there. I am looking for something similar to 'get_all_cubes_name'...

After using ARC and tracing the rest calls there I found a way of retrieving it. But I don't like it. :-D

_https://localhost:5001/api/v1/Contents('Applications')?$select=ID,Name&$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents)))))))))_

get_document function can return the file name with path and you can dump to xls files afterwards

Get Outlook for iOShttps://aka.ms/o0ukef


From: Christoph Hein notifications@github.com
Sent: Thursday, January 14, 2021 5:40:28 PM
To: cubewise-code/tm1py tm1py@noreply.github.com
Cc: tm1sir macsir@outlook.com; Comment comment@noreply.github.com
Subject: Re: [cubewise-code/tm1py] Retrieve all applications from tm1 instance (#458)

The application services unfortunately provides no function to retrieve all files stored there. I am looking for something similar to 'get_all_cubes_name'...

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHubhttps://github.com/cubewise-code/tm1py/issues/458#issuecomment-759987475, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAZQV7NMK5FIGAWF4VJHLCLSZ2NWZANCNFSM4WB5CLLQ.

The application services unfortunately provides no function to retrieve all files stored there. I am looking for something similar to 'get_all_cubes_name'...

After using ARC and tracing the rest calls there I found a way of retrieving it. But I don't like it. :-D

_https://localhost:5001/api/v1/Contents('Applications')?$select=ID,Name&$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents($select=ID,Name;$expand=tm1.Folder/Contents)))))))))_

It's true, we are lacking a function to return the name and path for every application on the server.

Something like that would be really useful, I guess. It is rather painful to get the path own your own. Maybe someone could come up with a better approach than the one I mentioned above.

@scrumthing
you can use this for the moment. Eventually we can make it more robust and integrate it into the ApplicationService.


from TM1py import TM1Service
from TM1py.Objects.Application import ApplicationTypes

with TM1Service(address="", port=12354, ssl=True, user="admin", password="apple") as tm1:
    application_entries = tm1.elements.get_element_names("}ApplicationEntries", "}ApplicationEntries")

    for application_entry in application_entries:
        *path_parts, application_name = application_entry.split("\\")
        if not application_name.endswith(".blob"):
            continue

        application_name, extension = application_name.rsplit(".", maxsplit=1)

        application = tm1.applications.get(
            path="/".join(path_parts),
            application_type=ApplicationTypes.DOCUMENT,
            name=application_name,
            private=False)

        application.to_xlsx(application.name + ".xlsx")

Hey @MariusWirtz, thanks for that. Works exactly like I need it. Playing around with perspective reports and trying to parse them for their formulas. For all that are curious, please find my work in progress here.

from TM1py import TM1Service
from TM1py.Objects.Application import ApplicationTypes
from openpyxl import load_workbook

with TM1Service(address="", port=12354, ssl=True, user="admin", password="apple") as tm1:
    application_entries = tm1.elements.get_element_names("}ApplicationEntries", "}ApplicationEntries")

    for application_entry in application_entries:
        *path_parts, application_name = application_entry.split("\\")
        if not application_name.endswith(".blob"):
            continue

        application_name, extension = application_name.rsplit(".", maxsplit=1)

        application = tm1.applications.get(
            path="/".join(path_parts),
            application_type=ApplicationTypes.DOCUMENT,
            name=application_name,
            private=False)

        application.to_xlsx(application.name)
        wb = load_workbook(filename = application.name)
        sheet_range = wb.sheetnames

        for sheet in sheet_range:
            ws = wb[sheet]
            for col in ws.iter_cols(min_row=1, min_col=1):
                for cell in col:
                    if str(cell.value) != 'None' and cell.data_type == 'f':
                        print(str(cell) + ' - ' + str(cell.value))
Was this page helpful?
0 / 5 - 0 ratings