Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the files for Crypto Currency Tracker #1050

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Date & Time,Price (Intraday),Change,% Change,Market Cap,Volume in Currency (Since 0:00 UTC),Volume in Currency (24Hr),Total Volume All Currencies (24Hr),Circulating Supply
11:34:51 2021-10-13,439.00,+29.89,+7.31%,73.813B,4.162B,4.162B,4.162B,168.137M
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Date & Time,Price (Intraday),Change,% Change,Market Cap,Volume in Currency (Since 0:00 UTC),Volume in Currency (24Hr),Total Volume All Currencies (24Hr),Circulating Supply
11:34:51 2021-10-13,"55,262.86","-2,290.62",-3.98%,1.041T,39.668B,39.668B,39.668B,18.842M
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Date & Time,Price (Intraday),Change,% Change,Market Cap,Volume in Currency (Since 0:00 UTC),Volume in Currency (24Hr),Total Volume All Currencies (24Hr),Circulating Supply
11:34:51 2021-10-13,2.1037,-0.0298,-1.40%,69.221B,3.386B,3.386B,3.386B,32.905B
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Date & Time,Price (Intraday),Change,% Change,Market Cap,Volume in Currency (Since 0:00 UTC),Volume in Currency (24Hr),Total Volume All Currencies (24Hr),Circulating Supply
11:34:51 2021-10-13,"3,467.42",-49.69,-1.41%,408.827B,17.488B,17.488B,17.488B,117.905M
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed: 0,Unnamed: 0.1,Unnamed: 0.1.1,Unnamed: 0.1.1.1,Unnamed: 0.1.1.1.1,Unnamed: 0.1.1.1.1.1,Unnamed: 0.1.1.1.1.1.1,Unnamed: 0.1.1.1.1.1.1.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Date & Time,Price (Intraday),Change,% Change,Market Cap,Volume in Currency (Since 0:00 UTC),Volume in Currency (24Hr),Total Volume All Currencies (24Hr),Circulating Supply
11:34:51 2021-10-13,1.0004,+0.0001,+0.01%,68.807B,72.262B,72.262B,72.262B,68.779B
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from bs4 import BeautifulSoup
from datetime import datetime
from datetime import date
import time
import pandas as pd
import requests

c = 0
# some coin names to be scraped.
CoinsNames = ["Bitcoin-USD", "Ethereum-USD", "HEX-USD", "Cardano-USD", "Tether-USD"]

while True:
now = datetime.now()
current_time = str(
now.strftime("%H:%M:%S") + " " + str(date.today())
) # this is just to get the time at the time of web scraping
print(f"At time : {current_time} IST")

# url to be scraped.
url = "https://finance.yahoo.com/cryptocurrencies/"
response = requests.get(url, headers={"Referer": "https://finance.yahoo.com/"})

text = response.text
html_data = BeautifulSoup(text, "html.parser")
headings = html_data.find_all("tr")[0]
headings_list = []
for x in headings:
headings_list.append(x.text)

headings_list = headings_list[2:10]
headings_list.insert(0, "Date & Time")

# path for the csv files, which needs to be changed as per the user.
path = "D:\hacktoberfest\General-Purpose-Scripts\scripts\CryptoCurrencyTracker\CoinsData"
datum = {}
if c == 0:
datum = {}
c += 1

else:
for coin in CoinsNames:
try:
df = pd.read_csv(path + "\\" + coin + ".csv")
except:
df = pd.DataFrame()

datum[coin] = df

for x in range(1, 6):
rows = html_data.find_all("tr")[x]
column_value = rows.find_all("td")
row = []
for i in range(10):
row.append(column_value[i].text)

name = row[1].replace(" ", "-")
row = row[2:]
row.insert(0, current_time)

if name not in datum.keys():
datum[name] = pd.DataFrame([row], columns=headings_list)

else:
temp = pd.DataFrame([row], columns=headings_list)
print(row)
datum[name] = pd.concat([datum[name], temp])

# To write to the csv files.
for eachone in datum.keys():
newpath = path + "\\" + eachone + ".csv"
datum[eachone].to_csv(path + "\\" + eachone + ".csv", index=False)

# to delete the response and creae a new instance
del response
time.sleep(600)
7 changes: 7 additions & 0 deletions WebScrapingScripts/CryptoCurrencyTracker/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Crypto Currency Tracker

I have used requests module to get the http data from the given url
then used bs4 module to extract the required information
After retrieving the data, used pandas module to handle loading and reading of data from csv files.

This bot scrapes the url for every 10 minutes, get the latest data related to the coins and then adds the new data to the csv files
5 changes: 5 additions & 0 deletions WebScrapingScripts/CryptoCurrencyTracker/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
requests
bs4
datetime
time
pandas