Advertisement
Guest User

Untitled

a guest
May 31st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.77 KB | None | 0 0
  1. <?php
  2.  
  3. ini_set('memory_limit','16M');
  4.  
  5. //define('PILLAR','PILLAR');
  6. //require_once('/home/soxred93/pillar/trunk/class.pillar.php');
  7. require_once('/home/soxred93/rfalib3.php');
  8.  
  9. //$pillar = Pillar::ini_launch('/home/soxred93/configs/rfx-report.cfg');
  10. //$site = $pillar->cursite;*/
  11.  
  12. //include '/home/soxred93/wikibot.classes.php';
  13. include '/home/soxred93/MPUploadBot/botclasses.php';
  14. $pass = file_get_contents('/home/soxred93/.password');
  15. $user = "SoxBot";
  16.  
  17. //Setting needed vars
  18. $chris = new wikipedia;
  19. $wpapi = $chris;
  20. $wpi = $chris;
  21. $wpq = $chris;
  22.  
  23. //Logging in
  24. //$wpapi->login($user,$pass);
  25. var_dump($user);
  26. var_dump($pass);
  27. echo "$user $pass";
  28. $chris->login($user,$pass);
  29. echo "Logged In!\n\n";
  30.  
  31. echo "Checking whether or not bot is enabled...\n\n";
  32. $enablepage = "User:SoxBot/Run/RfXReport";
  33. /*try {
  34.     $run = new Page($site,$enablepage);
  35.     $run = $run->get_text();
  36. } catch (PillarException $e) {
  37.     die( "Got an error when getting the enable page.\n" );
  38. }*/
  39. $run = $wpq->getpage($enablepage);
  40. if( !preg_match( '/(enable|yes|run|go|start)/i', $run ) ) {
  41.     die( "Bot is disabled.\n" );
  42. }
  43.  
  44. echo "Searching for RfX's on the main RfA page...\n\n";
  45. $findrfa = "/\{\{Wikipedia:Requests for adminship\/(.*)\}\}/";
  46. $findrfb = "/\{\{Wikipedia:Requests for bureaucratship\/(.*)\}\}/";
  47.  
  48. //$rfabuffer = new Page($site,"Wikipedia:Requests for adminship");
  49. //$rfabuffer = $rfabuffer->get_text();
  50.  
  51. $rfabuffer = $wpq->getpage("Wikipedia:Requests for adminship");
  52.  
  53. $numrfa = 0;
  54. $numrfb = 0;
  55.  
  56. $out = "<noinclude>{{shortcut|WP:RFXR||WP:BNRX|WP:BN/RfX Report}}</noinclude>\n{| {{{style|align=\"{{{align|right}}}\" cellspacing=\"0\" cellpadding=\"0\" style=\"white-space:wrap; clear: {{{clear|left}}}; margin-top: 0em; margin-bottom: .5em; float: {{{align|right}}};padding: .5em 0em 0em 1.4em; background: none;\"}}}\n|\n{| class=\"wikitable\"\n";
  57.  
  58. echo "Processing RfA's...\n\n";
  59.  
  60. preg_match_all($findrfa, $rfabuffer, $matches);
  61. $out .= "! RfA candidate !! S !! O !! N !! S% !! Ending (UTC) !! Time left !! Dups? !! Report";
  62. foreach ($matches[1] as $rfa) {
  63.     if ($rfa != "Front matter" && $rfa != "bureaucratship") {
  64.         $result = processrfx($rfa);
  65.         $out = $out . "\n|-\n" . $result;
  66.         $numrfa++;
  67.         sleep(5);
  68.     }
  69. }
  70.  
  71. echo "Processing RfB's...\n\n";
  72.  
  73. preg_match_all($findrfb, $rfabuffer, $matches);
  74. $out .= "\n|-\n! RfB candidate !! S !! O !! N !! S% !! Ending (UTC) !! Time left !! Dups? !! Report";
  75. foreach ($matches[1] as $rfb) {
  76.     $result = processrfx($rfb,"bureaucrat");
  77.     $out = $out . "\n|-\n" . $result;
  78.     $numrfb++;
  79.     sleep(5);
  80. }
  81.  
  82. $out .= "\n|}<div align=\"right\">\n''Last updated by '''~~~''' at '''~~~~~'''''\n</div>\n|}\n";
  83.  
  84. echo "FINAL RESULT: $out\n\n";
  85.  
  86. echo "Posting results...\n\n";
  87.  
  88. $output = "User:X!/RfX Report";
  89. /*try {
  90.     $reportbuffer = new Page($site,$output);
  91.     $reportbuffer = $reportbuffer->put($out, "Updating RFB Report, $numrfa RFAs, $numrfb RFBs");
  92. } catch( PillarException $e ) {
  93.     die( $e );
  94. }*/
  95. $chris->edit($output,$out,"Updating RFB Report, $numrfa RFAs, $numrfb RFBs");
  96.  
  97. function bailout($message) {
  98.     echo "Fatal Error\n";
  99.     echo "$message\n";
  100.     exit;
  101. }
  102.  
  103. function countDown($time) {
  104.   // make a unix timestamp for the given date
  105.   $c = $time;
  106.  
  107.   // get current unix timestamp
  108.   $t = time();
  109.  
  110.   // calculate the difference
  111.   $d = ($c - $t);
  112.   if ($d < 0) $d = 0;
  113.  
  114.   $days = floor($d/60/60/24);
  115.   $hours = floor(($d - $days*60*60*24)/60/60);
  116.   $mins = floor(($d - $days*60*60*24 - $hours*60*60)/60);
  117.  
  118.   return array('days' => $days, 'hours' => $hours, 'mins' => $mins);
  119.  
  120. }
  121.  
  122. function processrfx($candidate, $ship = "admin") {
  123.     global $site, $wpq;
  124.     $ship_initial = strtoupper( $ship[0] );
  125.    
  126.     echo "Loading Request for " . $ship . "ship for $candidate...\n\n";
  127.     $rfabasename = "Wikipedia:Requests for " . $ship . "ship/";
  128.    
  129.     $myRFA = new RFA();
  130.    
  131.     //$buffer = new Page($site,$rfabasename . $candidate);
  132.     //$buffer = $buffer->get_text();
  133.     $buffer = $wpq->getpage($rfabasename . $candidate);
  134.  
  135.     echo "Analyzing Rf" . $ship_initial . "...\n\n";
  136.     $result = $myRFA->analyze($buffer);
  137.     $section_support = $myRFA->support;
  138.     $section_oppose = $myRFA->oppose;
  139.     $section_neutral = $myRFA->neutral;
  140.  
  141.     if ($result !== TRUE) {
  142.         bailout($myRFA->lasterror);
  143.     }
  144.    
  145.     $enddate = $myRFA->enddate;
  146.     $enddate2 = strtotime($enddate);
  147.     $now = time();
  148.     echo "End Date: $enddate... \n\n";
  149.     echo "End Date in Unix time: $enddate2... \n\n";
  150.     echo "Current Unix Time: $now...\n\n";
  151.  
  152.     if ($now > $enddate2) {
  153.         echo "$now (current time) is greater than $enddate2 (ending time). \n";
  154.         echo "Rf{$ship_initial} is expired.\n\n";
  155.         $s1 = '|expired=yes';
  156.         $timeleft = "Pending closure...";
  157.     }
  158.     else {
  159.         echo "$now (current time) is less than $enddate2 (ending time). \n";
  160.         echo "Rf{$ship_initial} is not expired.\n\n";
  161.        
  162.         echo "Calculating time left until Rf{$ship_initial} is closed...\n\n";
  163.         $timeleft = countDown($enddate2);
  164.         $timeleft = $timeleft['days']. ' days, ' . $timeleft['hours'] . ' hours';
  165.     }
  166.    
  167.     if( $ship == "bureaucrat" ) {
  168.         $append = "|crat=yes";
  169.     }
  170.     else {
  171.         $append = "|rfa=yes";
  172.     }
  173.    
  174.     $opposes = count($section_oppose);
  175.     $supports = count($section_support);
  176.     $neutrals = count($section_neutral);
  177.    
  178.     $tally = count($supports).'/'.count($opposes).'/'.count($neutrals);
  179.     echo "Supports: $supports...\nOpposes: $opposes...\nNeutrals: $neutrals...\n\n";
  180.    
  181.     echo "Searching for duplicates...\n\n";
  182.     $n_dup = 0;
  183.     foreach($myRFA->duplicates as $dup) {
  184.         $n_dup++;
  185.     }
  186.  
  187.     if ($n_dup > 0) {
  188.         echo "Duplicate votes were found...\n\n";
  189.         $dups = "'''yes'''";
  190.     }
  191.     else {
  192.         echo "No duplicates found...\n\n";
  193.         $dups = "no";
  194.     }
  195.  
  196.     return "{{Bureaucrat candidate|candidate= $candidate|support= $supports|oppose= $opposes|neutral= $neutrals|end date= $enddate |time left=$timeleft|dups= $dups" . $s1 . $append . "}}";
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement