mccdv/api.py
2021-10-19 16:14:33 +11:00

53 lines
2.2 KiB
Python

import requests as r
import conf
import bs4
apiver=0.01
urls={}
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'
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 post(url,stuff):
return r.post(f'{urls["base"]}/{urls[url]}?P={conf.p}', data=stuff, headers={'User-Agent':uagent()})
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.
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.
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]
myroidpic=b.find('img',attrs={'alt':'マイロイド'}).attrs['src']