-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_listings_scraper.py
60 lines (48 loc) · 1.9 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
import requests
import os.path, json
import time
from store_order import *
from load_config import *
def get_last_coin():
"""
Scrapes new listings page for and returns new Symbol when appropriate
"""
latest_announcement = requests.get("https://www.binance.com/bapi/composite/v1/public/cms/article/catalog/list/query?catalogId=48&pageNo=1&pageSize=15")
latest_announcement = latest_announcement.json()
latest_announcement = latest_announcement['data']['articles'][0]['title']
# Binance makes several annoucements, irrevelant ones will be ignored
exclusions = ['Futures', 'Margin', 'adds', '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:
return file
else:
file = listing
store_order('new_listing.json', file)
print("New listing detected, updating file")
return file
else:
new_listing = store_order('new_listing.json', 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)
print("Checking for coin announcements every 1 minute (in a separate thread)")
time.sleep(10)