Skip to content

Commit

Permalink
Merge pull request #48 from c2corg/update-black
Browse files Browse the repository at this point in the history
Update black to its last version
  • Loading branch information
cbeauchesne authored Feb 18, 2022
2 parents f2683e7 + 50080d7 commit 0b5d21d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 47 deletions.
3 changes: 2 additions & 1 deletion campbot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ def main(args):

elif args["report"]:
get_campbot(args).report(
args["<url_or_file>"], lang=args["<lang>"],
args["<url_or_file>"],
lang=args["<lang>"],
)

elif args["clean"]:
Expand Down
2 changes: 1 addition & 1 deletion campbot/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def get_fixed_tests(lang):


def get_document_tests(lang):
""" Returns a list of tests that can be run on a single document"""
"""Returns a list of tests that can be run on a single document"""

return [
HistoryTest(lang),
Expand Down
67 changes: 36 additions & 31 deletions campbot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def put(self, url, data):

class WikiBot(BaseBot):
"""
Get functions for all camptocamp.org wiki
Get functions for all camptocamp.org wiki
"""

@property
Expand Down Expand Up @@ -414,22 +414,22 @@ def get_participants(self, url):
class CampBot(object):
"""
CampBot() object is the main class. You must instanciate only one instance of it.
It contains two property :
It contains two property :
* ``wiki`` for interacting with camptocamp.org wiki
* ``forum`` for interacting with camptocamp.org forum
"""

def __init__(self, min_delay=None, proxies=None, use_demo=False):
"""
:param min_delay: in seconds, minimum delay between each request
:param proxies: key-url dictionary
:param use_demo: Boolean, True if you want to use C2C demo API
:Example:
>>> bot = CampBot(min_delay=10, proxies={"https": "https://login:[email protected]"})
:param min_delay: in seconds, minimum delay between each request
:param proxies: key-url dictionary
:param use_demo: Boolean, True if you want to use C2C demo API
:Example:
>>> bot = CampBot(min_delay=10, proxies={"https": "https://login:[email protected]"})
"""

domain = "camptocamp" if not use_demo else "demov6.camptocamp"
Expand Down Expand Up @@ -459,12 +459,12 @@ def __init__(self, min_delay=None, proxies=None, use_demo=False):

def login(self, login, password):
"""
Login to camptocamp.org, mandatory for write actions.
It also sign-in to forum.
Login to camptocamp.org, mandatory for write actions.
It also sign-in to forum.
:param login: bot login used to sign-in (not the numerical ID)
:param password: bot password
:param login: bot login used to sign-in (not the numerical ID)
:param password: bot password
"""

logging.info(f"Logging to wiki with account {login}...")
Expand Down Expand Up @@ -527,12 +527,12 @@ def clean(
self, url_or_filename, lang, ask_before_saving, thread_url, clean_bbcode=False
):
"""
Clean a set of document.
Clean a set of document.
:param url_or_filename: Camptocamp.org URL, or filename
:param lang: lang identifier
:param ask_before_saving: Boolean
:param clean_bbcode: Boolean
:param url_or_filename: Camptocamp.org URL, or filename
:param lang: lang identifier
:param ask_before_saving: Boolean
:param clean_bbcode: Boolean
"""

Expand All @@ -545,10 +545,10 @@ def clean(

def report(self, url_or_filename, lang):
"""
Make quality report on a set of document.
Make quality report on a set of document.
:param url_or_filename: Camptocamp.org URL, or filename
:param langs: comma-separated list of lang identifiers
:param url_or_filename: Camptocamp.org URL, or filename
:param langs: comma-separated list of lang identifiers
"""

documents = [d for d in self.get_documents(url_or_filename)]
Expand Down Expand Up @@ -627,7 +627,12 @@ def _process_documents(

for processor in processors:
if processor.ready_for_production:
if processor(document, [lang,]):
if processor(
document,
[
lang,
],
):
messages.append(processor.comment)
must_save = True

Expand Down Expand Up @@ -655,10 +660,10 @@ def _process_documents(

def export(self, url, filename=None):
"""
Export all document given by a camptocamp.org url
Export all document given by a camptocamp.org url
:param url: Camptocamp.org URL
:param filename: Output file name. Defaut : <document_type>.csv
:param url: Camptocamp.org URL
:param filename: Output file name. Defaut : <document_type>.csv
"""

Expand Down Expand Up @@ -702,11 +707,11 @@ def export(self, url, filename=None):

def export_contributions(self, starts=None, ends=None, filename=None):
"""
Export all document given by a camptocamp.org url
Export all document given by a camptocamp.org url
:param starts: Start date, default is now minus 24 hours
:param ends: default is now
:param filename: Output file name. Defaut : contributions.csv
:param starts: Start date, default is now minus 24 hours
:param ends: default is now
:param filename: Output file name. Defaut : contributions.csv
"""

Expand Down
20 changes: 10 additions & 10 deletions campbot/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Locale(BotObject):
def get_title(self):
"""
Get the title, with prefix if it exists.
:return: String, pretty title
"""

Expand Down Expand Up @@ -178,7 +178,7 @@ def get_locale_fields(self):
def get_length(self):
"""
Get text length
:return: Integer, number of characters
"""

Expand Down Expand Up @@ -209,7 +209,7 @@ def __init__(self, campbot, data):

def get_url(self, lang=None):
"""
:return: camptocamp.org URL.
:return: camptocamp.org URL.
"""

return "{}/{}/{}{}".format(
Expand All @@ -221,7 +221,7 @@ def get_url(self, lang=None):

def get_history_url(self, lang):
"""
:return: camptocamp.org version list URL
"""

Expand All @@ -236,8 +236,8 @@ def get_title(self, lang):
def get_locale(self, lang):
"""
:param lang: fr, en, de ...
:return: String, or None if locale does not exists in this lang
:return: String, or None if locale does not exists in this lang
"""

if "locales" not in self:
Expand All @@ -250,9 +250,9 @@ def get_locale(self, lang):
def search(self, patterns, lang):
"""
Search a pattern (regular expression)
:param lang: fr, de, en...
:return: True if pattern is found, False otherwise
"""

Expand All @@ -277,10 +277,10 @@ def _build_payload(self, message):
def save(self, message, ask_before_saving=True):
"""
Save object to camptocamp.org. Bot must be authentified.
:param message: Modification comment
:param ask_before_saving: Boolean, ask user before saing document
:return: raw request response, useless.
"""

Expand Down
13 changes: 10 additions & 3 deletions campbot/processors/cleaners.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,18 @@ def build_pattern(url_ending):
)

self.modifiers = [
Converter(build_pattern(r"(\d+)/?#?\)"), r"[[\2/\3|\1]]",),
Converter(
build_pattern(r"(\d+)/([a-z]{2})(/[\w-]*)?#?\)"), r"[[\2/\3|\1]]",
build_pattern(r"(\d+)/?#?\)"),
r"[[\2/\3|\1]]",
),
Converter(
build_pattern(r"(\d+)/([a-z]{2})(/[\w-]*)?#?\)"),
r"[[\2/\3|\1]]",
),
Converter(
build_pattern(r"(\d+)#([a-z0-9\-]+)\)"),
r"[[\2/\3#\4|\1]]",
),
Converter(build_pattern(r"(\d+)#([a-z0-9\-]+)\)"), r"[[\2/\3#\4|\1]]",),
Converter(
build_pattern(r"(\d+)/([a-z]{2})(/[\w-]*)?#([a-z0-9\-]+)\)"),
r"[[\2/\3/\4#\6|\1]]",
Expand Down
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pytest
pytest-cov
wheel
setuptools
black==19.10b0
black==22.1.0

0 comments on commit 0b5d21d

Please sign in to comment.