Merge branch 'testing' into 'master'

1.5.2

See merge request piotrex43/RcGcDw!39
This commit is contained in:
Frisk 2019-02-15 15:10:32 +00:00
commit b1ccf5c57a
6 changed files with 77 additions and 46 deletions

12
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,12 @@
image: python:3.6-alpine
test:
type: test
script:
- apk add libxml2-dev libxslt-dev libxml2 gcc musl-dev linux-headers
- pip3.6 install -r requirements.txt
- sed -i -e "s/https:\/\/discordapp.com\/api\/webhooks\/111111111111111111\/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/$DISCORD/g" settings.json.example
- mv settings.json.example settings.json
- python3.6 rcgcdw.py --test
only:
- testing

Binary file not shown.

View file

@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: RcGcDw\n" "Project-Id-Version: RcGcDw\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2019-01-26 19:51+0100\n" "POT-Creation-Date: 2019-01-26 19:51+0100\n"
"PO-Revision-Date: 2019-01-26 19:56+0100\n" "PO-Revision-Date: 2019-02-12 13:20+0100\n"
"Last-Translator: Frisk <piotrex43@protonmail.ch>\n" "Last-Translator: Frisk <piotrex43@protonmail.ch>\n"
"Language-Team: \n" "Language-Team: \n"
"Language: pl\n" "Language: pl\n"

View file

