Advertisement
Guest User

Untitled

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