Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d660980

Browse files
Merge pull request #1067 from vkb20/main
Crypto price checker
2 parents 27a4c96 + 0a387c7 commit d660980

File tree

6 files changed

+134
-0
lines changed

6 files changed

+134
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Related Issue
2+
3+
- Using python script to fetch the top 100 cryptocurrencies from https://www.cointracker.io/ and then displaying cryptocurrency name and price.
4+
5+
- [x] Hacktoberfest2021 Participant
6+
- [x] Contributor
7+
8+
Closes: #957
9+
10+
### Describe the changes you've made
11+
12+
I did all the tasks from scratch. Created the crypto_price_checker.py file for script. Created README.md file for explaining the project. Added relevant screenshots and added requirement.txt file.
13+
14+
## Type of change
15+
16+
What sort of change have you made:
17+
<!--
18+
Example how to mark a checkbox:-
19+
- [x] My code follows the code style of this project.
20+
-->
21+
- [ ] Bug fix (non-breaking change which fixes an issue)
22+
- [x] New feature (non-breaking change which adds functionality)
23+
- [ ] Code style update (formatting, local variables)
24+
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
25+
- [ ] This change requires a documentation update
26+
27+
## How Has This Been Tested?
28+
29+
I ran the script in the command prompt
30+
31+
## Checklist:
32+
<!--
33+
Example how to mark a checkbox:-
34+
- [x] My code follows the code style of this project.
35+
-->
36+
- [x] My code follows the guidelines of this project.
37+
- [x] I have performed a self-review of my own code.
38+
- [x] I have commented my code, particularly whereever it was hard to understand.
39+
- [x] I have made corresponding changes to the documentation.
40+
- [x] My changes generate no new warnings.
41+
- [x] I have added tests that prove my fix is effective or that my feature works.
42+
- [x] Any dependent changes have been merged and published in downstream modules.
43+
44+
## Screenshots
45+
![crypto_output_1](https://user-images.githubusercontent.com/88720381/139568849-d6de7888-4c5b-4b54-b708-6f4ae52b71cf.png)
46+
47+
![crypto_output_2](https://user-images.githubusercontent.com/88720381/139568851-ed73bd55-fce9-43eb-9c52-d72806347d58.png)
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
## Crypto Price Checker
2+
3+
## Aim
4+
5+
To fetch live top-100 cryptocurrency prices scraped from cointracker.io
6+
7+
## Purpose
8+
9+
Instead of users manually looking for live prices they can run the script easily to get the prices of cryptocurrencies.
10+
11+
## Short description of package/script
12+
13+
- The script navigates to website "https://www.cointracker.io/price" and then finds out the top 100 cryptocurrencies on that
14+
webpage and then prints the price of all the cryptocurrencies in that webpage.
15+
- Libraries imported : requests, bs4 (beautiful soup).
16+
17+
18+
## Workflow of the Project
19+
20+
I am getting the data from website "https://www.cointracker.io/price" and in this site there are tags with class name
21+
"d-flex no-underline" and for all 100 cryptocurrencies I am finding this class and storing the "price/<cryptocurrency>" in the list
22+
and then looping through the list and then navigating to website "https://www.cointracker.io/" + "price/<cryptocurrency>". Then I am
23+
finding the div tag with class name "my-auto h4" and then converting the data received to string. Then I am finding the first index
24+
of price string and looping till the end of price string. Then for each cryptocurrency I am printing it's name and it's price.
25+
26+
27+
## Setup instructions
28+
29+
Just press "run" on IDLE or write "python crypto_price_checker.py" on command prompt.
30+
31+
32+
## Detailed explanation of script, if needed
33+
34+
Explained above
35+
36+
37+
## Compilation Steps
38+
39+
Explained above
40+
41+
## Author(s)
42+
43+
Varun Kumar
44+
45+
46+
## Disclaimers, if any
47+
48+
Use this section to mention if any particular disclaimer is required
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import requests
2+
import bs4
3+
4+
url = "https://www.cointracker.io/price"
5+
req = requests.get(url)
6+
scrap = bs4.BeautifulSoup(req.text, 'html.parser')
7+
8+
#getting list of individual sites to get price data
9+
individual_sites = [tag['href'] for tag in scrap.find_all('a', {'class':"d-flex no-underline"})]
10+
11+
for i in range(len(individual_sites)):
12+
#appending the string for each "i" to "https://www.cointracker.io".
13+
url2 = "https://www.cointracker.io" + individual_sites[i]
14+
req2 = requests.get(url2)
15+
scrap2 = bs4.BeautifulSoup(req2.text, 'html.parser')
16+
17+
#getting the cryptocurreny name from the string
18+
crypto_name = individual_sites[i][7:]
19+
20+
#getting the data where the price is present and converting it to string
21+
findClass = scrap2.find('div', {'class':'my-auto h4'})
22+
findClassStr = str(findClass)
23+
24+
#finding index from which price of cryptocurrency starts
25+
idx = findClassStr.find("data-price-container-symbol=")
26+
idx = findClassStr.find(">", idx, len(findClassStr))
27+
idx = idx+1
28+
price_str = ""
29+
30+
#looping till I get the complete price as a string
31+
while(findClassStr[idx]!="<"):
32+
price_str = price_str + findClassStr[idx]
33+
idx = idx+1
34+
print("crptocurrency : " + crypto_name + " and 1 " + crypto_name + " = " + price_str)
35+
36+
177 KB
Loading[フレーム]
175 KB
Loading[フレーム]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Libraries used :
2+
1) requests
3+
2) Beautiful Soup

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /