-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGetFinanacialTransscripts.js
73 lines (62 loc) · 2.45 KB
/
GetFinanacialTransscripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Created by: RemcoE33
https://github.com/RemcoE33/apps-script-codebase
From codeline 28 are the functions you can invoke via menu "Transcript".
*/
/**
* Returns selected transscript from financialmodelingprep.
*
* @param {"AAPL"} ticker - Input the stock ticker.
* @param {3} quarter - Input quarter number
* @param {2020} year - Input year number
* @param {"demo"} apikey - Input your apikey
* @return {array} transscript
* @customfunction
*/
function GETTRANSCRIPT(ticker = 'AAPL', quarter = 3, year = 2020, apikey = 'demo'){
const url = `https://financialmodelingprep.com/api/v3/earning_call_transcript/${ticker}?quarter=${quarter}&year=${year}&apikey=${apikey}`
const res = UrlFetchApp.fetch(url)
const data = JSON.parse(res.getContentText())
const split = data[0].content.split(/\n/);
const output = []
split.forEach(line => { output.push([line])})
return output
}
// -------- Functions you can use on other triggers or menu:
function onOpen(e){
const menu = SpreadsheetApp.getUi().createMenu('Transcript')
.addItem('Get transcript in current cell', 'transcript')
.addItem('Set api key', 'setApiKey')
.addItem('Get stored api key', 'readApiKey')
.addToUi()
}
function transcript(){
const paramsRaw = SpreadsheetApp.getUi().prompt(`Enter url parameters '|' separated->: AAPL|3|2020 `).getResponseText()
const params = paramsRaw.split("|")
const prop = PropertiesService.getScriptProperties()
const token = prop.getProperty('TOKEN')
const response = GETTRANSCRIPT(params[0],params[1],params[2],params[3],(token) ? token : 'demo')
const ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet()
const richTextValues = [];
response.forEach(row =>{
const text = row[0]
const colonPositions = text.indexOf(':')
richTextValues.push([SpreadsheetApp.newRichTextValue()
.setText(text)
.setTextStyle(0, colonPositions, SpreadsheetApp.newTextStyle()
.setBold(true)
.build())
.build()])
})
ss.getRange(ss.getCurrentCell().getRow(),ss.getCurrentCell().getColumn(),response.length,1).setRichTextValues(richTextValues)
}
function setApiKey(){
const token = SpreadsheetApp.getUi().prompt('Enter api key:').getResponseText()
const prop = PropertiesService.getScriptProperties()
prop.setProperty('TOKEN', token)
}
function readApiKey(){
const prop = PropertiesService.getScriptProperties()
const token = prop.getProperty('TOKEN')
SpreadsheetApp.getUi().alert((token) ? token : "No token is set")
}