Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions Examples/example_library.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import json
from os.path import join
import os
from dotenv import load_dotenv
from iLibrary import Library

#load ENV file and get the Connection Settings
dotenv_path = join('..', '.env')
load_dotenv(dotenv_path)
DB_DRIVER = os.environ.get("DB_DRIVER")
DB_USER = os.environ.get("DB_USER")
DB_PASSWORD = os.environ.get("DB_PASSWORD")
DB_SYSTEM = os.environ.get("DB_SYSTEM")




# ----------------------------------------------------
# make a Savefile from a library
# ----------------------------------------------------
def getSaveFile():

# Flag to enable/disable Mapepire connection mode
USE_MAPEPIRE = False


PORT = 22 #for the Pub400.com use the Port 2222
LIBRARY = '<LIBRARY_TO_SAVE>'
SAVE_FILE_NAME = 'FOO'
LOCAL_PATH = 'YOUR_LOCAL_PATH'
DESCRIPTION = 'Saved from iLibrary'
try:
# Establish a connection to the IBM i system using the User class
# The context manager ensures the connection is properly opened and closed
with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER, mapepire=USE_MAPEPIRE) as l:

# Call the method to save the Library
# The result is returned as a JSON string
raw_result = l.saveLibrary(
library=LIBRARY,
saveFileName=SAVE_FILE_NAME,
description=DESCRIPTION,
localPath=LOCAL_PATH,
port=PORT
)

# Parse the JSON string into a Python object (list/dictionary)
data = json.loads(raw_result)

# Pretty-print the parsed data with indentation for readability
print(json.dumps(data, indent=4))

# Handle any exceptions that occur during connection or data retrieval
except Exception as e:
# Print the error message for debugging
print(e)



# ----------------------------------------------------
# Get library information about all libraries from
# IBM i Server using iLibrary
# ----------------------------------------------------
def getAllLibraries():
# Flag to enable/disable Mapepire connection mode
USE_MAPEPIRE = False

try:
# Establish a connection to the IBM i system using the User class
# The context manager ensures the connection is properly opened and closed
with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER, mapepire=USE_MAPEPIRE) as l:

# Call the method to get all libraries on the system
# The result is returned as a JSON string
raw_result = l.getAllLibraries()

# Parse the JSON string into a Python object (list/dictionary)
data = json.loads(raw_result)

# Pretty-print the parsed data with indentation for readability
print(json.dumps(data, indent=4))

# Handle any exceptions that occur during connection or data retrieval
except Exception as e:
# Print the error message for debugging
print(e)




# ----------------------------------------------------
# Get single library information from IBM i Server
# using iLibrary
# ----------------------------------------------------
def getSingleLibraryInfo():
# Flag to enable/disable Mapepire connection mode
USE_MAPEPIRE = False
LIBRARY = '<LIBRARY>'
try:
# Establish a connection to the IBM i system using the User class
# The context manager ensures the connection is properly opened and closed
with Library(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER, mapepire=USE_MAPEPIRE) as l:

# Call the method to show singe information about the Library
# The result is returned as a JSON string
raw_result = l.getLibraryInfo(
library=LIBRARY
)

# Parse the JSON string into a Python object (list/dictionary)
data = json.loads(raw_result)

# Pretty-print the parsed data with indentation for readability
print(json.dumps(data, indent=4))

# Handle any exceptions that occur during connection or data retrieval
except Exception as e:
# Print the error message for debugging
print(e)

if __name__ == '__main__':
getSaveFile()
getAllLibraries()
getSingleLibraryInfo()
49 changes: 43 additions & 6 deletions Examples/example_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
DB_PASSWORD = os.environ.get("DB_PASSWORD")
DB_SYSTEM = os.environ.get("DB_SYSTEM")

if __name__ == "__main__":

# ----------------------------------------------------
# Get all Users information from IBM i Server using
# iLibrary
# ----------------------------------------------------


def getAllUsers():
# Flag to enable/disable Mapepire connection mode
USE_MAPEPIRE = False

Expand All @@ -43,11 +41,13 @@
# Print the error message for debugging
print(e)



# ----------------------------------------------------
# Get single Users information from IBM i Server
# using iLibrary
# ----------------------------------------------------

def getSingleUser():
# Flag to enable/disable Mapepire connection mode
USE_MAPEPIRE = False

Expand Down Expand Up @@ -77,6 +77,43 @@
# Output the error message for debugging purposes
print(e)

# ----------------------------------------------------
# Send a message to a IBM i User using iLibrary
# ----------------------------------------------------
def sendMessage():
# Flag to enable/disable Mapepire connection mode
USE_MAPEPIRE = False

# Username to search for in the IBM i system
USERNAME_TO_SEARCH = '<USERNAME>'
MESSAGE_TO_SEND = 'From iLibrary'

try:
# Establish a connection to the IBM i system using the User class
# The context manager ensures proper connection handling (open/close)
with User(DB_USER, DB_PASSWORD, DB_SYSTEM, DB_DRIVER, mapepire=USE_MAPEPIRE) as u:

# Retrieve detailed information for a single user
# - username: the user profile to look up
# Returns data as a JSON string
raw_result = u.send_message_to_user(
username=USERNAME_TO_SEARCH,
message=MESSAGE_TO_SEND,
)

# Convert the JSON string into a Python object (dict or list)
data = json.loads(raw_result)

#TODO ---------------------------------------------
#TODO Write the SendMessage Function to here
# Pretty-print the result for better readability
print(json.dumps(data, indent=4))

# Handle any exceptions that occur during execution
except Exception as e:
# Output the error message for debugging purposes
print(e)


if __name__ == "__main__":
getAllUsers()
getSingleUser()
sendMessage()
2 changes: 1 addition & 1 deletion app/iLibrary/src/iLibrary/Usr/sendMSG.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def send_message_to_user(
# msgtype: str = None,
# rpymsgq: str = None,
ccsid: int = None
):
) -> dict[str, str]:
"""
Sends a message to a specified user on the system. This method interacts with the system
to send a message by executing an SQL query. It validates the required
Expand Down
18 changes: 18 additions & 0 deletions dev_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json
from os.path import join, dirname
import os
from dotenv import load_dotenv
from iLibrary import Library, User, IFS
from os.path import dirname

#load ENV file and get the Connection Settings
dotenv_path = join(dirname(__file__), '.env')
load_dotenv(dotenv_path)
DB_DRIVER = os.environ.get("DB_DRIVER")
DB_USER = os.environ.get("DB_USER")
DB_PASSWORD = os.environ.get("DB_PASSWORD")
DB_SYSTEM = os.environ.get("DB_SYSTEM")


if __name__ == "__main__":
print('Nothing to do')
38 changes: 0 additions & 38 deletions test.py

This file was deleted.

Loading