|
@@ -13,49 +13,73 @@ sys.path.append(os.path.join(os.path.abspath(__file__).split('auto')[0] + 'auto'
|
|
|
from utils.utils_send_gotify import *
|
|
from utils.utils_send_gotify import *
|
|
|
|
|
|
|
|
|
|
|
|
|
-def get_coinmarketcap_coin_price(url, target):
|
|
|
|
|
|
|
+def get_coinmarketcap_coin_price():
|
|
|
|
|
+ url_list = [
|
|
|
|
|
+ ['BTC', 'https://coinmarketcap.com/currencies/bitcoin/'],
|
|
|
|
|
+ ['ETH', 'https://coinmarketcap.com/currencies/ethereum/'],
|
|
|
|
|
+ ['SOL', 'https://coinmarketcap.com/currencies/solana/'],
|
|
|
|
|
+ ['SUI', 'https://coinmarketcap.com/currencies/sui/'],
|
|
|
|
|
+ ['DOGE', 'https://coinmarketcap.com/currencies/dogecoin/'],
|
|
|
|
|
+ ['ARB', 'https://coinmarketcap.com/currencies/arbitrum/'],
|
|
|
|
|
+ ['ATH', 'https://coinmarketcap.com/currencies/aethir/']
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
headers = {
|
|
headers = {
|
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107"
|
|
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107"
|
|
|
}
|
|
}
|
|
|
- resp = httpx.get(url=url, headers=headers)
|
|
|
|
|
|
|
|
|
|
- if resp.status_code == 301:
|
|
|
|
|
- print(resp.text)
|
|
|
|
|
- return None
|
|
|
|
|
- elif resp.status_code != 200:
|
|
|
|
|
- print(resp.status_code)
|
|
|
|
|
- return None
|
|
|
|
|
|
|
+ result = ''
|
|
|
|
|
+ for data_list in url_list:
|
|
|
|
|
+ url = data_list[1]
|
|
|
|
|
+ target = data_list[0]
|
|
|
|
|
|
|
|
- resp.encoding = 'utf-8'
|
|
|
|
|
- page = resp.text
|
|
|
|
|
|
|
+ try:
|
|
|
|
|
+ resp = httpx.get(url=url, headers=headers)
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ print(f'target: {target}, {e}')
|
|
|
|
|
+ time.sleep(5)
|
|
|
|
|
+ continue
|
|
|
|
|
|
|
|
- text = re.findall('<strong>(.*?)</p></div><div class="sc-65e7f566-0', page)[0] if re.findall(
|
|
|
|
|
- '<strong>(.*?)</p></div><div class="sc-65e7f566-0', page) else 'No Data'
|
|
|
|
|
|
|
+ result += f'target: {target}\n'
|
|
|
|
|
|
|
|
- text = re.sub(r'</strong>', '', text)
|
|
|
|
|
- text = re.sub(r'<!-- -->', '', text)
|
|
|
|
|
|
|
+ if resp.status_code == 301:
|
|
|
|
|
+ print(resp.text)
|
|
|
|
|
+ return None
|
|
|
|
|
+ elif resp.status_code != 200:
|
|
|
|
|
+ print(resp.status_code)
|
|
|
|
|
+ return None
|
|
|
|
|
|
|
|
- result = f'target: {target}\n'
|
|
|
|
|
- prices = re.findall(r'\$(\d+\.\d+)', text)
|
|
|
|
|
- if prices:
|
|
|
|
|
- result += f'prices: ${prices[0]}\n'
|
|
|
|
|
|
|
+ resp.encoding = 'utf-8'
|
|
|
|
|
+ page = resp.text
|
|
|
|
|
|
|
|
- volumes = re.findall(r'\$(\d{1,3}(?:,\d{3})*(?:\.\d+)?)', text)
|
|
|
|
|
- if volumes:
|
|
|
|
|
- result += f'24-hour trading volume: ${volumes[1]}\n'
|
|
|
|
|
|
|
+ text = re.findall('<strong>(.*?)</p></div><div class="sc-65e7f566-0', page)[0] if re.findall(
|
|
|
|
|
+ '<strong>(.*?)</p></div><div class="sc-65e7f566-0', page) else 'No Data'
|
|
|
|
|
|
|
|
- change = re.findall(r'(up|down) (\d+\.\d+)%', text)
|
|
|
|
|
- if change:
|
|
|
|
|
- c = ' '.join(change[0])
|
|
|
|
|
- result += f'change: {c}%\n'
|
|
|
|
|
|
|
+ text = re.sub(r'</strong>', '', text)
|
|
|
|
|
+ text = re.sub(r'<!-- -->', '', text)
|
|
|
|
|
|
|
|
- live_market_cap = re.findall(r'\$(\d{1,3}(?:,\d{3})*(?:\.\d+)?)', text)
|
|
|
|
|
- if live_market_cap:
|
|
|
|
|
- result += f'live market cap: ${live_market_cap[2]}\n'
|
|
|
|
|
|
|
+ prices = re.findall(r'\$(\d+\.\d+)', text)
|
|
|
|
|
+ if prices:
|
|
|
|
|
+ result += f'prices: ${prices[0]}\n'
|
|
|
|
|
|
|
|
- max_circulating_supply = re.findall(r'(\d{1,3}(?:,\d{3})*)', text)
|
|
|
|
|
- if max_circulating_supply:
|
|
|
|
|
- result += f'max circulating supply: {max_circulating_supply[-1]}'
|
|
|
|
|
|
|
+ volumes = re.findall(r'\$(\d{1,3}(?:,\d{3})*(?:\.\d+)?)', text)
|
|
|
|
|
+ if volumes:
|
|
|
|
|
+ result += f'24-hour trading volume: ${volumes[1]}\n'
|
|
|
|
|
+
|
|
|
|
|
+ change = re.findall(r'(up|down) (\d+\.\d+)%', text)
|
|
|
|
|
+ if change:
|
|
|
|
|
+ c = ' '.join(change[0])
|
|
|
|
|
+ result += f'change: {c}%\n'
|
|
|
|
|
+
|
|
|
|
|
+ live_market_cap = re.findall(r'\$(\d{1,3}(?:,\d{3})*(?:\.\d+)?)', text)
|
|
|
|
|
+ if live_market_cap:
|
|
|
|
|
+ result += f'live market cap: ${live_market_cap[2]}\n'
|
|
|
|
|
+
|
|
|
|
|
+ max_circulating_supply = re.findall(r'(\d{1,3}(?:,\d{3})*)', text)
|
|
|
|
|
+ if max_circulating_supply:
|
|
|
|
|
+ result += f'max circulating supply: {max_circulating_supply[-1]}\n'
|
|
|
|
|
+
|
|
|
|
|
+ time.sleep(2)
|
|
|
|
|
|
|
|
return result + '\n\n'
|
|
return result + '\n\n'
|
|
|
|
|
|
|
@@ -97,32 +121,24 @@ def get_vix_data():
|
|
|
return result
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
-if __name__ == '__main__':
|
|
|
|
|
- url_list = [
|
|
|
|
|
- ['BTC', 'https://coinmarketcap.com/currencies/bitcoin/'],
|
|
|
|
|
- ['ETH', 'https://coinmarketcap.com/currencies/ethereum/'],
|
|
|
|
|
- ['SOL', 'https://coinmarketcap.com/currencies/solana/'],
|
|
|
|
|
- ['SUI', 'https://coinmarketcap.com/currencies/sui/'],
|
|
|
|
|
- ['DOGE', 'https://coinmarketcap.com/currencies/dogecoin/'],
|
|
|
|
|
- ['ARB', 'https://coinmarketcap.com/currencies/arbitrum/'],
|
|
|
|
|
- ['ATH', 'https://coinmarketcap.com/currencies/aethir/']
|
|
|
|
|
- ]
|
|
|
|
|
|
|
+def get_crypto_fear_and_greed_index():
|
|
|
|
|
+ url = 'https://coinmarketcap.com/charts/fear-and-greed-index/'
|
|
|
|
|
|
|
|
- text = ''
|
|
|
|
|
|
|
|
|
|
- for data_list in url_list:
|
|
|
|
|
- res = get_coinmarketcap_coin_price(data_list[1], data_list[0])
|
|
|
|
|
- if res:
|
|
|
|
|
- text += res
|
|
|
|
|
- time.sleep(2)
|
|
|
|
|
|
|
+def main():
|
|
|
|
|
+ text = get_coinmarketcap_coin_price()
|
|
|
|
|
|
|
|
res = get_vix_data()
|
|
res = get_vix_data()
|
|
|
if res:
|
|
if res:
|
|
|
text += res
|
|
text += res
|
|
|
|
|
|
|
|
- print(text)
|
|
|
|
|
|
|
+
|
|
|
|
|
|
|
|
if text:
|
|
if text:
|
|
|
GotifyNotifier('Real-time coin price\n', text).send_message()
|
|
GotifyNotifier('Real-time coin price\n', text).send_message()
|
|
|
else:
|
|
else:
|
|
|
print('No Data')
|
|
print('No Data')
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+if __name__ == '__main__':
|
|
|
|
|
+ main()
|