Skip to content

Commit

Permalink
changed from Text output to ProgressBar output
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolaiVdS committed Jan 18, 2021
1 parent 3cecd5c commit eeb6d84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import requests
import browser_cookie3
import re
import progressbar
from bs4 import BeautifulSoup


Expand Down Expand Up @@ -56,13 +57,13 @@ def get_diffs(own: list, friend: list):


def get_post_id(diffs: list):
print(f"Getting {len(diffs)} song Id's")
song_ids = []
url = 'https://bsaber.com/songs/{}'
for song in diffs:
for song in progressbar.progressbar(diffs):
song_url = url.format(song['song_key'])
soup = BeautifulSoup(requests.get(song_url).content, 'html.parser')
for data_id in soup.findAll("a", attrs={"data-id": re.compile(r"\d+")}):
print(f"found song id for song {song['title']}: {data_id.attrs.get('data-id', None)}")
song_ids.append(data_id.attrs.get("data-id", None))
return song_ids

Expand All @@ -72,7 +73,8 @@ def get_browser_cookies():


def add_to_bookmark(cj: any, song_ids: list):
for song in song_ids:
print(f"adding {len(song_ids)} to your bookmarks.")
for song in progressbar.progressbar(song_ids):
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0',
'Accept': '*/*',
Expand All @@ -91,8 +93,6 @@ def add_to_bookmark(cj: any, song_ids: list):
response = requests.post('https://bsaber.com/wp-admin/admin-ajax.php', headers=headers, cookies=cj, data=data)
if response.status_code != 200:
print(f'error adding song with id {song}')
else:
print(f"added song with song id {song} to your bookmarks.")


if __name__ == '__main__':
Expand Down
1 change: 1 addition & 0 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
requests==2.25.1
beautifulsoup4==4.9.3
browser_cookie3==0.12.0
progressbar2==3.53.1

0 comments on commit eeb6d84

Please sign in to comment.