Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
231f756
commit 2d8aa27
Showing
5 changed files
with
56 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import codecs | ||
import csv | ||
from datetime import datetime | ||
import os | ||
import requests | ||
import zipfile | ||
|
||
# '2014-12-23' => '1419292800' | ||
def str2unixtime(s): | ||
try: | ||
datetime.strptime(s, '%Y-%m-%d').strftime("%s") | ||
except ValueError: | ||
print('ValueError') | ||
'' | ||
|
||
# Please update your quandl key | ||
URL = 'https://www.quandl.com/api/v3/datasets/CUR/JPY.csv?api_key=mCkqGja_5orzQJxF5RhQ' | ||
OUTPUT_FILE_PATH = '/src/data/output.csv' | ||
|
||
# GET raw data | ||
r = requests.get(URL) | ||
with open('/tmp/raw.csv', 'wb') as file: | ||
file.write(r.content) | ||
|
||
# CONVERT data into CSV along with converting date to unixtime | ||
with open(OUTPUT_FILE_PATH, 'w', newline='') as output: | ||
spamwriter = csv.writer(output, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) | ||
with codecs.open('/tmp/raw.csv', 'r') as input: | ||
spamreader = csv.reader(input, delimiter=',', quotechar='"') | ||
for row in spamreader: | ||
spamwriter.writerow([str2unixtime(row[0]), row[1]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters