removed console app modules

This commit is contained in:
StevanFreeborn
2022-05-02 12:46:49 -05:00
parent 0501c54a82
commit ce7a10fe83
2 changed files with 0 additions and 452 deletions
-293
View File
@@ -1,293 +0,0 @@
import json
import mimetypes
import os
from requests import request
from OnspringClient import OnspringClient
from Models import *
from Enums import *
#connectivity
def PrintCanConnect(client: OnspringClient):
print(client.CanConnect())
# apps
def PrintGetApps(client: OnspringClient):
response = client.GetApps()
print(f'Status Code: {response.statusCode}')
print(f'Page Size: {response.data.pageSize}')
print(f'Page Number: {response.data.pageNumber}')
print(f'Total Pages: {response.data.totalPages}')
print(f'Total Records: {response.data.totalRecords}')
for app in response.data.apps:
print(f'Id: {app.id}')
print(f'Name: {app.name}')
print(f'href: {app.href}')
def PrintGetAppById(client: OnspringClient, appId: int):
response = client.GetAppById(appId)
print(f'Status Code: {response.statusCode}')
print(f'id: {response.data.app.id}')
print(f'Name: {response.data.app.name}')
print(f'href: {response.data.app.href}')
def PrintGetAppsByIds(client: OnspringClient, appIds: list[int]):
response = client.GetAppsByIds(appIds)
print(f'Status Code: {response.statusCode}')
print(f'Count: {response.data.count}')
for app in response.data.apps:
print(f'Id: {app.id}')
print(f'Name: {app.name}')
print(f'href: {app.href}')
# fields
def PrintField(field: Field):
print('Field:')
print(f' Id: {field.id}')
print(f' App Id: {field.appId}')
print(f' Name: {field.name}')
print(f' Type: {field.type}')
print(f' Status: {field.status}')
print(f' IsRequired: {field.isRequired}')
print(f' IsUnique: {field.isUnique}')
if field.type == 'Formula':
print(f' Output Type: {field.outputType}')
if field.outputType == 'ListValue':
print(f' Multiplicity: {field.multiplicity}')
print(' Values:')
for value in field.values:
print(f' {value.AsString()}')
if field.type == 'List':
print(f' Multiplicity: {field.multiplicity}')
print(' Values:')
for value in field.values:
print(f' {value.AsString()}')
def PrintGetFieldById(client: OnspringClient, fieldId: int):
response = client.GetFieldById(fieldId)
print(f'Status Code: {response.statusCode}')
if response.isSuccessful:
PrintField(response.data.field)
else:
print(f'Message: {response.message}')
# files
def PrintGetFileById(client: OnspringClient, recordId: int, fieldId: int, fileId: int):
response = client.GetFileById(recordId, fieldId, fileId)
print(f'Status Code: {response.statusCode}')
print(f'Name: {response.data.file.name}')
print(f'Content Type: {response.data.file.contentType}')
print(f'Content Length: {response.data.file.contentLength}')
def PrintGetFileInfoById(client: OnspringClient, recordId: int, fieldId: int, fileId: int):
response = client.GetFileInfoById(recordId, fieldId, fileId)
print(f'Status Code: {response.statusCode}')
print(f'Name: {response.data.fileInfo.name}')
print(f'Type: {response.data.fileInfo.type}')
print(f'Owner: {response.data.fileInfo.owner}')
print(f'Content Type: {response.data.fileInfo.contentType}')
print(f'Created Date: {response.data.fileInfo.createdDate}')
print(f'Modified Date: {response.data.fileInfo.modifiedDate}')
print(f'File Href: {response.data.fileInfo.fileHref}')
def PrintSaveFile(client: OnspringClient, filePath: str, recordId: int, fieldId: int, notes: str=None, modifiedDate: datetime=None):
filePath = filePath
fileName = os.path.basename(filePath)
contentType = mimetypes.guess_type(filePath)
request = SaveFileRequest(
recordId,
fieldId,
fileName,
filePath,
contentType,
notes,
modifiedDate)
response = client.SaveFile(request)
print(f'Status Code: {response.statusCode}')
print(f'File Id: {response.data.id}')
# records
def PrintGetRecordsByAppId(client: OnspringClient, appId: int):
request = GetRecordsByAppRequest(appId, dataFormat=DataFormat.Raw.name)
response = client.GetRecordsByAppId(request)
print(f'Status Code: {response.statusCode}')
print(f'Page Size: {response.data.pageSize}')
print(f'Page Number: {response.data.pageNumber}')
print(f'Total Pages: {response.data.totalPages}')
print(f'Total Records: {response.data.totalRecords}')
for record in response.data.records:
print(f'AppId: {record.appId}')
print(f'RecordId: {record.recordId}')
for field in record.fields:
print(f'Type: {field.type}')
print(f'FieldId: {field.fieldId}')
print(f'Value: {field.GetResultValueString()}')
def PrintGetRecordById(client: OnspringClient, appId: int, recordId: int, fieldIds: list[int]=[], dataFormat: str=DataFormat.Raw.name):
request = GetRecordByIdRequest(
appId,
recordId,
fieldIds,
dataFormat)
response = client.GetRecordById(request)
print(f'Status Code: {response.statusCode}')
print(f'AppId: {response.data.appId}')
print(f'RecordId: {response.data.recordId}')
for field in response.data.fields:
print(f'Type: {field.type}')
print(f'FieldId: {field.fieldId}')
print(f'Value: {field.GetResultValueString()}')
def PrintDeleteRecord(client: OnspringClient, appId: int, recordId: int):
response = client.DeleteRecordById(appId, recordId)
print(f'Status Code: {response.statusCode}')
print(f'Message: {response.message}')
def PrintGetRecordsByIds(client: OnspringClient, appId: int, recordIds: list[int], fieldIds: list[int]=[], dataFormat: str=DataFormat.Raw.name):
request = GetBatchRecordsRequest(
appId,
recordIds,
fieldIds,
dataFormat)
response = client.GetRecordsByIds(request)
print(f'Status Code: {response.statusCode}')
print(f'Count: {response.data.count}')
for record in response.data.records:
print(f'AppId: {record.appId}')
print(f'RecordId: {record.recordId}')
for field in record.fields:
print(f'Type: {field.type}')
print(f'FieldId: {field.fieldId}')
print(f'Value: {field.GetResultValueString()}')
def PrintQueryRecords(client: OnspringClient, appId: int, filter: str, fieldIds: list[int]=[], dataFormat: str=DataFormat.Raw.name, pagingRequest: PagingRequest=PagingRequest(1,50)):
request = QueryRecordsRequest(
appId,
filter,
fieldIds,
dataFormat,
pagingRequest)
response = client.QueryRecords(request)
print(f'Status Code: {response.statusCode}')
print(f'Page Size: {response.data.pageSize}')
print(f'Page Number: {response.data.pageNumber}')
print(f'Total Pages: {response.data.totalPages}')
print(f'Total Records: {response.data.totalRecords}')
for record in response.data.records:
print(f'AppId: {record.appId}')
print(f'RecordId: {record.recordId}')
for field in record.fields:
print(f'Type: {field.type}')
print(f'FieldId: {field.fieldId}')
print(f'Value: {field.GetResultValueString()}')
def PrintAddOrUpdateRecord(client: OnspringClient, appId: int, fields: list[RecordFieldValue], recordId: int=None):
record = Record(
appId,
fields,
recordId)
response = client.AddOrUpdateRecord(record)
print(f'Status Code: {response.statusCode}')
print(f'Id: {response.data.id}')
for warning in response.data.warnings:
print(f'Warning: {warning}')
def PrintDeleteRecordsByIds(client: OnspringClient, appId: int, recordIds: list[int]):
request = DeleteBatchRecordsRequest(appId, recordIds)
response = client.DeleteRecordsByIds(request)
print(f'Status Code: {response.statusCode}')
print(f'Message: {response.message}')
# reports
def PrintGetReportById(client: OnspringClient, reportId: int, apiDataFormat: str=DataFormat.Raw.name, dataFormat: str=ReportDataType.ReportData.name):
request = GetReportByIdRequest(reportId, apiDataFormat, dataFormat)
response = client.GetReportById(request)
print(f'Status Code: {response.statusCode}')
print('Columns:')
print(f'{", ".join(response.data.columns)}')
print('Rows:')
for row in response.data.rows:
print(f'Record Id {row.recordId}: {", ".join([str(cell) for cell in row.cells])}')
def PrintGetReportsByAppId(client: OnspringClient, appId: int, pagingRequest: PagingRequest=PagingRequest(1,50)):
response = client.GetReportsByAppId(appId, pagingRequest)
print(f'Status Code: {response.statusCode}')
print(f'App Id: {appId}')
print('Reports:')
for report in response.data.reports:
print(f' Id: {report.id}')
print(f' Name: {report.name}')
print(f' Description: {report.description}')
-159
View File
@@ -1,159 +0,0 @@
import sys
from OnspringClient import OnspringClient
from configparser import ConfigParser
from Models import *
from Enums import *
from Commands import *
cfg = ConfigParser()
cfg.read('config.ini')
key = cfg['prod']['key']
url = cfg['prod']['url']
onspring = OnspringClient(url, key)
def main():
argsLength = len(sys.argv)
if not argsLength > 1:
print('No valid command given')
return
command = sys.argv[1].lower()
if command =='connect':
PrintCanConnect(onspring)
if command == 'getapps':
PrintGetApps(onspring)
return
if command == 'getappbyid':
PrintGetAppById(onspring, 195)
return
if command == 'getappsbyids':
PrintGetAppsByIds(onspring, [195, 240])
return
if command == 'getfieldbyid':
PrintGetFieldById(onspring, 9686 )
return
if command == 'getfileinfobyid':
if not argsLength > 4:
print('Please provide record id, fieldId, and fileId values')
return
recordId = sys.argv[2]
fieldId = sys.argv[3]
fileId = sys.argv[4]
PrintGetFileInfoById(onspring, recordId, fieldId, fileId)
return
if command == 'savefile':
PrintSaveFile(
onspring,
'C:\\Users\\sfree\\OneDrive\\Desktop\\Test Attachment.txt',
60,
6989
)
return
if command == 'getrecordsbyappid':
PrintGetRecordsByAppId(onspring, 195)
return
if command == 'getrecordbyid':
PrintGetRecordById(onspring, 195, 3,dataFormat=DataFormat.Raw.name)
return
if command == 'deleterecord':
PrintDeleteRecord(onspring, 195, sys.argv[2])
return
if command == 'getrecordsbyids':
PrintGetRecordsByIds(onspring, 195, [1, 2], [6983, 6984])
return
if command == 'queryrecords':
fieldId = 6983
operator = 'eq'
value = '\'Test Task 5\''
PrintQueryRecords(onspring, 195, f'{fieldId} {operator} {value}')
return
if command == 'addrecord':
fields = [
StringFieldValue(6983, 'A New Test Task'),
StringFieldValue(6984, 'This is a test task.')
]
PrintAddOrUpdateRecord(onspring, 195, fields)
return
if command == 'updaterecord':
fields = [
StringFieldValue(6983, 'Updated'),
StringFieldValue(6984, 'Updated')
]
PrintAddOrUpdateRecord(onspring, 195, fields, 60)
return
if command == 'deleterecordsbyids':
appId = sys.argv[2]
ids = sys.argv[3].split(',')
recordIds = [int(id) for id in ids]
PrintDeleteRecordsByIds(onspring, appId, recordIds)
return
if command == 'getreportbyid':
if not argsLength > 2:
print('Please provide report id value')
return
reportId = sys.argv[2]
if argsLength > 3:
apiDataFormat = sys.argv[3]
else:
apiDataFormat = DataFormat.Raw.name
if argsLength > 4:
dataType = sys.argv[4]
else:
dataType = ReportDataType.ReportData.name
PrintGetReportById(onspring, reportId, apiDataFormat, dataType)
return
if command == 'getreportsbyappid':
if not argsLength > 2:
print('Please provide app id value')
return
appId = sys.argv[2]
PrintGetReportsByAppId(onspring, appId)
return
print('No valid command given')
return
if __name__ == "__main__":
main()