From e3623002f40e699f7cf4bad863fbd73c0d3d58cb Mon Sep 17 00:00:00 2001 From: Zergling_man Date: Thu, 11 Nov 2021 23:54:12 +1100 Subject: [PATCH] Finally actually using this thing --- api.py | 47 ++++++++++++++++++++++++++++++++--------------- main.py | 6 +++++- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/api.py b/api.py index a2f8dff..b62a80a 100644 --- a/api.py +++ b/api.py @@ -5,22 +5,24 @@ import bs4 apiver=0.01 urls={} +urls[None]='' urls['base']='https://us-moe-app.amz-aws.jp' -urls['refresh']='login.php' -urls['login']='change/check.php' -urls['loginconf']='change/conf.php' -urls['recremove']='give/del_chk.php' -urls['charstatus']='room/status.php' -urls['saralink']='friend/rand_get.php' # This doesn't work yet. -urls['item']='item/' -urls['iralink']='contact/irara_contact_conf.php' +urls['refresh']='/login.php' +urls['login']='/change/check.php' +urls['login_conf']='/change/conf.php' +urls['rec_remove']='/give/del_chk.php' +urls['char_status']='/room/status.php' +urls['sara_link']='/friend/rand_get.php' # This doesn't work yet. +urls['item']='/item/' +urls['ira_link']='/contact/irara_contact_conf.php' +urls['start_study']='/study/conf.php' +urls['time_items']='/study/time_item.php' -def get(url=None): - if url is not None: return r.get(f'{urls["base"]}/{urls[url]}',params={'P':conf.p}, headers={'User-Agent':uagent()}) - return r.get(urls['base'],headers={'User-Agent':uagent()}) +def get(url=None,params={},headers={},*args,**kwargs): + return r.get(urls['base']+urls[url],params={'P':conf.p}|params, headers={'User-Agent':uagent()}|headers,*args,**kwargs) -def post(url,stuff): - return r.post(f'{urls["base"]}/{urls[url]}?P={conf.p}', data=stuff, headers={'User-Agent':uagent()}) +def post(url,stuff,params={},headers={},*args,**kwargs): + return r.post(urls['base']+urls[url], data=stuff, params={'P':conf.p}|params, headers={'User-Agent':uagent()}|headers,*args,**kwargs) def uagent(uid=None): if uid is None: uid=conf.uid @@ -41,7 +43,7 @@ def top(): def login(un,pw): pag=post('login',{'id':un,'pass':pw}) # We don't actually care about the result of this. We know exactly what comes next. Though this would be useful for error handling, I suppose. - pag2=post('loginconf',{'id':un,'pass':pw}) # We also don't care about this; if we got this far, it's guaranteed to succeed. Probably should still parse it and check, JUST IN CASE. + pag2=post('login_conf',{'id':un,'pass':pw}) # We also don't care about this; if we got this far, it's guaranteed to succeed. Probably should still parse it and check, JUST IN CASE. return True def myroom(): @@ -50,4 +52,19 @@ def myroom(): a=get('refresh').content.decode('utf-8') b=bs4.BeautifulSoup(a) myroidname=b.find(attrs={'class':'new_name1'}).find('div').contents[0] - myroidpic=b.find('img',attrs={'alt':'マイロイド'}).attrs['src'] \ No newline at end of file + myroidpic=b.find('img',attrs={'alt':'マイロイド'}).attrs['src'] + +def startstudy(studyid): # This needs a lot of upgrades, like a local list of study names/effects to IDs + post(urls['base']+urls['start_study'],{'id':studyid,'time':0}) + +def reducetime(rep=1): # Repetition thing doesn't need to be built into the API, but it's a valuable time-saving measure + p=get(urls['base']+urls['time_items'],params={'ftime':1}) + c=p.content.decode('utf-8') + start=c.find('jp/item')+len('jp/item/detail.php?P=')+len(params['P'])+len('&id=') + end=c.find('#',start); idd=c[start:end] + p=get(urls['base']+'/item/detail.php',params={'id':idd}) + c=p.content.decode('utf-8') + start=c.find('