diff --git a/.gitignore b/.gitignore index e38da20..19f395d 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ settings.json +pygettext.py diff --git a/locale/pl/LC_MESSAGES/rcgcdw.mo b/locale/pl/LC_MESSAGES/rcgcdw.mo new file mode 100644 index 0000000..9cd2b8a Binary files /dev/null and b/locale/pl/LC_MESSAGES/rcgcdw.mo differ diff --git a/locale/pl/LC_MESSAGES/rcgcdw.po b/locale/pl/LC_MESSAGES/rcgcdw.po new file mode 100644 index 0000000..a3bb240 --- /dev/null +++ b/locale/pl/LC_MESSAGES/rcgcdw.po @@ -0,0 +1,250 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: RcGcDw\n" +"POT-Creation-Date: 2018-06-16 13:32+0200\n" +"PO-Revision-Date: 2018-06-16 13:58+0200\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" +"X-Generator: Poedit 2.0.8\n" +"Last-Translator: Frisk \n" +"Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" +"Language: pl\n" + +#: rcgcdw.py:88 +msgid "New file version {name}" +msgstr "Nowa wersja pliku (name)" + +#: rcgcdw.py:89 +msgid "([preview]({link}) | [undo]({undolink}))" +msgstr "([podgląd]({link}) | [wycofaj]({undolink}))" + +#: rcgcdw.py:89 rcgcdw.py:105 +msgid "Options" +msgstr "Opcje" + +#: rcgcdw.py:91 +msgid "New file {name}" +msgstr "Nowy plik {name}" + +#: rcgcdw.py:105 +msgid "([preview]({link}))" +msgstr "([podgląd]({link})" + +#: rcgcdw.py:106 +msgid "" +"{desc}\n" +"License: {license}" +msgstr "" +"{desc}\n" +"Licencja: {license}" + +#: rcgcdw.py:111 +msgid "Deleted {article}" +msgstr "Usunięto {article}" + +#: rcgcdw.py:116 +msgid "Deleted redirect ({article}) to make space for moved page" +msgstr "Usunięto przekierowanie ({article}) aby utworzyć miejsce dla przenoszonej strony" + +#: rcgcdw.py:120 +msgid "A redirect has been made" +msgstr "Zostało utworzone przekierowanie" + +#: rcgcdw.py:120 +msgid "No redirect has been made" +msgstr "Nie utworzono przekierowania" + +#: rcgcdw.py:121 +msgid "Moved \"{article}\" to \"{target}\"" +msgstr "Przeniesiono \"{article}\" do \"{target}\"" + +#: rcgcdw.py:124 +msgid "Moved {article} to redirect page ({title})" +msgstr "Przeniesiono {article} do przekierowania ({title})" + +#: rcgcdw.py:128 +msgid "Moved protection settings from {article} to {title}" +msgstr "Przeniesiono ustawienia zabezpieczeń z {article} do {title}" + +#: rcgcdw.py:133 +msgid "infinity and beyond" +msgstr "wieczność" + +#: rcgcdw.py:134 +msgid "Blocked {blocked_user} for {time}" +msgstr "Zablokowano {blocked_user} na {time}" + +#: rcgcdw.py:140 +msgid "Reapplied the block on {blocked_user}" +msgstr "Ponownie nałożono blokadę na {blocked_user}" + +#: rcgcdw.py:146 +msgid "Removed the block on {blocked_user}" +msgstr "Usunięto blokadę na {blocked_user}" + +#: rcgcdw.py:151 +msgid "Left a comment on {target}'s profile" +msgstr "Pozostawiono komentarz na profilu użytkownika {target}" + +#: rcgcdw.py:154 +msgid "Replied to a comment on {target}'s profile" +msgstr "Odpowiedziano na komentarz na profilu użytkownika {target}" + +#: rcgcdw.py:157 +msgid "Edited a comment on {target}'s profile" +msgstr "Edytowano komentarz na profilu użytkownika {target}" + +#: rcgcdw.py:161 +msgid "Location" +msgstr "Lokacja" + +#: rcgcdw.py:163 +msgid "About me" +msgstr "O mnie" + +#: rcgcdw.py:183 +msgid "Unknown" +msgstr "Nieznana" + +#: rcgcdw.py:184 +msgid "Edited {target}'s profile" +msgstr "Edytowano profil użytkownika {target}" + +#: rcgcdw.py:185 +msgid "{field} field changed to: {desc}" +msgstr "pole {field} zostało zmienione na: {desc}" + +#: rcgcdw.py:188 +msgid "Removed a comment on {target}'s profile" +msgstr "Usunięto komentarz na profilu użytkownika {target}" + +#: rcgcdw.py:191 +msgid "Changed {target}'s user groups" +msgstr "Zmieniono grupy użytkownika {target}" + +#: rcgcdw.py:195 rcgcdw.py:197 +msgid "none" +msgstr "brak" + +#: rcgcdw.py:198 +msgid "Groups changed from {old_groups} to {new_groups} with reason given: {desc}" +msgstr "Grupy zmienione z {old_groups} do {new_groups} z powodu: {desc}" + +#: rcgcdw.py:201 +msgid "Protected the page {target}" +msgstr "Zabezpieczono stronę: {target}" + +#: rcgcdw.py:206 +msgid "Modified protection settings for {article}" +msgstr "Zmodyfikowano ustawienia zabezpieczeń dla {article}" + +#: rcgcdw.py:211 +msgid "Removed protection for {article}" +msgstr "Usunięto zabezpieczenia dla {article}" + +#: rcgcdw.py:215 +msgid "Removed revision(s) from public view for {article}" +msgstr "Usunięto edycje z widoku publicznego dla {article}" + +#: rcgcdw.py:218 +msgid "Imported {article} with {count} revision(s)" +msgstr "Zaimportowano {article} z {count} wersjami" + +#: rcgcdw.py:221 +msgid "Restored {article}" +msgstr "Przywrócono {article)" + +#: rcgcdw.py:224 +msgid "Removed events" +msgstr "Usunięto wydarzenia" + +#: rcgcdw.py:227 +msgid "Imported interwiki" +msgstr "Zaimportowano interwiki" + +#: rcgcdw.py:230 +msgid "Edited abuse filter number {number}" +msgstr "Edytowano filtr nadużyć numer (number)" + +#: rcgcdw.py:233 +msgid "Merged revision histories for {article}" +msgstr "Połączono historie artykułu dla {article}" + +#: rcgcdw.py:236 +msgid "Added interwiki entry" +msgstr "Dodano intwrwiki" + +#: rcgcdw.py:237 rcgcdw.py:241 +msgid "Prefix: {prefix}, website: {website} | {desc}" +msgstr "Prefix: {prefix}, strona: {website} | desc" + +#: rcgcdw.py:240 +msgid "Edited interwiki entry" +msgstr "Edytowano interwiki" + +#: rcgcdw.py:244 +msgid "Deleted interwiki entry" +msgstr "Usunięto interwiki" + +#: rcgcdw.py:245 +msgid "Prefix: {prefix} | {desc}" +msgstr "Prefix: {prefix} | {desc}" + +#: rcgcdw.py:248 +msgid "Changed content model of {article}" +msgstr "Zmieniono model zawartości {article}" + +#: rcgcdw.py:249 +msgid "Model changed from {old} to {new}: {reason}" +msgstr "Model został zmieniony z {old} na {new}: reason" + +#: rcgcdw.py:252 +msgid "Edited the sprite for {article}" +msgstr "Edytowano sprite dla {article}" + +#: rcgcdw.py:255 +msgid "Created the sprite sheet for {article}" +msgstr "Utworzono sprite sheet dla {article}" + +#: rcgcdw.py:258 +msgid "Edited the slice for {article}" +msgstr "Edytowano część sprite dla {article}" + +#: rcgcdw.py:261 +msgid "Created a tag \"{tag}\"" +msgstr "Utworzono tag \"{tag}\"" + +#: rcgcdw.py:264 +msgid "Deleted a tag \"{tag}\"" +msgstr "Usunięto tag \"{tag}\"" + +#: rcgcdw.py:283 +msgid "No description provided" +msgstr "Nie podano opisu zmian" + +#: rcgcdw.py:364 +msgid "Unable to process the event" +msgstr "Nie udało się odczytać wydarzenia" + +#: rcgcdw.py:364 +msgid "error" +msgstr "błąd" + +#: rcgcdw.py:445 +msgid "Connection status" +msgstr "Problem z połączeniem" + +#: rcgcdw.py:445 +msgid "Minecraft Wiki seems to be down or unreachable." +msgstr "Minecraft Wiki nie działa lub jest nieosiągalna." + +#: rcgcdw.py:445 +msgid "https://i.imgur.com/2jWQEt1.png" +msgstr "https://i.imgur.com/2jWQEt1.png" diff --git a/rcgcdw.pot b/rcgcdw.pot new file mode 100644 index 0000000..2d1759b --- /dev/null +++ b/rcgcdw.pot @@ -0,0 +1,247 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2018-06-16 13:32+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" + + +#: rcgcdw.py:88 +msgid "New file version {name}" +msgstr "" + +#: rcgcdw.py:89 +msgid "([preview]({link}) | [undo]({undolink}))" +msgstr "" + +#: rcgcdw.py:89 rcgcdw.py:105 +msgid "Options" +msgstr "" + +#: rcgcdw.py:91 +msgid "New file {name}" +msgstr "" + +#: rcgcdw.py:105 +msgid "([preview]({link}))" +msgstr "" + +#: rcgcdw.py:106 +msgid "" +"{desc}\n" +"License: {license}" +msgstr "" + +#: rcgcdw.py:111 +msgid "Deleted {article}" +msgstr "" + +#: rcgcdw.py:116 +msgid "Deleted redirect ({article}) to make space for moved page" +msgstr "" + +#: rcgcdw.py:120 +msgid "A redirect has been made" +msgstr "" + +#: rcgcdw.py:120 +msgid "No redirect has been made" +msgstr "" + +#: rcgcdw.py:121 +msgid "Moved \"{article}\" to \"{target}\"" +msgstr "" + +#: rcgcdw.py:124 +msgid "Moved {article} to redirect page ({title})" +msgstr "" + +#: rcgcdw.py:128 +msgid "Moved protection settings from {article} to {title}" +msgstr "" + +#: rcgcdw.py:133 +msgid "infinity and beyond" +msgstr "" + +#: rcgcdw.py:134 +msgid "Blocked {blocked_user} for {time}" +msgstr "" + +#: rcgcdw.py:140 +msgid "Reapplied the block on {blocked_user}" +msgstr "" + +#: rcgcdw.py:146 +msgid "Removed the block on {blocked_user}" +msgstr "" + +#: rcgcdw.py:151 +msgid "Left a comment on {target}'s profile" +msgstr "" + +#: rcgcdw.py:154 +msgid "Replied to a comment on {target}'s profile" +msgstr "" + +#: rcgcdw.py:157 +msgid "Edited a comment on {target}'s profile" +msgstr "" + +#: rcgcdw.py:161 +msgid "Location" +msgstr "" + +#: rcgcdw.py:163 +msgid "About me" +msgstr "" + +#: rcgcdw.py:183 +msgid "Unknown" +msgstr "" + +#: rcgcdw.py:184 +msgid "Edited {target}'s profile" +msgstr "" + +#: rcgcdw.py:185 +msgid "{field} field changed to: {desc}" +msgstr "" + +#: rcgcdw.py:188 +msgid "Removed a comment on {target}'s profile" +msgstr "" + +#: rcgcdw.py:191 +msgid "Changed {target}'s user groups" +msgstr "" + +#: rcgcdw.py:195 rcgcdw.py:197 +msgid "none" +msgstr "" + +#: rcgcdw.py:198 +msgid "Groups changed from {old_groups} to {new_groups} with reason given: {desc}" +msgstr "" + +#: rcgcdw.py:201 +msgid "Protected the page {target}" +msgstr "" + +#: rcgcdw.py:206 +msgid "Modified protection settings for {article}" +msgstr "" + +#: rcgcdw.py:211 +msgid "Removed protection for {article}" +msgstr "" + +#: rcgcdw.py:215 +msgid "Removed revision(s) from public view for {article}" +msgstr "" + +#: rcgcdw.py:218 +msgid "Imported {article} with {count} revision(s)" +msgstr "" + +#: rcgcdw.py:221 +msgid "Restored {article}" +msgstr "" + +#: rcgcdw.py:224 +msgid "Removed events" +msgstr "" + +#: rcgcdw.py:227 +msgid "Imported interwiki" +msgstr "" + +#: rcgcdw.py:230 +msgid "Edited abuse filter number {number}" +msgstr "" + +#: rcgcdw.py:233 +msgid "Merged revision histories for {article}" +msgstr "" + +#: rcgcdw.py:236 +msgid "Added interwiki entry" +msgstr "" + +#: rcgcdw.py:237 rcgcdw.py:241 +msgid "Prefix: {prefix}, website: {website} | {desc}" +msgstr "" + +#: rcgcdw.py:240 +msgid "Edited interwiki entry" +msgstr "" + +#: rcgcdw.py:244 +msgid "Deleted interwiki entry" +msgstr "" + +#: rcgcdw.py:245 +msgid "Prefix: {prefix} | {desc}" +msgstr "" + +#: rcgcdw.py:248 +msgid "Changed content model of {article}" +msgstr "" + +#: rcgcdw.py:249 +msgid "Model changed from {old} to {new}: {reason}" +msgstr "" + +#: rcgcdw.py:252 +msgid "Edited the sprite for {article}" +msgstr "" + +#: rcgcdw.py:255 +msgid "Created the sprite sheet for {article}" +msgstr "" + +#: rcgcdw.py:258 +msgid "Edited the slice for {article}" +msgstr "" + +#: rcgcdw.py:261 +msgid "Created a tag \"{tag}\"" +msgstr "" + +#: rcgcdw.py:264 +msgid "Deleted a tag \"{tag}\"" +msgstr "" + +#: rcgcdw.py:283 +msgid "No description provided" +msgstr "" + +#: rcgcdw.py:364 +msgid "Unable to process the event" +msgstr "" + +#: rcgcdw.py:364 +msgid "error" +msgstr "" + +#: rcgcdw.py:445 +msgid "Connection status" +msgstr "" + +#: rcgcdw.py:445 +msgid "Minecraft Wiki seems to be down or unreachable." +msgstr "" + +#: rcgcdw.py:445 +msgid "https://i.imgur.com/2jWQEt1.png" +msgstr "" + diff --git a/rcgcdw.py b/rcgcdw.py index 1d1c58c..4b9c017 100644 --- a/rcgcdw.py +++ b/rcgcdw.py @@ -1,12 +1,14 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -import time, logging, json, requests, datetime, re +import time, logging, json, requests, datetime, re, gettext from bs4 import BeautifulSoup from collections import defaultdict logging.basicConfig(level=logging.DEBUG) #logging.warning('Watch out!') #DEBUG, INFO, WARNING, ERROR, CRITICAL +pl = gettext.translation('rcgcdw', localedir='locale', languages=['pl']) +pl.install() with open("settings.json") as sfile: settings = json.load(sfile) @@ -39,7 +41,7 @@ def webhook_formatter(action, timestamp, **params): article_encoded = params["title"].replace(" ", "_").replace(')', '\)') if re.match(r"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b", params["author"]) is not None: author_url = "https://{wiki}.gamepedia.com/Special:Contributions/{user}".format(wiki=settings["wiki"], user=params["author"]) - if params["author"] not in recent_changes.map_ips.keys(): + if params["author"] not in list(recent_changes.map_ips.keys()): contibs = safe_read(recent_changes.safe_request("https://{wiki}.gamepedia.com/api.php?action=query&format=json&list=usercontribs&uclimit=max&ucuser={user}&ucprop=".format(wiki=settings["wiki"], user=params["author"])), "query", "usercontribs") if contibs is None: logging.warning("WARNING: Something went wrong when checking amount of contributions for given IP address") @@ -77,23 +79,23 @@ def webhook_formatter(action, timestamp, **params): undolink = "" link ="https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], article=article_encoded) if urls is not None: - img_info = urls.itervalues().next()["imageinfo"] + img_info = iter(urls.values()).next()["imageinfo"] embed["image"]["url"] = img_info[0]["url"] else: return if params["overwrite"]: colornumber = 12390624 - img_timestamp = filter(lambda x: x.isdigit(), img_info[1]["timestamp"]) + img_timestamp = [x for x in img_info[1]["timestamp"] if x.isdigit()] undolink = "https://{wiki}.gamepedia.com/index.php?title={filename}&action=revert&oldimage={timestamp}%21{filenamewon}".format(wiki=settings["wiki"], filename=article_encoded, timestamp=img_timestamp, filenamewon = article_encoded[5:]) embed["title"] = _("New file version {name}").format(name=params["title"]) embed["fields"] = [{"name": _("Options"), "value": _("([preview]({link}) | [undo]({undolink}))").format(link=embed["image"]["url"], undolink=undolink)}] else: embed["title"] = _("New file {name}").format(name=params["title"]) - article_content = safe_read(recent_changes.safe_request("https://minecraft.gamepedia.com/api.php?action=query&format=json&prop=revisions&titles={article}&rvprop=content".format(article=urllib.quote_plus(params["title"]))), "query", "pages") #TODO Napewno urllib? + article_content = safe_read(recent_changes.safe_request("https://minecraft.gamepedia.com/api.php?action=query&format=json&prop=revisions&titles={article}&rvprop=content".format(article=urllib.parse.quote_plus(params["title"]))), "query", "pages") #TODO Napewno urllib? if article_content is None: logging.warning("Something went wrong when getting license for the image") return 0 - content = article_content.values()[0]['revisions'][0]['*'].lower() + content = list(article_content.values())[0]['revisions'][0]['*'].lower() if "{{license" not in content: license = "**No license!**" else: @@ -387,7 +389,7 @@ class recent_changes(object): self.ids.pop(0) def fetch(self): self.recent_id = self.fetch_changes() - def fetch_changes(self): + def fetch_changes(self, clean=False): if len(self.cache) == 0: logging.debug("cache is empty, triggering clean fetch") clean = True