forked from drift-labs/driftpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape.py
54 lines (42 loc) · 1.05 KB
/
scrape.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
#%%
from gazpacho import get
from bs4 import BeautifulSoup
url = 'https://github.com/drift-labs/protocol-v2/releases'
html = get(url)
soup = BeautifulSoup(html, 'html.parser')
divs = soup.find_all("div", class_="clearfix container-xl px-3 px-md-4 px-lg-5 mt-4")
#%%
div = divs[0]
div = list(div.children)[5]
#%%
info = div.find('section')
program_id = info.find('h2').text
commit = info.find_all("code")[0].text
print(program_id, commit)
#%%
## update config program_id
with open("src/driftpy/constants/config.py", 'r') as f:
data = f.read()
import re
result = re.search("clearing_house_program_id=PublicKey\(\'(.*)\'\)", data)
old_id = result.group(1)
data = data.replace(old_id, program_id)
with open("src/driftpy/constants/config.py", 'w') as f:
f.write(data)
#%%
# update protocol commit
from subprocess import Popen
Popen(
'git fetch --all'.split(' '),
cwd='protocol-v2/'
).wait()
#%%
Popen(
f'git checkout {commit}'.split(' '),
cwd='protocol-v2/'
).wait()
#%%
Popen(
'bash update_idl.sh'.split(' '),
).wait()
print('done! :)')