Skip to content

Commit

Permalink
v6
Browse files Browse the repository at this point in the history
  • Loading branch information
bobermilk committed Feb 24, 2023
1 parent 7a0d47a commit 0b10aa6
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_VERSION=5
APP_VERSION=6

api_get_interval=0.1
osu_get_interval=3 # osu site
Expand Down
48 changes: 35 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ def reset_job_toggle_button_text():
# called when jobs are completed
main_window.m_toggle_downloading.SetLabelText(constants.activity_start)

def show_dialog(msg, ok=None):
def show_dialog(msg, ok=None, focus_main=True):
focus=main_window
if not focus_main:
focus=add_source_window
# called when new release dropped on github
dlg = wx.MessageDialog(main_window,
dlg = wx.MessageDialog(focus,
msg,
"Alert OwO", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
result = dlg.ShowModal()
Expand Down Expand Up @@ -285,16 +288,22 @@ async def onDestroy(self, event):
#User closed application
if main_window != None:
main_window.m_add_source.Enable()
main_window.SetFocus()

async def add_userpage(self, event):
links=self.m_userpages.GetValue()
links=self.m_userpages.GetValue().strip()
scope=[self.m_user_top100.GetValue(), self.m_user_favourites.GetValue(), self.m_user_everything.GetValue(),
self.m_user_ranked.GetValue(), self.m_user_loved.GetValue(), self.m_user_pending.GetValue(), self.m_user_graveyarded.GetValue()]
success=True
if not "ppy.sh/users/" in links:
show_dialog("You need to input a link to the osu user profile", focus_main=False)
success=False
if all(x==0 for x in scope):
show_dialog("You need to select something to download from the userpage!")
else:
show_dialog("You need to select something to download from the userpage!", focus_main=False)
success=False
if success:
self.Destroy()
StartCoroutine(main_window.add_userpage(links, scope), main_window)
StartCoroutine(main_window.add_userpage(links, scope), main_window)

async def add_tournament(self, event):
selection=self.m_tournament.GetPageText(self.m_tournament.GetSelection())
Expand All @@ -308,15 +317,28 @@ async def add_mappack(self, event):
await data.Sources.add_mappack_source(ids)

async def add_osucollector(self, event):
links=self.m_osu_collector.GetValue()
self.Destroy()
StartCoroutine(main_window.add_osucollector(links), main_window)
success=True
links=self.m_osu_collector.GetValue().strip()
if not "osucollector.com/collections/" in links:
show_dialog("You need to input osucollector collection url", focus_main=False)
success=False
if success:
self.Destroy()
StartCoroutine(main_window.add_osucollector(links), main_window)

async def add_osuweblinks(self, event):
title=self.m_osu_weblinks_key.GetValue()
links=self.m_osu_weblinks.GetValue()
self.Destroy()
StartCoroutine(main_window.add_osuweblinks(title, links), main_window)
success=True
title=self.m_osu_weblinks_key.GetValue().strip()
links=self.m_osu_weblinks.GetValue().strip()
if not title:
show_dialog("You need to name the collection", focus_main=False)
success=False
if not "ppy.sh/beatmapsets/" in links:
show_dialog("You need to input beatmaps for this collection", focus_main=False)
success=False
if success:
self.Destroy()
StartCoroutine(main_window.add_osuweblinks(title, links), main_window)

async def change_mappack_section(self, event):
selection=str(self.m_mappack_section.GetSelection())
Expand Down
9 changes: 6 additions & 3 deletions scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def get_userpage_beatmaps(source):
cached_beatmap_ids=set()
for beatmap in source.all_beatmaps:
cached_beatmap_ids.add(beatmap[1])
for i, item in enumerate(j):
for i, item in enumerate(j, 1):
beatmap_id=item['beatmap_id']
pub.sendMessage("show.loading", msg=f"Getting beatmap data from osu! api ({i}/{len(j)})")
if data.Settings.valid_oauth and not beatmap_id in cached_beatmap_ids:
Expand Down Expand Up @@ -145,7 +145,7 @@ async def get_tournament_beatmaps(source):
cached_beatmap_ids=set()
for beatmap in source.all_beatmaps:
cached_beatmap_ids.add(beatmap[1])
for i, beatmap in enumerate(beatmaps):
for i, beatmap in enumerate(beatmaps, 1):
pub.sendMessage("show.loading", msg=f"Getting beatmap data from osu! api ({i}/{len(beatmaps)})")
if data.Settings.valid_oauth and not beatmap[1] in cached_beatmap_ids:
checksum, beatmapset_id=await api.query_osu_beatmap(session, beatmap[1])
Expand Down Expand Up @@ -199,8 +199,11 @@ async def get_osuweblinks_beatmaps(source):
all_beatmaps.add((beatmapset_id, None, None))

async with aiohttp.ClientSession() as session:
for beatmap_id in source.get_beatmap_ids():
for i, beatmap_id in enumerate(source.get_beatmap_ids(), 1):
pub.sendMessage("show.loading", msg=f"Getting beatmap data from osu! api ({i}/{len(source.get_beatmap_ids())})")
beatmap_checksum, beatmapset_id = await api.query_osu_beatmap(session, beatmap_id)
if (beatmapset_id, None, None) in all_beatmaps:
all_beatmaps.remove((beatmapset_id, None, None))
all_beatmaps.add((beatmapset_id, beatmap_id, beatmap_checksum))

pub.sendMessage("show.loading", msg=None)
Expand Down

0 comments on commit 0b10aa6

Please sign in to comment.