CSESC.php 2.98 KB
Newer Older
Freddy's avatar
Freddy committed
1 2
#!/usr/bin/php
<?php
Freddy's avatar
Freddy committed
3
include 'Core/BotCore.php';
Freddy's avatar
Freddy committed
4 5 6 7 8 9 10 11 12 13 14
/** CSGroenland.php
* Aktualisiert die Neuen Artikel im Portal ESC
* @Author Freddy2001 <freddy2001@wikipedia.de>
* @Version 0.1
* @Status Alpha
*/

class CSESC extends Core {
	public function editCheck ($Job) {
		$allowed = $this->readPage("User:LarusBot/active/" . $Job);
		if($allowed == "true") {
Freddy's avatar
Freddy committed
15
			echo "Job nicht gesperrt";
Freddy's avatar
Freddy committed
16
		} else {
Freddy's avatar
Freddy committed
17
			die("Job durch Benutzer onwiki gesperrt. Ende.\n");
Freddy's avatar
Freddy committed
18 19 20 21 22 23
		}
		echo "\n\n";
	}

	public function CSESC ($Account, $Job, $pUseHTTPS = true) {
		$this->initcurl($Account, $Job, $pUseHTTPS = true);
24
		$this->editCheck($Job);
Freddy's avatar
Freddy committed
25 26 27 28 29 30 31
		echo "---CSESC---\nDurchlauf: " . date('l jS F Y H:i:s') . "\n---\n";
		$page = "Portal:Eurovision_Song_Contest/Neue_Artikel";
		$catscanlink = "https://petscan.wmflabs.org/?language=de&project=wikipedia&depth=10&categories=Eurovision%20Song%20Contest&combination=subset&negcats=&ns%5B0%5D=1&larger=&smaller=&minlinks=&maxlinks=&before=&after=&max_age=720&only_new=on&show_redirects=both&edits%5Bbots%5D=both&edits%5Banons%5D=both&edits%5Bflagged%5D=both&templates_yes=&templates_any=&templates_no=&outlinks_yes=&outlinks_any=&outlinks_no=&links_to_all=&links_to_any=&links_to_no=&sparql=&manual_list=&manual_list_wiki=&pagepile=&wikidata_source_sites=&subpage_filter=either&common_wiki=auto&source_combination=&wikidata_item=no&wikidata_label_language=&wikidata_prop_item_use=&wpiu=any&sitelinks_yes=&sitelinks_any=&sitelinks_no=&min_sitelink_count=&max_sitelink_count=&labels_yes=&cb_labels_yes_l=1&langs_labels_yes=&labels_any=&cb_labels_any_l=1&langs_labels_any=&labels_no=&cb_labels_no_l=1&langs_labels_no=&format=json&output_compatability=catscan&sortby=date&sortorder=ascending&regexp_filter=&min_redlink_count=1&doit=Do%20it%21&interface_language=en&active_tab=tab_pageprops";
		echo "Hole Daten\n";
		$data = $this->getData($catscanlink);
		$artdata = $data['*'][0]['a']['*'];
		$string = $this->makeString($artdata);
32
		echo $string;
Freddy's avatar
Freddy committed
33 34
		$this->updatePage($string, $page);
		echo "\nDone!";
Freddy's avatar
Freddy committed
35
	}
Freddy's avatar
Freddy committed
36

Freddy's avatar
Freddy committed
37
	private function makeString($data) {
Freddy's avatar
Freddy committed
38 39
		$string = "[{{fullurl:toollabs:catscan2/catscan2.php|project=wikipedia&language=de&categories=Eurovision%20Song%20Contest&depth=10&only_new=1&max_age=720&interface_language=de&doit=1#results}} 30-Tage-Catscan]\n\n";
		$string .= "Es wurden " . count($data) . " Artikel in den letzten 30 Tagen neu angelegt.\n\n";
40
		$datasort = array();
Freddy's avatar
Freddy committed
41
		for($i = 0; count($data) > $i; $i++) {
42 43 44 45 46
			$datasort[] = $data[$i]['title'];
		}
		sort($datasort);
                for($i = 0; count($data) > $i; $i++) {
			$string .= "[[" . str_replace("_", " ", $datasort[$i]) . "]]" . " • ";
Freddy's avatar
Freddy committed
47 48 49
		}
		$string = substr($string, 0, -4);
		return $string;
Freddy's avatar
Freddy committed
50
	}
Freddy's avatar
Freddy committed
51

Freddy's avatar
Freddy committed
52
	private function updatePage($data, $page) {
Freddy's avatar
Freddy committed
53
		$this->editPage($page, $data, "Bot: Aktualisiere Liste");
Freddy's avatar
Freddy committed
54 55 56 57 58 59
	}

	private function getData($catscanlink) {
		$result = file_get_contents($catscanlink);
		$result = json_decode($result, true);
		return $result;
Freddy's avatar
Freddy committed
60 61
	 }
}
Freddy's avatar
Freddy committed
62
$Bot = new CSESC ('LarusBot@dewiki', 'CSESC'); // Aufrufen der definierten Passwortdaten in Password.php
Freddy's avatar
Freddy committed
63
?>