Page tree
Skip to end of metadata
Go to start of metadata

These methods are included as convenience shortcuts for end users.

Summary

MethodDescription

print (dict, filename)

Prints a dictionary in a format easier to readlink

formatUtc (dateString)

Formats the provided date string as ISO8601 UTClink



print

Prints a dictionary to the console in a format easier to read. Can alternatively print the dictionary to a text file if a filename is provided.

Used in the examples to print the results returned by other class methods.

Parameter

Type

Description

Example

dictdictionary

Any dictionary (i.e. the returned by other methods in this class)

{'locationCode':'BACAX'}

filenamestring

If present, the dictionary will be printed to a text file with this filename. Can be used to store formatted results from other methods in a text file.

When not present, the dictionary is printed to the console instead.

Default value: None (prints to console)

'output.txt'

(parameters with an underline are required)

Example: Print a list of devices to the console
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')

result = onc.getDevices({ 'locationCode': 'NEP' })
onc.print(result)



formatUtc

Formats the provided date string as a ISO8601 UTC date string (the date format required by the API). Provides an easy way to format dates to include as filters in "dateFrom" and "dateTo" fields.

Parameter

Type

Description

Example

dateStringstring

A string that represents a date & time in any of the formats described in the parser.parse() method. Most date formats work, including:

  • '2016-12-04'
  • '2016-Dec-04, 12:00:00'
  • '2016 Dec 04 03:00 PM'
  • 'now' (returns current UTC date & time)

Default value: 'now'

'2018-09-26, 12:00 PM'

Example: Print an UTC date formated as ISO8601
from onc.onc import ONC
onc = ONC('YOUR_TOKEN_HERE')
myDate = onc.formatUtc('2019-Sept-09 03:00 PM')
print(myDate)

Returns

The UTC date in ISO8601 format, as expected for dates in filters provided to other class methods.

Example of a formated date & time
2019-09-09T15:00:00.000Z
  • No labels