-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
46 lines (32 loc) · 1 KB
/
main.py
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
#Python Version 3.6.3
import json
import urllib3
import numpy as np
import sys
from scipy.io.wavfile import write
def normalize(nums):
return np.int16(nums/np.max(np.abs(nums)) * (2 ** 15 - 1))
def repeat(nums, n):
result = []
for i in range(0, n):
for j in nums:
result += [j]
return np.array(result)
def construct(nums):
result = []
for i in range(0, len(nums)):
result += [nums[i] + nums[len(nums) - i - 1]]
return np.array(result)
def main():
apiKey = ""
with open("./Key.txt", "r") as keyFile:
apiKey = keyFile.readline()
caller = urllib3.PoolManager()
url = "https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=" + sys.argv[1] + "&apikey=" + apiKey
data = list(json.loads(caller.request("GET", url).data)['Time Series (Daily)'].values())
vals = []
for i in range(0, len(data)):
vals.insert(0, float(data[i]['4. close']) - float(data[i]['1. open']))
vals = np.array(vals)
write("./" + sys.argv[1] + ".wav", 44100, normalize(construct(repeat(vals, 1000))))
main()