Created
May 30, 2016 14:10
-
-
Save op01/076d5d7789f4d36b308a4bcd7643c729 to your computer and use it in GitHub Desktop.
admission 59 utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests,threading,time,sys,re | |
MAX = 9200000 | |
MIN = 9000000 | |
N=10 | |
threads = [None] * N | |
results = [None] * N | |
def post(reg,idcard): | |
try: | |
result=requests.post('http://admission.cuas.or.th/adm59/findpdf_result.php',{'regno':str(reg),'pplid':str(idcard),'submit':'ค้รหาใบสมัคร'}) | |
except requests.exceptions.ConnectionError: | |
print("\ncon err %d"%reg) | |
return post(reg,idcard) | |
index=result.text.find('ไม่พบข้อมูลดังกล่าวในฐานข้อมูลผู้สมัคร') | |
return index | |
def worker(i,idx): | |
if post(i,idnum)==-1: | |
results[idx]=-1 | |
print("\nFOUND or error %d"%i) | |
def main(): | |
start=0 | |
with open('save.txt','r') as f: | |
start=int(f.read()) | |
print("continue at %d"%start) | |
for i in range(start,MAX,N): | |
print("at %d * %d"%(i,N),end='') | |
st = time.time() | |
for idx in range(N): | |
threads[idx]=threading.Thread(target=worker,args=(i+idx,idx)) | |
threads[idx].start() | |
for j in threads: | |
j.join() | |
total = time.time()-st | |
for j in results: | |
if j==-1: | |
print('...') | |
return 0 | |
print(" remain","%.2f"%((MAX-i)*total/N/60),"min\r",end='') | |
with open('save.txt','w') as f: | |
f.write('%d'%(i+N)) | |
if __name__ == '__main__': | |
if sys.argv[1]=='init': | |
print('Init save...') | |
with open('save.txt','w') as f: | |
f.write(str(MIN)) | |
print('Done') | |
exit(0) | |
idnum = sys.argv[2] | |
if sys.argv[1]=='select': | |
main() | |
regno=sys.argv[3] | |
if sys.argv[1]=='pdf': | |
result=requests.post('http://admission.cuas.or.th/adm59/findpdf_result.php',{'regno':str(regno),'pplid':str(idnum),'submit':'ค้รหาใบสมัคร'}) | |
result=re.search(r'<input type="hidden" name="pdf" value="([\w\.]+)">',result.text) | |
pdf=result.group(1) | |
with open('reg.pdf','wb') as f: | |
r=requests.get('http://admission.cuas.or.th/adm59/pdffiles/'+pdf) | |
f.write(r.content) | |
elif sys.argv[1]=='score': | |
with open('score.html','wb') as f: | |
r=requests.post('http://admission.cuas.or.th/adm59check/result.php',data={'input_regno':regno,'input_pplid':idnum}) | |
f.write(r.content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment