def loggedin_forum(self):
     """Connect to forum before testing, disconnect after."""
     # Setup : log in forum
     forum = PhpBB(host)
     forum.login(username, password)
     print("Pytest fixture : Logging in forum")
     yield forum
     # this is where the testing happens
     # Teardown : log out forum
     forum.logout()
     print("Pytest fixture : Logging out forum")
Beispiel #2
0
CFG_FORUM = 'dctrad'

Topic = namedtuple('Topic', ['f', 't', 'desc'])
topic_list = [
    Topic(147, 15066, 'équipe_DC_Hors'),
    Topic(147, 7848, 'équipe_DC'),
    Topic(12, 14511, 'absences'),
    Topic(121, 13388, 'news_média'),
    Topic(119, 13387, "News Comics"),
]

try:
    # user = int(sys.argv[2])
    cfg = Settings(CFG_FILE)
    cfg_dict = cfg.read_section(CFG_FORUM)
    phpbb = PhpBB(cfg_dict['host'])
    # forum.setUserAgent(cfg.user_agent)
    if phpbb.login(cfg_dict['username'], cfg_dict['password']):
        print('Login')
        for top in topic_list:
            topic = f'viewtopic.php?f={top.f}&t={top.t}'
            post_list = phpbb.get_topic_posts(topic, int(
                cfg_dict['max_count']))  # noqa: E501
            n = len(post_list)
            print(f"{n} posts dans ce topic")
            print("===================")

            post_list = PostList([p for p in post_list[1:] if p.old > 365])

            print("===================")
            post_list.print_posts()
def nuke_oc(forum, fid, pid):
    mess = forum.get_post_editmode_content(fid, pid)
    new_mess = replace_message(origin)
    return mess, new_mess


if __name__ == '__main__':

    old_file = open("old.txt", "w")
    new_file = open("new.txt", "w")

    # Config
    cfg = Settings(cfg_file)
    if cfg.load(cfg_forum, Const.cfg_opts):
        phpbb = PhpBB(cfg.host)
        max = int(cfg.max_count)

        if phpbb.login(cfg.username, cfg.password):
            print('Login')

            mode = 0
            while True:
                mode = input('Que voulez-vous faire ?\n'
                             '1- Traiter un seul topic\n'
                             '2- Traiter un sous forum entier '
                             '(DC Rebirth / Marvel / etc...)\n'
                             'Réponse : 1 ou 2\n')
                if 1 <= int(mode) <= 2:
                    break
                else:
Beispiel #4
0
def nuke_oc(phpbb, f_id, p_id):
    """Get message (with his pid) and return new text."""
    origin = phpbb.get_post_editmode_content(f_id, p_id)
    new_mess = replace_message(origin)
    return origin, new_mess


if __name__ == '__main__':

    old_file = open("old.txt", "w")
    new_file = open("new.txt", "w")

    # Config
    cfg = Settings(CFG_FILE)
    if cfg.load(cfg_phpbb, Const.cfg_opts):
        phpbb = PhpBB(cfg.host)

        # phpbb.setUserAgent(cfg.user_agent)
        if phpbb.login(cfg.username, cfg.password):
            print('Login')

            mode = 0
            while True:
                mode = input(Const.MODE_CHOICE)
                if 1 <= int(mode) <= 2:
                    break
                else:
                    print("\nValeur incorrect")

            # Treat a topic
            if int(mode) == 1:
def test_login():
    """Test PhpBB login()."""
    forum = PhpBB(host)
    assert forum.login(username, password)
    forum.logout()
regex1 = re.compile(reg)


def replace_message(message):
    """Replace text using regex.

    Removes [url=htts://getcomics.....] bbcodes.
    """
    return re.sub(regex1, r"\g<comic>", message)


try:
    # user = int(sys.argv[2])
    cfg = Settings(cfg_file)
    cfg_dict = cfg.read_section(cfg_forum)
    phpbb = PhpBB(cfg_dict['host'])
    # forum.setUserAgent(cfg.user_agent)
    if phpbb.login(cfg_dict['username'], cfg_dict['password']):
        print('Login')
        f_id = 139
        viewtopics = phpbb.get_forum_view_topics(f_id)
        for v in viewtopics[3:10]:
            postlist = phpbb.get_user_topic_posts(v.urlpart,
                                                  int(cfg_dict['max_count']))
            target = postlist.select_user_list(targeted_user)
            target.print_posts_user()
            for p in target:
                txt = phpbb.get_post_editmode_content(f_id, p.id)
                txt2 = replace_message(txt)

                print("============")
