mccdv/api.py

71 lines
3.2 KiB
Python
Raw Permalink Normal View History

2021-10-19 16:14:33 +11:00
import requests as r
import conf
import bs4
apiver=0.01
urls={}
2021-11-11 23:54:12 +11:00
urls[None]=''
2021-10-19 16:14:33 +11:00
urls['base']='https://us-moe-app.amz-aws.jp'
2021-11-11 23:54:12 +11:00
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,params={},headers={},*args,**kwargs):
2022-10-18 07:54:13 +11:00
pp={'P':conf.p} if conf.p else {}
return r.get(urls['base']+urls[url],params=pp|params, headers={'User-Agent':uagent()}|headers,*args,**kwargs)
2021-11-11 23:54:12 +11:00
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)
2021-10-19 16:14:33 +11:00
def uagent(uid=None):
if uid is None: uid=conf.uid
country='AU' # Let players spoof this, ofc.
ver=30 # Move this to config file for player to bump up at their leisure.
browse=f'MCCDV/{apiver}'
#browse="Mozilla/5.0 (Linux; Android 8.0.0; SHIFT6m Build/O00623; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/70.0.3538.110 Mobile Safari/537.36" TODO: Use this or similar for masking client
return f'{browse}/{country}/AMBITION_UA/GooglePlay/Android-/MOE_ver{ver}:{uid}'
def top():
pag=get()
stoof=pag.content.decode('utf-8')
start=stoof.index('?&P=')+4 # That needs a rewrite
end=stoof[start:].index('#')+start
conf.p=stoof[start:end]
return conf.p
# This function only really needs to return a P value (which it should actually just store in conf instead), and current login state. I suppose returning newsposts is good too, since they're there.
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.
2021-11-11 23:54:12 +11:00
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.
2021-10-19 16:14:33 +11:00
return True
def myroom():
a=''
while 'alt="マイロイド"' not in a:
a=get('refresh').content.decode('utf-8')
b=bs4.BeautifulSoup(a)
myroidname=b.find(attrs={'class':'new_name1'}).find('div').contents[0]
2021-11-11 23:54:12 +11:00
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':''})