Example #1
0
CFG_FILE = ".forum.cfg"
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("===================")
Example #2
0
                # phpbb.edit_post(12, 323626, new_message)

            # Treat a forum
            elif int(mode) == 2:
                while True:
                    choice = int(input(Const.SECTION_CHOICE))
                    if choice < 1 or choice > 10:
                        print("\nValeur incorrect")
                    else:
                        break

                try:
                    # Convert input number into forum section (rebirth, etc...)
                    # And read config for this forum section
                    forum_section = Const.SECTION_MAP[choice]
                    forum_dict = cfg.read_section("forums")
                    f_list = forum_dict[forum_section].split(",")
                except KeyError as e:
                    print(e)
                    print("Mauvaise valeur")
                    f_list = None
                    quit()

                reg = re.compile(r't=(?P<topic>\d+)')

                # f_list = cfg.phpbb_list.split(",")
                for f in f_list:
                    topics = phpbb.get_forum_topics(f)
                    f_id = f.split("&start")[0]
                    print("Processing")
                    for t in topics:
reg = r"\[url=https\:\/\/getcomics\.info\/.*?\](?P<comic>.*?)\[\/url\]"
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)
Example #4
0
#!/usr/bin/python3
# -*-coding:utf-8 -*-
"""List all topics in phpbb forum."""

import sys
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()
    # 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]

    # 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")
Example #6
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()