mirror of
https://gitlab.com/chicken-riders/RcGcDb.git
synced 2025-02-23 00:54:09 +00:00
Buggy as hell non crashy version
This commit is contained in:
parent
d7b93d55bf
commit
c04982f78d
|
@ -11,7 +11,7 @@ RcGcDb is a backend for handling webhooks to which recent changes of MediaWiki w
|
||||||
#### Installation
|
#### Installation
|
||||||
```
|
```
|
||||||
$ git clone git@gitlab.com:chicken-riders/rcgcdb.git #clone repo
|
$ git clone git@gitlab.com:chicken-riders/rcgcdb.git #clone repo
|
||||||
$ cd RcGcDw
|
$ cd RcGcDb
|
||||||
$ python3 -m venv . #(optional, if you want to contain everything (you should!))
|
$ python3 -m venv . #(optional, if you want to contain everything (you should!))
|
||||||
$ source bin/activate #(optional, see above)
|
$ source bin/activate #(optional, see above)
|
||||||
$ pip3 install -r requirements.txt #install requirements (lxml may require additional distro packages, more on that here https://lxml.de/build.html)
|
$ pip3 install -r requirements.txt #install requirements (lxml may require additional distro packages, more on that here https://lxml.de/build.html)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
},
|
},
|
||||||
"max_requests_per_minute": 30,
|
"max_requests_per_minute": 30,
|
||||||
"minimal_cooldown_per_wiki_in_sec": 60,
|
"minimal_cooldown_per_wiki_in_sec": 60,
|
||||||
|
"database_path": "rcgcdb.db",
|
||||||
"monitoring_webhook": "111111111111111111/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
"monitoring_webhook": "111111111111111111/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
|
||||||
"logging": {
|
"logging": {
|
||||||
"version": 1,
|
"version": 1,
|
||||||
|
|
|
@ -112,9 +112,9 @@ def global_exception_handler(loop, context):
|
||||||
"""Global exception handler for asyncio, lets us know when something crashes"""
|
"""Global exception handler for asyncio, lets us know when something crashes"""
|
||||||
msg = context.get("exception", context["message"])
|
msg = context.get("exception", context["message"])
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
requests.post("https://discord.com/api/webhooks/" + settings["monitoring_webhook"],
|
#requests.post("https://discord.com/api/webhooks/" + settings["monitoring_webhook"],
|
||||||
data=DiscordMessage("embed", "exception", None, content=
|
# data=DiscordMessage("embed", "exception", None, content=
|
||||||
"[RcGcDb] Exception detected, function might have shut down! Exception: {}".format(msg), wiki=None))
|
# "[RcGcDb] Exception detected, function might have shut down! Exception: {}".format(msg), wiki=None))
|
||||||
|
|
||||||
|
|
||||||
async def main_loop():
|
async def main_loop():
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
from src.config import settings
|
||||||
|
|
||||||
db_connection = sqlite3.connect('rcgcdb.db')
|
db_connection = sqlite3.connect(settings.get("database_path", 'rcgcdb.db'))
|
||||||
db_cursor = db_connection.cursor()
|
db_cursor = db_connection.cursor()
|
||||||
|
|
10
src/wiki.py
10
src/wiki.py
|
@ -21,12 +21,8 @@ class Wiki:
|
||||||
fail_times: int = 0 # corresponding to amount of times connection with wiki failed for client reasons (400-499)
|
fail_times: int = 0 # corresponding to amount of times connection with wiki failed for client reasons (400-499)
|
||||||
session: aiohttp.ClientSession = None
|
session: aiohttp.ClientSession = None
|
||||||
|
|
||||||
async def create_session(self):
|
|
||||||
self.session = aiohttp.ClientSession(headers=settings["header"], timeout=aiohttp.ClientTimeout(5.0))
|
|
||||||
|
|
||||||
async def fetch_wiki(self, extended, script_path) -> aiohttp.ClientResponse:
|
async def fetch_wiki(self, extended, script_path) -> aiohttp.ClientResponse:
|
||||||
if self.session is None:
|
|
||||||
await self.create_session()
|
|
||||||
url_path = script_path + "api.php"
|
url_path = script_path + "api.php"
|
||||||
amount = 20
|
amount = 20
|
||||||
if extended:
|
if extended:
|
||||||
|
@ -44,7 +40,8 @@ class Wiki:
|
||||||
"rcprop": "title|redirect|timestamp|ids|loginfo|parsedcomment|sizes|flags|tags|user",
|
"rcprop": "title|redirect|timestamp|ids|loginfo|parsedcomment|sizes|flags|tags|user",
|
||||||
"rclimit": amount, "rctype": "edit|new|log|external", "siprop": "namespaces|general"}
|
"rclimit": amount, "rctype": "edit|new|log|external", "siprop": "namespaces|general"}
|
||||||
try:
|
try:
|
||||||
response = await self.session.get(url_path, params=params)
|
async with aiohttp.ClientSession(headers=settings["header"], timeout=aiohttp.ClientTimeout(5.0)) as session:
|
||||||
|
response = await session.get(url_path, params=params)
|
||||||
except (aiohttp.ClientConnectionError, aiohttp.ServerTimeoutError):
|
except (aiohttp.ClientConnectionError, aiohttp.ServerTimeoutError):
|
||||||
logger.exception("A connection error occurred while requesting {}".format(url_path))
|
logger.exception("A connection error occurred while requesting {}".format(url_path))
|
||||||
raise WikiServerError
|
raise WikiServerError
|
||||||
|
@ -52,7 +49,8 @@ class Wiki:
|
||||||
|
|
||||||
async def safe_request(self, url):
|
async def safe_request(self, url):
|
||||||
try:
|
try:
|
||||||
request = await self.session.get(url, timeout=5, allow_redirects=False)
|
async with aiohttp.ClientSession(headers=settings["header"], timeout=aiohttp.ClientTimeout(5.0)) as session:
|
||||||
|
request = await session.get(url, timeout=5, allow_redirects=False)
|
||||||
request.raise_for_status()
|
request.raise_for_status()
|
||||||
except (aiohttp.ClientConnectionError, aiohttp.ServerTimeoutError):
|
except (aiohttp.ClientConnectionError, aiohttp.ServerTimeoutError):
|
||||||
logger.exception("Reached connection error for request on link {url}".format(url=url))
|
logger.exception("Reached connection error for request on link {url}".format(url=url))
|
||||||
|
|
Loading…
Reference in a new issue