Spaces:
Sleeping
Sleeping
Download app.py from Pezh/Hou: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/Pezh/Hou/resolve/main/app.py
- Command line
-
hf download hf://spaces/Pezh/Hou/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Pezh/Hou/resolve/main/app.py
1.4 kB
| import requests | |
| import pandas as pd | |
| # Your API Key (you need to replace 'YOUR_API_KEY' with your actual CryptoCompare API key) | |
| api_key = '1606c591d78cde143733502669d97c3707d94637e2c32c3184bef54a2a1653d2' | |
| # The base URL for the CryptoCompare API | |
| base_url = 'https://min-api.cryptocompare.com/data/v2/histohour' | |
| # Parameters for the API call | |
| # In this example, we are getting hourly data for Bitcoin (BTC) priced in USD | |
| parameters = { | |
| 'fsym': 'BTC', | |
| 'tsym': 'USD', | |
| 'limit': 2000, # The maximum number of data points you can get in one call is 2000 | |
| 'api_key': api_key | |
| } | |
| # Make the API call | |
| response = requests.get(base_url, params=parameters) | |
| # Check if the request was successful | |
| if response.status_code == 200: | |
| # Parse the received JSON data | |
| data = response.json() | |
| # Extract the data points | |
| data_points = data['Data']['Data'] | |
| # Create a DataFrame from the data points | |
| df = pd.DataFrame(data_points) | |
| # Convert timestamps to human-readable dates | |
| df['time'] = pd.to_datetime(df['time'], unit='s') | |
| # Save the DataFrame to a CSV file | |
| df.to_csv('crypto_hourly_data.csv', index=False) | |
| print(df) | |
| #print("Data extraction successful, saved to crypto_hourly_data.csv") | |
| else: | |
| print(f"Failed to fetch data: {response.status_code}") | |
| # Make sure to install pandas and requests modules if you haven't already | |
| # pip install pandas requests |