Skip to content

Commit 027869b

Browse files
committed
updated api script
1 parent 862866c commit 027869b

File tree

3 files changed

+46
-16
lines changed

3 files changed

+46
-16
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
/.env
2+
*.csv

coinAPI-pull.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
# Finally, the dataframe that has each crytpo coin value in 30 minute increments is written to a PostgreSQL db table.
1313

1414
from dotenv import load_dotenv
15+
import numpy as np
1516
import os
1617
import requests
1718
import json
1819
import pandas as pd
1920
from datetime import datetime, timedelta
20-
from sqlalchemy import exc, create_engine
21+
from sqlalchemy import exc, create_engine, text
2122
import time
2223

2324
load_dotenv()
@@ -50,22 +51,23 @@
5051
if "status" not in daily_text:
5152
temp_df = pd.read_json(daily_text)
5253
temp_df['exchange_id'] = exchange_id
53-
daily_df = pd.concat([daily_df, temp_df])
54+
daily_df = pd.concat([daily_df, temp_df], ignore_index=True)
5455

5556
time.sleep(3)
5657
else:
5758
time.sleep(15)
5859
except requests.HTTPError as e:
5960
print(f'There was an error: {e}')
60-
61+
62+
daily_df[['time_close', 'time_open', 'time_period_end', 'time_period_start']] = daily_df[['time_close', 'time_open', 'time_period_end', 'time_period_start']].apply(pd.to_datetime, utc=True)
63+
6164

6265
daily_df = daily_df[['exchange_id','rate_close','rate_high','rate_low','rate_open','time_close','time_open','time_period_end','time_period_start']]
63-
64-
# print(daily_df)
66+
daily_df = daily_df.drop_duplicates().sort_values(by='time_period_start', ignore_index=True)
6567

6668
try:
67-
daily_df.to_sql(name = 'daily_crypto_data', con=conn, if_exists='append', index=False)
68-
69+
daily_df.to_sql(name = 'daily_crypto_prod', schema='crypto_data', con=conn, if_exists='append', index=False)
70+
6971
print('data loaded to table')
7072
except exc.SQLAlchemyError as e:
7173
print(f'There was an error: {e}')

requirements.txt

+36-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,47 @@
1-
certifi==2025.1.31
2-
charset-normalizer==3.4.1
1+
anaconda-anon-usage @ file:///croot/anaconda-anon-usage_1710965072196/work
2+
archspec @ file:///croot/archspec_1709217642129/work
3+
boltons @ file:///work/perseverance-python-buildout/croot/boltons_1698851177130/work
4+
Brotli @ file:///croot/brotli-split_1714483155106/work
5+
certifi @ file:///croot/certifi_1725551672989/work/certifi
6+
cffi @ file:///croot/cffi_1726856441404/work
7+
charset-normalizer @ file:///croot/charset-normalizer_1721748349566/work
8+
conda @ file:///croot/conda_1729193882500/work
9+
conda-content-trust @ file:///croot/conda-content-trust_1714483159009/work
10+
conda-libmamba-solver @ file:///croot/conda-libmamba-solver_1727775630457/work/src
11+
conda-package-handling @ file:///croot/conda-package-handling_1718138267740/work
12+
conda_package_streaming @ file:///croot/conda-package-streaming_1718136078615/work
13+
cryptography @ file:///croot/cryptography_1724940562255/work
14+
distro @ file:///croot/distro_1714488253808/work
15+
frozendict @ file:///croot/frozendict_1713194832637/work
316
greenlet==3.1.1
4-
idna==3.10
17+
idna @ file:///croot/idna_1714398848350/work
18+
jsonpatch @ file:///croot/jsonpatch_1714483231291/work
19+
jsonpointer==2.1
20+
libmambapy @ file:///croot/mamba-split_1725563367192/work/libmambapy
21+
menuinst @ file:///croot/menuinst_1723567589013/work
522
numpy==2.2.2
23+
packaging @ file:///croot/packaging_1720101850331/work
624
pandas==2.2.3
25+
platformdirs @ file:///work/perseverance-python-buildout/croot/platformdirs_1701732573265/work
26+
pluggy @ file:///work/perseverance-python-buildout/croot/pluggy_1698805497733/work
727
psycopg==3.2.4
828
psycopg-binary==3.2.4
9-
psycopg-pool==3.2.4
29+
pycosat @ file:///croot/pycosat_1714510623388/work
30+
pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work
31+
PySocks @ file:///work/perseverance-python-buildout/croot/pysocks_1698845478203/work
1032
python-dateutil==2.9.0.post0
1133
python-dotenv==1.0.1
1234
pytz==2025.1
13-
requests==2.32.3
14-
setuptools==75.8.0
35+
requests @ file:///croot/requests_1721410876868/work
36+
ruamel.yaml @ file:///croot/ruamel.yaml_1727980156079/work
37+
ruamel.yaml.clib @ file:///croot/ruamel.yaml.clib_1727769819935/work
38+
setuptools==75.1.0
1539
six==1.17.0
16-
SQLAlchemy==2.0.37
40+
SQLAlchemy==2.0.38
41+
tqdm @ file:///croot/tqdm_1724853939799/work
42+
truststore @ file:///work/perseverance-python-buildout/croot/truststore_1701735771625/work
1743
typing_extensions==4.12.2
1844
tzdata==2025.1
19-
urllib3==2.3.0
20-
wheel==0.45.1
45+
urllib3 @ file:///croot/urllib3_1727769808118/work
46+
wheel==0.44.0
47+
zstandard @ file:///croot/zstandard_1728569189425/work

0 commit comments

Comments
 (0)