Finally actually using this thing
This commit is contained in:
parent
e9523c2a8f
commit
e3623002f4
45
api.py
45
api.py
|
@ -5,22 +5,24 @@ import bs4
|
||||||
apiver=0.01
|
apiver=0.01
|
||||||
|
|
||||||
urls={}
|
urls={}
|
||||||
|
urls[None]=''
|
||||||
urls['base']='https://us-moe-app.amz-aws.jp'
|
urls['base']='https://us-moe-app.amz-aws.jp'
|
||||||
urls['refresh']='login.php'
|
urls['refresh']='/login.php'
|
||||||
urls['login']='change/check.php'
|
urls['login']='/change/check.php'
|
||||||
urls['loginconf']='change/conf.php'
|
urls['login_conf']='/change/conf.php'
|
||||||
urls['recremove']='give/del_chk.php'
|
urls['rec_remove']='/give/del_chk.php'
|
||||||
urls['charstatus']='room/status.php'
|
urls['char_status']='/room/status.php'
|
||||||
urls['saralink']='friend/rand_get.php' # This doesn't work yet.
|
urls['sara_link']='/friend/rand_get.php' # This doesn't work yet.
|
||||||
urls['item']='item/'
|
urls['item']='/item/'
|
||||||
urls['iralink']='contact/irara_contact_conf.php'
|
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):
|
def get(url=None,params={},headers={},*args,**kwargs):
|
||||||
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']+urls[url],params={'P':conf.p}|params, headers={'User-Agent':uagent()}|headers,*args,**kwargs)
|
||||||
return r.get(urls['base'],headers={'User-Agent':uagent()})
|
|
||||||
|
|
||||||
def post(url,stuff):
|
def post(url,stuff,params={},headers={},*args,**kwargs):
|
||||||
return r.post(f'{urls["base"]}/{urls[url]}?P={conf.p}', data=stuff, headers={'User-Agent':uagent()})
|
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):
|
def uagent(uid=None):
|
||||||
if uid is None: uid=conf.uid
|
if uid is None: uid=conf.uid
|
||||||
|
@ -41,7 +43,7 @@ def top():
|
||||||
|
|
||||||
def login(un,pw):
|
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.
|
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
|
return True
|
||||||
|
|
||||||
def myroom():
|
def myroom():
|
||||||
|
@ -51,3 +53,18 @@ def myroom():
|
||||||
b=bs4.BeautifulSoup(a)
|
b=bs4.BeautifulSoup(a)
|
||||||
myroidname=b.find(attrs={'class':'new_name1'}).find('div').contents[0]
|
myroidname=b.find(attrs={'class':'new_name1'}).find('div').contents[0]
|
||||||
myroidpic=b.find('img',attrs={'alt':'マイロイド'}).attrs['src']
|
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('<input type="hidden" name="id"')+len('<input type="hidden" name="id" value="')
|
||||||
|
end=c.find('"',start+1); idd=c[start:end]
|
||||||
|
for _ in range(rep):
|
||||||
|
post(urls['base']+'/item/conf.php',stuff={'id':idd,'now':''})
|
Loading…
Reference in New Issue
Block a user