0% found this document useful (0 votes)
51 views2 pages

BC Exp 10 Output

Uploaded by

2021.rishi.kokil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views2 pages

BC Exp 10 Output

Uploaded by

2021.rishi.kokil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

!

pip install requests tweepy pandas

Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (2.32.3)


Requirement already satisfied: tweepy in /usr/local/lib/python3.10/dist-packages (4.14.0)
Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (2.1.4)
Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests) (3.7)
Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests) (2.0.7)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests) (2024.7.4)
Requirement already satisfied: oauthlib<4,>=3.2.0 in /usr/local/lib/python3.10/dist-packages (from tweepy) (3.2.2)
Requirement already satisfied: requests-oauthlib<2,>=1.2.0 in /usr/local/lib/python3.10/dist-packages (from tweepy) (1.3.1)
Requirement already satisfied: numpy<2,>=1.22.4 in /usr/local/lib/python3.10/dist-packages (from pandas) (1.26.4)
Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.10/dist-packages (from pandas) (2.8.2)
Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas) (2024.1)
Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas) (2024.1)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)

import requests
import pandas as pd

# --- 1. CoinGecko: Collect Cryptocurrency Data ---


def fetch_crypto_data(crypto_id, days='30'):
url = f'https://api.coingecko.com/api/v3/coins/{crypto_id}/market_chart'
params = {
'vs_currency': 'usd',
'days': days,
}
response = requests.get(url, params=params)
data = response.json()
prices = pd.DataFrame(data['prices'], columns=['timestamp', 'price'])
prices['timestamp'] = pd.to_datetime(prices['timestamp'], unit='ms')
return prices

crypto_data = fetch_crypto_data('bitcoin')
crypto_data

timestamp price

0 2024-07-14 08:04:57.924 60097.322837

1 2024-07-14 09:09:58.821 60271.268699

2 2024-07-14 10:09:20.681 60177.292570

3 2024-07-14 11:03:36.203 59941.156134

4 2024-07-14 12:04:19.221 60118.991512

... ... ...

715 2024-08-13 04:20:55.826 58948.845279

716 2024-08-13 05:23:49.709 59206.268295

717 2024-08-13 06:19:46.177 59210.936414

718 2024-08-13 07:02:50.292 59392.980705

719 2024-08-13 07:43:32.000 59289.746171

720 rows × 2 columns

import datetime

# --- 2. NewsAPI: Collect News Articles ---


def fetch_news(query, from_date, to_date):
url = 'https://newsapi.org/v2/everything'
params = {
'q': query,
'from': from_date,
'to': to_date,
'sortBy': 'relevance',
'apiKey': '5d0d7726e8e141b1bfb90959c2086d8b',
'language': 'en',
}
response = requests.get(url, params=params)
articles = response.json()['articles']
news_df = pd.DataFrame(articles)
return news_df[['publishedAt', 'title', 'description', 'url']]

today = datetime.datetime.now().strftime('%Y-%m-%d')
one_week_ago = (datetime.datetime.now() - datetime.timedelta(days=7)).strftime('%Y-%m-%d')
news_data = fetch_news('bitcoin', one_week_ago, today)
news_data
publishedAt title description u

What
Happened From Bitcoin
2024-08- in Crypto bouncing back
0 https://finance.yahoo.com/news/happened-crypto
07T10:16:05Z Today: above 56K to
Bullish perman...
Signals...

Recent
Bitcoin
movements in
2024-08- Investors
1 the https://en.bitcoinhaber.net/bitcoin-investors
07T08:28:23Z Buy Puts
cryptocurrency
Aggressively
market ...

Stock The Bank of


market Japan
2024-08-
2 today: Dow suggested on https://markets.businessinsider.com/news/stock
07T13:45:50Z
jumps 285 Wednesday it
points as tr... wo...

Google
@jason_kint:
Strategy
2024-08- wow an

import requests, json

def fetch_eth_block_data():
url = 'https://api.etherscan.io/api'
params = {
'module': 'block',
'action': 'getblockreward',
'blockno': '2165403',
'apikey': 'GJYHYZDW27Z4AEWYPSBGPIK4IWZMR2QIZC'
}
response = requests.get(url, params=params)
data = response.json()
return data['result']

block_data = fetch_eth_block_data()
block_str = json.dumps(block_data, indent=4)
print(f'Latest Ethereum Block Number: {block_str}')

Latest Ethereum Block Number: {


"blockNumber": "2165403",
"timeStamp": "1472533979",
"blockMiner": "0x13a06d3dfe21e0db5c016c03ea7d2509f7f8d1e3",
"blockReward": "5314181600000000000",
"uncles": [
{
"miner": "0xbcdfc35b86bedf72f0cda046a3c16829a2ef41d1",
"unclePosition": "0",
"blockreward": "3750000000000000000"
},
{
"miner": "0x0d0c9855c722ff0c78f21e43aa275a5b8ea60dce",
"unclePosition": "1",
"blockreward": "3750000000000000000"
}
],
"uncleInclusionReward": "312500000000000000"
}

You might also like