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("Get: ",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(P,[]) :- total(P).
- task(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_queue_(P,_) :- total(P),!.
- task_queue_(Page,Queue) :-
- thread_send_message(Queue,task(Page,Results)),
- succ(Page,Page0),
- task_queue_(Page0,Queue).
- task_queue(Queue) :-
- message_queue_create(Queue),
- task_queue_(0,Queue).
- %task_mt(1,Time,0,Result).
- main(Queue) :-
- api(Api),
- get_time(Time),
- set_flag(count,0),
- set_flag(time,Time),
- length(Api,Total),
- ( total(_)
- -> retract(total(_))
- ; true),
- assert(total(Total)),
- task_queue(Queue).
- %task_mt(1,Time,0,Result).
- rate_limit :-
- get_flag(count,Count),
- get_flag(time,Time),
- 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),
- flag(count,_,0),
- flag(time,_,Time1)
- ;
- writeln("RL Miss") ).
- :- dynamic total/1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement