-
Notifications
You must be signed in to change notification settings - Fork 276
/
new_listings_scraper.py
76 lines (61 loc) · 2.34 KB
/
new_listings_scraper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from chromedriver_py import binary_path
import os.path, json
from store_order import *
from load_config import *
from send_notification import *
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(executable_path=binary_path, options=chrome_options)
driver.get("https://www.binance.com/en/support/announcement/c-48")
def get_last_coin():
"""
Scrapes new listings page for and returns new Symbol when appropriate
"""
latest_announcement = driver.find_element(By.ID, 'link-0-0-p1')
latest_announcement = latest_announcement.text
# Binance makes several annoucements, irrevelant ones will be ignored
exclusions = ['Futures', 'Margin', 'adds']
for item in exclusions:
if item in latest_announcement:
return None
enum = [item for item in enumerate(latest_announcement)]
#Identify symbols in a string by using this janky, yet functional line
uppers = ''.join(item[1] for item in enum if item[1].isupper() and (enum[enum.index(item)+1][1].isupper() or enum[enum.index(item)+1][1]==' ' or enum[enum.index(item)+1][1]==')') )
return uppers
def store_new_listing(listing):
"""
Only store a new listing if different from existing value
"""
if os.path.isfile('new_listing.json'):
file = load_order('new_listing.json')
if listing in file:
print("No new listings detected...")
return file
else:
file = listing
store_order('new_listing.json', file)
#print("New listing detected, updating file")
send_notification(listing)
return file
else:
new_listing = store_order('new_listing.json', listing)
send_notification(listing)
#print("File does not exist, creating file")
return new_listing
def search_and_update():
"""
Pretty much our main func
"""
while True:
latest_coin = get_last_coin()
if latest_coin:
store_new_listing(latest_coin)
else:
pass
print("Checking for coin announcements every 2 hours (in a separate thread)")
return latest_coin
time.sleep(60*180)