This file includes examples of how to invoke all of the methods in the mktste.py file, including to get the OAuth Token. Some method parameters have been ‘parameterized’ in the info.py file, while others are hard-coded in this file and will need to be updated or parameterized, as required. Note that this file will execute all of the methods when it is executed, so any implementation would need to break the methods out into separate executables.

Copy
Copied
import mktste
import json
import info


token = mktste.get_token(info.tokenUrl, info.username, info.password, info.clientId, info.secret)
print('token: ' + token)


# print("Obtaining and saving report -------------------------------------------------------")
# payload = info.reportParams
# data = mktste.get_report(info.fileApiUrl, token, payload, info.reportPath, "CSV")
# with open(info.reportDownloadPath, "wb") as file1:
# 	file1.write(bytearray(data))
# 	file1.close()


# print("Get file and save its contents -------------------------------------------------------")
# data = mktste.get_file(info.fileApiUrl, token, info.fileGuid)
# with open(info.fileDownloadPath, "wb") as file1:
#   file1.write(bytearray(data))
#   file1.close()


# print("Getting schedule data and saving it in a file -----------------------------------------")
# payload = json.dumps({
#   "region": "" + info.region + "",
#   "marketParticipants": [
#     "" + info.participantCode + ""
#   ],
#   "marketStage": "" + info.marketStage + "",
#   "marketStatus": "" + info.marketStatus + "",
#   "firstIntervalBegin": "" + info.firstIntervalBegin + "",
#   "lastIntervalEnd": "" + info.lastIntervalEnd + "",
#   "applications": info.applications,
#   "format": "XML"
# })
# data = mktste.get_schedule_data(info.fileApiUrl, token, payload, "/getScheduleData/test_file", "ScheduleData")
# with open(info.scheduleDataDownloadPath, "wb") as file1:
#   file1.write(bytearray(data))
#   file1.close()
  
  
print("Upload file -------------------------------------------------------")
fileAttributes = json.dumps({
	"location": "" + info.region + "",
	"participant": "" + info.participantShortName + "",
	"intervalBegin": "" + info.uploadIntervalBegin + "",
	"intervalEnd": "" + info.uploadIntervalEnd + "",
	"fileType": "" + info.fileType + "",
	"source": "Client",
	"rendition": "DAM"})
data = mktste.upload_file(info.fileApiUrl, token, info.fileUploadPath, fileAttributes)
print(data.decode("utf-8"))


# print("Status -------------------------------------------------------------")
# data = mktste.get_status(info.fileApiUrl, token, info.fileGuid)
# with open(info.statusDownloadPath, "wb") as file1:
#   file1.write(bytearray(data))
#   file1.close()


# print("File Listing -------------------------------------------------------")
# fileListing = mktste.list_files(info.fileApiUrl, token, info.region, info.participantShortName, info.fileType, info.fileSource, info.fileRendition, True, info.fileIntervalBegin, info.fileIntervalEnd)
# print(fileListing)


# print("Since File Listing -------------------------------------------------------")
# fileListing = mktste.list_files_since(info.fileApiUrl, token, info.region, info.participantShortName, info.fileType, info.fileSource, info.fileRendition, True, info.fileWatermarkDate)
# print(fileListing)