Beispiel #7
0
try:
    # Check or create database file
    db = Database(DB_FILE)
    try:
        table = db.table(DB_TABLE).create({
            "topic": int,
            "posts": int
        },
                                          pk="topic")
    except sqlite3.OperationalError:
        # Table already exists
        table = db[DB_TABLE]
    # Config
    cfg = Settings(CFG_FILE)
    if cfg.load(CFG_FORUM, Const.cfg_opts_modo):
        phpbb = PhpBB(cfg.host)
        words_list = tools.configsplit(cfg.keywords)
    else:
        sys.exit(1)

    # forum.setUserAgent(cfg.user_agent)
    if phpbb.login(cfg.username, cfg.password):
        print("Login")
        # f_id = cfg.forum_id.split("&start")[0]
        mode = 0
        while True:
            mode = input(Const.MODE_CHOICE2)
            if 1 <= int(mode) <= 4:
                break
            else:
                print("\nValeur incorrect")
Beispiel #8
0
from utils.phpbb import PhpBB
from utils.settings import Settings
from configparser import NoOptionError

CFG_FILE = '.dctrad.cfg'
CFG_FORUM = 'dctrad'

try:
    # Config
    cfg = Settings(CFG_FILE)
    cfg_dict = cfg.read_section('dctrad')
    forum_dict = cfg.read_section('forums')
    print('Config loaded')

    # Log in
    phpbb = PhpBB(cfg_dict['host'])
    phpbb.login(cfg_dict['username'], cfg_dict['password'])
    f_list = forum_dict['all_topics'].split(",")

    for f in f_list:
        phpbb.get_forum_topics(f)

    Join = input('Appuyez sur une touche pour quitter\n')
    phpbb.logout()
    phpbb.close()

except KeyboardInterrupt:
    print("\nAu revoir")
    sys.exit(0)
except NoOptionError as e:
    print(e)
    try:
        table = db.table(DB_TABLE).create({"topic": int, "posts": int},
                                          pk="topic")
    except sqlite3.OperationalError:
        # Table already exists
        table = db[DB_TABLE]

    # Log
    logfile = open(".merci_logfile.txt", "a+")
    logfile.write(str(datetime.datetime.now()) + "\n")

    # Config
    cfg = Settings(CFG_FILE)
    cfg_dict = cfg.read_section(CFG_FORUM)
    forum_dict = cfg.read_section("forums")
    phpbb = PhpBB(cfg_dict["host"])
    regex1, regex2, regex3 = tools.compute_regex(cfg)

    if phpbb.login(cfg_dict["username"], cfg_dict["password"]):
        print("Login")

        mode = 0
        while True:
            mode = int(input(Const.MODE_CHOICE))
            if 1 <= mode <= 4:
                break
            else:
                print("\nValeur incorrect")

        # One topic
        if mode == 1:
Beispiel #10
0
#!/usr/bin/python3
# -*-coding:utf-8 -*-
"""Purge old messages in 'Sorties VO'."""

import sys
from utils.phpbb import PhpBB
from utils.settings import Settings

CFG_FILE = '.dctrad.cfg'
cfg_forum = 'dctrad'
targeted_user = '******'

try:
    cfg = Settings(CFG_FILE)
    cfg_dict = cfg.read_section('dctrad')
    phpbb = PhpBB(cfg_dict['host'])

    if phpbb.login(cfg_dict['username'], cfg_dict['password']):
        print('Login')
        f_id = 139
        viewtopics = phpbb.get_forum_view_topics(f_id)
        for t in viewtopics[5:10]:
            postlist = phpbb.get_user_topic_posts(t.urlpart,
                                                  int(cfg_dict['max_count']))
            target = postlist.select_user_list(targeted_user)
            target.print_posts_user()

            phpbb.delete_post_list(target)
        else:
            print('> Login failed')
        phpbb.logout()