Moved link_formatter function to misc module

This commit is contained in:
Frisk 2019-05-20 12:41:40 +02:00
parent 5d0758f32d
commit f010832269
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C
2 changed files with 37 additions and 32 deletions

View file

@ -1,6 +1,7 @@
import json, logging, sys import json, logging, sys, re
# Create a custom logger # Create a custom logger
misc_logger = logging.getLogger("rcgcdw.misc") misc_logger = logging.getLogger("rcgcdw.misc")
data_template = {"rcid": 99999999999, data_template = {"rcid": 99999999999,
@ -44,3 +45,8 @@ def save_datafile(data):
def weighted_average(value, weight, new_value): def weighted_average(value, weight, new_value):
"""Calculates weighted average of value number with weight weight and new_value with weight 1""" """Calculates weighted average of value number with weight weight and new_value with weight 1"""
return round(((value * weight) + new_value) / (weight + 1), 2) return round(((value * weight) + new_value) / (weight + 1), 2)
def link_formatter(link):
"""Formats a link to not embed it"""
return "<"+re.sub(r"([ \)])", "\\\\\\1", link)+">"

View file

@ -20,12 +20,14 @@
# WARNING! SHITTY CODE AHEAD. ENTER ONLY IF YOU ARE SURE YOU CAN TAKE IT # WARNING! SHITTY CODE AHEAD. ENTER ONLY IF YOU ARE SURE YOU CAN TAKE IT
# You have been warned # You have been warned
import time, logging, logging.config, json, requests, datetime, re, gettext, math, random, os.path, schedule, sys, ipaddress, misc import time, logging.config, json, requests, datetime, re, gettext, math, random, os.path, schedule, sys, ipaddress, misc
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from collections import defaultdict, Counter 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
from misc import link_formatter
if __name__ != "__main__": # return if called as a module if __name__ != "__main__": # return if called as a module
logging.critical("The file is being executed as a module. Please execute the script using the console.") logging.critical("The file is being executed as a module. Please execute the script using the console.")
sys.exit(1) sys.exit(1)
@ -171,9 +173,6 @@ def send_to_discord(data):
time.sleep(2.0) time.sleep(2.0)
pass pass
def link_formatter(link):
return "<"+re.sub(r"([ \)])", "\\\\\\1", link)+">"
def compact_formatter(action, change, parsed_comment, categories): def compact_formatter(action, change, parsed_comment, categories):
if action != "suppressed": if action != "suppressed":
author_url = link_formatter("https://{wiki}.gamepedia.com/User:{user}".format(wiki=settings["wiki"], user=change["user"])) author_url = link_formatter("https://{wiki}.gamepedia.com/User:{user}".format(wiki=settings["wiki"], user=change["user"]))