CSGroenland.php 2.84 KB
Newer Older
Freddy's avatar
Freddy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/php
<?php
include 'Core/BotCore.php';
/** CSGroenland.php
* Aktualisiert die Neuen Artikel im Portal Grönland
* @Author Freddy2001 <freddy2001@wikipedia.de>
* @Version 0.1
* @Status Alpha
*/

class CSGroenland extends Core {
	public function editCheck ($Job) {
		$allowed = $this->readPage("User:LarusBot/active/" . $Job);
		if($allowed == "true") {
			echo "Job nicht gesperrt";
		} else {
			die("Job durch Benutzer onwiki gesperrt. Ende.\n");
		}
		echo "\n\n";
	}

	public function CSGroenland ($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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
		echo "---CSGroenland---\nDurchlauf: " . date('l jS F Y H:i:s') . "\n---\n";
		$page = "Portal:Grönland/Neue_Artikel";
		$catscanlink = "https://petscan.wmflabs.org/?language=de&project=wikipedia&depth=10&categories=Gr%C3%B6nland&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=title&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);
		echo $string;
		$this->updatePage($string, $page);
		echo "\nDone!";
	}

	private function makeString($data) {
		$string = "[{{fullurl:toollabs:catscan2/catscan2.php|project=wikipedia&language=de&categories=Gr%C3%B6nland&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";
		for($i = 0; count($data) > $i; $i++) {
			$string .= "[[" . str_replace("_", " ", $data[$i]['title']) . "]]" . " • ";
		}
		$string = substr($string, 0, -4);
		return $string;
	}

	private function updatePage($data, $page) {
		$this->editPage($page, $data, "Bot: Aktualisiere Liste");
	}

	private function getData($catscanlink) {
		$result = file_get_contents($catscanlink);
		$result = json_decode($result, true);
		return $result;
	}
}
$Bot = new CSGroenland ('LarusBot@dewiki', 'CSGroenland'); // Aufrufen der definierten Passwortdaten in Password.php
?>