-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparse_utils.py
31 lines (29 loc) · 1.07 KB
/
parse_utils.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
import requests
from bs4 import BeautifulSoup as bs
def get_response_soup(url):
response = requests.get(url)
return bs(response.text, 'html')
accord_list = ['C', 'F', 'Gm', 'Dm', 'Bb', 'B', 'E', 'Em', 'Eb', 'Fm', 'Fb', 'Am', 'G', 'D', 'A', 'Bm', 'G6sus2', '3x223x', 'F#m']
def if_accords(text):
if '|' in text or '*' in text:
return True
list_tmp = text.split(' ')
for word in list_tmp:
if word in accord_list:
return True
return False
def prepare_song(soup):
tmp_string = soup.find('div',class_='js-store')['data-content'].split('content":"')[1].split("revision")[0]
tmp_string = tmp_string.replace('\\r', '').replace('\t', '').replace('[tab]', '').replace('[/tab]', '').replace('[ch]', '').replace('[/ch]', '').split('\\n')
filtered_data = []
for tmp in tmp_string:
if len(tmp) > 0 and tmp[0] != '[' and tmp != ' ':
filtered_data.append(tmp)
chords = []
texts = []
for tmp in filtered_data:
if if_accords(tmp):
chords.append(tmp)
else:
texts.append(tmp)
return {'chords':chords, 'texts':texts, 'all':filtered_data}