Last active
August 29, 2015 14:21
-
-
Save op01/9b89b962f974f05a23eb to your computer and use it in GitHub Desktop.
admission 58 regno finder
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 | |
idnum = sys.argv[1] | |
MAX = 8200000 | |
N=10 | |
threads = [None] * N | |
results = [None] * N | |
def post(reg,idcard): | |
try: | |
result=requests.post('http://admission.cuas.or.th/adm58/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__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment