EPM 集成代理脚本示例

以下脚本示例显示了如何调用外部 API,API 用于提供兑换率,然后准备数据以便采用 Oracle Enterprise Performance Management Cloud 的“数据交换”部分中定义的集成可处理的格式上传。EPM 云中的设置步骤使用代理实例作为集成的数据源,使用 EPM 应用程序作为目标。注意,此脚本只是一个示例,不保证无任何缺陷,用户不能就与该脚本相关的任何疑问或问题向 Oracle 支持部门提出服务请求。

''' This jython script calls an external API to get exchange rates, and then generates a file which is picked up by the EPM Integration Agent '''

import json
import urllib2

''' Turn off SQL processing by AGENT '''

agentAPI.skipAction('true')

''' Set Proxy for HTTP call. Needed when connected via VPN ''' 

proxy = urllib2.ProxyHandler({'http': 'www-proxy.example.com:80' 'https': 'www-proxy.example.com:80'})
opener = urllib2.build_opener(proxy) urllib2.install_opener(opener)

''' Set up URL for rates download.  Please see the URL for additional information in regards to options. ''' 

currency = 'USD'
ratesurl = 'https://api.exchangeratesapi.io/latest?base=' + currency
fxrates = urllib2.urlopen(ratesurl)
text = json.loads(fxrates.read())
allrates = text['rates']

agentAPI.logInfo("Jython Script - RateExtract: URL - " + str(ratesurl))

''' Generate file for loading into the EPM Cloud '''

outfilename = agentContext["DATAFILENAME"]
outfile = open(outfilename, "w")

''' Generate header row '''

outfile.write("Account,Currency,Entity,From Currency,Scenario,View,Rate" + chr(10))

''' Generate a row for each rate '''

for toCur,toRate in allrates.iteritems():
    mystr = "Ending Rate" + "," + str(toCur) + "," + "FCCS_Global Assumptions" + "," + "FROM_" + str(currency) + "," + "Actual" + "," + "FCCS_Periodic" + "," + str(toRate) + chr(10)
    outfile.write(mystr)

outfile.close() 

agentAPI.logInfo("Jython Script - RateExtract: Output File Name - " + str(outfilename))