@ -26,6 +26,12 @@ from collections import defaultdict, Counter
from urllib.parse import quote_plus from urllib.parse import quote_plus
from html.parser import HTMLParser from html.parser import HTMLParser
if __name__ != "__main__":
logging.critical("The file is being executed as a module. Please execute the script using the console.")
sys.exit(1)
TESTING = True if "--test" in sys.argv else False
try: try:
with open("settings.json") as sfile: with open("settings.json") as sfile:
settings = json.load(sfile) settings = json.load(sfile)
@ -37,11 +43,16 @@ except FileNotFoundError:
logged_in = False logged_in = False
logging.basicConfig(level=settings["verbose_level"]) logging.basicConfig(level=settings["verbose_level"])
if settings["limitrefetch"] != -1 and os.path.exists("lastchange.txt") == False: if settings["limitrefetch"] != -1 and os.path.exists("lastchange.txt") is False:
with open("lastchange.txt", 'w') as sfile: with open("lastchange.txt", 'w') as sfile:
sfile.write("99999999999") sfile.write("99999999999")
logging.debug("Current settings: {settings}".format(settings=settings)) logging.debug("Current settings: {settings}".format(settings=settings))
try:
lang = gettext.translation('rcgcdw', localedir='locale', languages=[settings["lang"]]) lang = gettext.translation('rcgcdw', localedir='locale', languages=[settings["lang"]])
except FileNotFoundError:
logging.critical("No language files have been found. Make sure locale folder is located in the directory.")
sys.exit(1)
lang.install() lang.install()
ngettext = lang.ngettext ngettext = lang.ngettext
@ -82,8 +93,7 @@ LinkParser = LinkParser()
def send(message, name, avatar): def send(message, name, avatar):
dictionary_creator = {} dictionary_creator = {"content": message}
dictionary_creator["content"] = message
if name: if name:
dictionary_creator["username"] = name dictionary_creator["username"] = name
if avatar: if avatar:
@ -184,7 +194,7 @@ def webhook_formatter(action, STATIC, **params):
if editsize < -6032: if editsize < -6032:
colornumber = 16711680 colornumber = 16711680
else: else:
colornumber = 9175040 + (math.floor((editsize * -1) / (52))) * 65536 colornumber = 9175040 + (math.floor((editsize * -1) / 52)) * 65536
elif editsize == 0: elif editsize == 0:
colornumber = 8750469 colornumber = 8750469
link = "https://{wiki}.gamepedia.com/index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format( link = "https://{wiki}.gamepedia.com/index.php?title={article}&curid={pageid}&diff={diff}&oldid={oldrev}".format(
@ -199,7 +209,6 @@ def webhook_formatter(action, STATIC, **params):
urls = safe_read(recent_changes.safe_request( urls = safe_read(recent_changes.safe_request(
"https://{wiki}.gamepedia.com/api.php?action=query&format=json&prop=imageinfo&list=&meta=&titles={filename}&iiprop=timestamp%7Curl&iilimit=2".format( "https://{wiki}.gamepedia.com/api.php?action=query&format=json&prop=imageinfo&list=&meta=&titles={filename}&iiprop=timestamp%7Curl&iilimit=2".format(
wiki=settings["wiki"], filename=params["title"])), "query", "pages") wiki=settings["wiki"], filename=params["title"])), "query", "pages")
undolink = ""
link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"], link = "https://{wiki}.gamepedia.com/{article}".format(wiki=settings["wiki"],
article=params["title"].replace(" ", "_")) article=params["title"].replace(" ", "_"))
additional_info_retrieved = False additional_info_retrieved = False
@ -266,7 +275,7 @@ def webhook_formatter(action, STATIC, **params):
article=params["target"].replace(" ", "_")) article=params["target"].replace(" ", "_"))
params["desc"] = "{supress}. {desc}".format(desc=params["desc"], params["desc"] = "{supress}. {desc}".format(desc=params["desc"],
supress=_("No redirect has been made") if params[ supress=_("No redirect has been made") if params[
"supress"] == True else _( "supress"] is True else _(
"A redirect has been made")) "A redirect has been made"))
embed["title"] = _("Moved {redirect}{article} to {target}").format(redirect="" if STATIC["redirect"] else "", article=params["title"], target=params["target"]) embed["title"] = _("Moved {redirect}{article} to {target}").format(redirect="" if STATIC["redirect"] else "", article=params["title"], target=params["target"])
elif action == "move/move_redir": elif action == "move/move_redir":
@ -565,7 +574,7 @@ def first_pass(
STATIC_VARS = {"timestamp": change["timestamp"], "tags": change["tags"], "redirect": (True if "redirect" in change else False), "ipaction": (True if "anon" in change else False), "changed_categories": changed_categories} STATIC_VARS = {"timestamp": change["timestamp"], "tags": change["tags"], "redirect": (True if "redirect" in change else False), "ipaction": (True if "anon" in change else False), "changed_categories": changed_categories}
if not parsedcomment: if not parsedcomment:
parsedcomment = _("No description provided") parsedcomment = _("No description provided")
parsedcomment = re.sub(r"(`|_|\*|~|<|>|{|})", "\\\\\\1", parsedcomment, 0) parsedcomment = re.sub(r"(`|_|\*|~|<|>|{|}|\|\|)", "\\\\\\1", parsedcomment, 0)
if change["type"] == "edit" and "edit" not in settings["ignored"]: if change["type"] == "edit" and "edit" not in settings["ignored"]:
logging.debug("List of categories in first_pass: {}".format(changed_categories)) logging.debug("List of categories in first_pass: {}".format(changed_categories))
if "userhidden" in change: if "userhidden" in change:
@ -875,7 +884,8 @@ class Recent_Changes_Class(object):
else: else:
file_id = 999999999 # such value won't cause trouble, and it will make sure no refetch happen file_id = 999999999 # such value won't cause trouble, and it will make sure no refetch happen
def handle_mw_errors(self, request): @staticmethod
def handle_mw_errors(request):
if "errors" in request: if "errors" in request:
logging.error(request["errors"]) logging.error(request["errors"])
raise MWError raise MWError
@ -1128,7 +1138,7 @@ time.sleep(1.0)
recent_changes.fetch(amount=settings["limitrefetch"] if settings["limitrefetch"] != -1 else settings["limit"]) recent_changes.fetch(amount=settings["limitrefetch"] if settings["limitrefetch"] != -1 else settings["limit"])
schedule.every(settings["cooldown"]).seconds.do(recent_changes.fetch) schedule.every(settings["cooldown"]).seconds.do(recent_changes.fetch)
if 1 == 2: if 1 == 2: # additional translation strings in unreachable code
print(_("director"), _("bot"), _("editor"), _("directors"), _("sysop"), _("bureaucrat"), _("reviewer"), print(_("director"), _("bot"), _("editor"), _("directors"), _("sysop"), _("bureaucrat"), _("reviewer"),
_("autoreview"), _("autopatrol"), _("wiki_guardian")) _("autoreview"), _("autopatrol"), _("wiki_guardian"))
@ -1144,6 +1154,15 @@ if settings["overview"]:
logging.error("Invalid time format! Currentely: {}. Note: It needs to be in HH:MM format.".format(settings["overview_time"])) logging.error("Invalid time format! Currentely: {}. Note: It needs to be in HH:MM format.".format(settings["overview_time"]))
schedule.every().day.at("00:00").do(recent_changes.clear_cache) schedule.every().day.at("00:00").do(recent_changes.clear_cache)
if TESTING:
logging.debug("DEBUGGING")
recent_changes.recent_id -= 5
recent_changes.file_id -= 5
recent_changes.ids = [1]
recent_changes.fetch(amount=5)
day_overview()
sys.exit(0)
while 1: while 1:
time.sleep(1.0) time.sleep(1.0)
schedule.run_pending() schedule.run_pending()

View file

@ -3,7 +3,7 @@
"wiki": "minecraft", "wiki": "minecraft",
"lang": "en", "lang": "en",
"header": { "header": {
"user-agent": "FrisksRcGcDw/1.5.1.2" "user-agent": "FrisksRcGcDw/1.5.2"
}, },
"limit": 11, "limit": 11,
"webhookURL": "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "webhookURL": "https://discordapp.com/api/webhooks/111111111111111111/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@ -36,15 +36,15 @@
"color":"THIS COLOR DEPENDS ON EDIT SIZE, PLEASE DON'T CHANGE" "color":"THIS COLOR DEPENDS ON EDIT SIZE, PLEASE DON'T CHANGE"
}, },
"edit":{ "edit":{
"icon":"https://d1u5p3l4wpay3k.cloudfront.net/minecraft_pl_gamepedia/d/df/Ksi%C4%85%C5%BCka_z_pi%C3%B3rem.png?version=d2b085f15fb5713091ed06f92f81c360", "icon":"",
"color":"THIS COLOR DEPENDS ON EDIT SIZE, PLEASE DON'T CHANGE" "color":"THIS COLOR DEPENDS ON EDIT SIZE, PLEASE DON'T CHANGE"
}, },
"upload/overwrite":{ "upload/overwrite":{
"icon":"", "icon":"https://i.imgur.com/egJpa81.png",
"color":12390624 "color":12390624
}, },
"upload/upload":{ "upload/upload":{
"icon":"", "icon":"https://i.imgur.com/egJpa81.png",
"color":null "color":null
}, },
"delete/delete":{ "delete/delete":{
@ -56,27 +56,27 @@
"color":1 "color":1
}, },
"delete/restore":{ "delete/restore":{
"icon":"", "icon":"https://i.imgur.com/9MnROIU.png",
"color":null "color":null
}, },
"delete/revision":{ "delete/revision":{
"icon":"", "icon":"https://i.imgur.com/1gps6EZ.png",
"color":null "color":null
}, },
"delete/event":{ "delete/event":{
"icon":"", "icon":"https://i.imgur.com/1gps6EZ.png",
"color":null "color":null
}, },
"merge/merge":{ "merge/merge":{
"icon":"", "icon":"https://i.imgur.com/uQMK9XK.png",
"color":null "color":null
}, },
"move/move":{ "move/move":{
"icon":"https://i.imgur.com/ZX02KBf.png", "icon":"https://i.imgur.com/eXz9dog.png",
"color":null "color":null
}, },
"move/move_redir":{ "move/move_redir":{
"icon":"https://i.imgur.com/ZX02KBf.png", "icon":"https://i.imgur.com/UtC3YX2.png",
"color":null "color":null
}, },
"block/block":{ "block/block":{
@ -84,7 +84,7 @@
"color":1 "color":1
}, },
"block/unblock":{ "block/unblock":{
"icon":"https://i.imgur.com/g7KgZHf.png", "icon":"https://i.imgur.com/bvtBJ8o.png",
"color":1 "color":1
}, },
"block/reblock":{ "block/reblock":{
@ -92,19 +92,19 @@
"color":1 "color":1
}, },
"protect/protect":{ "protect/protect":{
"icon":"https://i.imgur.com/Lfk0wuw.png", "icon":"https://i.imgur.com/bzPt89Z.png",
"color":null "color":null
}, },
"protect/modify":{ "protect/modify":{
"icon":"https://i.imgur.com/Lfk0wuw.png", "icon":"https://i.imgur.com/bzPt89Z.png",
"color":null "color":null
}, },
"protect/move_prot":{ "protect/move_prot":{
"icon":"https://i.imgur.com/ZX02KBf.png", "icon":"https://i.imgur.com/bzPt89Z.png",
"color":null "color":null
}, },
"protect/unprotect":{ "protect/unprotect":{
"icon":"https://i.imgur.com/Lfk0wuw.png", "icon":"https://i.imgur.com/2wN3Qcq.png",
"color":null "color":null
}, },
"import/upload":{ "import/upload":{
@ -112,7 +112,7 @@
"color":null "color":null
}, },
"import/interwiki":{ "import/interwiki":{
"icon":"", "icon":"https://i.imgur.com/sFkhghb.png",
"color":null "color":null
}, },
"rights/rights":{ "rights/rights":{
@ -120,35 +120,35 @@
"color":null "color":null
}, },
"abusefilter/abusefilter":{ "abusefilter/abusefilter":{
"icon":"", "icon":"https://i.imgur.com/Sn2NzRJ.png",
"color":null "color":null
}, },
"abusefilter/modify":{ "abusefilter/modify":{
"icon":"", "icon":"https://i.imgur.com/Sn2NzRJ.png",
"color":null "color":null
}, },
"abusefilter/create": { "abusefilter/create": {
"icon":"", "icon":"https://i.imgur.com/Sn2NzRJ.png",
"color":null "color":null
}, },
"interwiki/iw_add":{ "interwiki/iw_add":{
"icon":"", "icon":"https://i.imgur.com/sFkhghb.png",
"color":null "color":null
}, },
"interwiki/iw_edit":{ "interwiki/iw_edit":{
"icon":"", "icon":"https://i.imgur.com/sFkhghb.png",
"color":null "color":null
}, },
"interwiki/iw_delete":{ "interwiki/iw_delete":{
"icon":"", "icon":"https://i.imgur.com/sFkhghb.png",
"color":null "color":null
}, },
"curseprofile/comment-created":{ "curseprofile/comment-created":{
"icon":"", "icon":"https://i.imgur.com/Lvy5E32.png",
"color":null "color":null
}, },
"curseprofile/comment-edited":{ "curseprofile/comment-edited":{
"icon":"", "icon":"https://i.imgur.com/Lvy5E32.png",
"color":null "color":null
}, },
"curseprofile/comment-deleted":{ "curseprofile/comment-deleted":{
@ -156,7 +156,7 @@
"color":null "color":null
}, },
"curseprofile/comment-replied":{ "curseprofile/comment-replied":{
"icon":"", "icon":"https://i.imgur.com/hkyYsI1.png",
"color":null "color":null
}, },
"curseprofile/profile-edited":{ "curseprofile/profile-edited":{
@ -200,7 +200,7 @@
"color":null "color":null
}, },
"suppressed":{ "suppressed":{
"icon": "", "icon": "https://i.imgur.com/1gps6EZ.png",
"color": 8092539 "color": 8092539
} }
} }

View file

@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name='RcGcDw', name='RcGcDw',
version='1.5.1.2', version='1.5.2',
packages=['venv.lib.python3.7.site-packages.bs4', 'venv.lib.python3.7.site-packages.bs4.tests', packages=['venv.lib.python3.7.site-packages.bs4', 'venv.lib.python3.7.site-packages.bs4.tests',
'venv.lib.python3.7.site-packages.bs4.builder', 'venv.lib.python3.7.site-packages.idna', 'venv.lib.python3.7.site-packages.bs4.builder', 'venv.lib.python3.7.site-packages.idna',
'venv.lib.python3.7.site-packages.lxml', 'venv.lib.python3.7.site-packages.lxml.html', 'venv.lib.python3.7.site-packages.lxml', 'venv.lib.python3.7.site-packages.lxml.html',