Created
January 8, 2020 23:25
-
-
Save glof2/177bfc1958fa703f5ee8fc5c4f74e53d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#A simple scraping program that provides up-to-date information about 100 cryptocurrencies | |
# | |
import requests | |
from bs4 import BeautifulSoup | |
import time | |
import os | |
from colorama import Fore, init | |
from os import system, name | |
import sys | |
# | |
sys.argv | |
#Init from colorama | |
init() | |
# | |
url = "https://coinmarketcap.com" | |
# | |
def clear(): | |
# for windows | |
if name == 'nt': | |
_ = system('cls') | |
# for mac and linux(here, os.name is 'posix') | |
else: | |
_ = system('clear') | |
# | |
# | |
def checkprice(): | |
page = requests.get(url) | |
soup = BeautifulSoup(page.content, "lxml") | |
name = soup.select(".eTVhdN .cmc-link") | |
marketcap = soup.select(".cmc-table__cell--sort-by__market-cap div") | |
price = soup.select(".cmc-table__cell--sort-by__price .cmc-link") | |
volume24 = soup.select(".cmc-table__cell--sort-by__price .cmc-link") | |
supply = soup.select(".cmc-table__cell--sort-by__circulating-supply div") | |
change24 = soup.select(".cmc-table__cell--sort-by__percent-change-24-h div") | |
cryptoinfo = {} | |
for index in range(len(name)): | |
cryptoinfo.update({name[index].text.lower() : [name[index].text, | |
"Market capacity: " + marketcap[index].text, | |
"Price: " + price[index].text, | |
"Volume (24h): " + volume24[index].text, | |
"Supply: " + supply[index].text, | |
"Change (24h): " + change24[index].text, | |
]}) | |
clear() | |
print("------------------------------") | |
for value in cryptoinfo[cryptoanswer]: | |
print(f"{Fore.GREEN} {value} {Fore.WHITE}") | |
print("------------------------------") | |
# | |
# | |
if len(sys.argv) > 1: | |
cryptoanswer = " ".join(sys.argv[1:]).lstrip().rstrip().lower() | |
else: | |
cryptoanswer = input(f"Cryptocurrency: ").lower() | |
# | |
while True: | |
checkprice() | |
time.sleep(5) | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment