Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- api([[[a,10],[b,11],[c,12],[d,13],[e,14]],
- [[f,15],[g,16],[h,16],[i,17],[j,18]],
- [[k,19],[l,20],[m,21],[n,22],[o,23]],
- [[p,24],[q,25],[r,26],[s,27],[t,28]],
- [[u,29],[v,30],[w,31],[x,32],[y,33]]]).
- task_(Count,Time,Page,[],Cont) :-
- succ(Page,Page0),task(Count,Time,Page0,Cont), !.
- task_(Count,Time,Page,[[Abc,Num]|Tuples],[Num|Nums]) :-
- atomic_concat("Got: ",Abc,Log),
- writeln(Log),sleep(2),succ(Count,Count0),
- rate_limit(Count0,Time,Count_rl,Time_rl),
- task_(Count_rl,Time_rl,Page,Tuples,Nums).
- task(_,_,T,[]) :- total(T).
- task(Count,Time,Page,Results) :-
- atomic_concat("Page: ",Page,Log),
- api(Api), writeln(Log),sleep(2),
- nth0(Page,Api,Data),succ(Count,Count0),
- rate_limit(Count0,Time,Count_rl,Time_rl),
- task_(Count_rl,Time_rl,Page,Data,Results).
- task_init(Result) :-
- api(Api),
- get_time(Time),
- length(Api,Total),
- ( total(_)
- -> retract(total(_))
- ; true),
- assert(total(Total)),
- task(1,Time,0,Result).
- rate_limit(Count,Time,Count_rl,Time_rl) :-
- get_time(Time0),
- T_diff is Time0-Time,
- (( T_diff >= 20
- ; Count >= 7 )
- -> Sleep is 21-T_diff,
- atomic_concat("RL: ",Sleep,Log),
- writeln(Log),
- sleep(Sleep),
- get_time(Time1),
- Time_rl = Time1,
- Count_rl = 0
- ;
- writeln("RL Miss"),
- Time_rl = Time,
- Count_rl = Count ).
- :- dynamic total/1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement