{"id":16613362,"url":"https://github.com/sergeileduc/pyphpbb-sl","last_synced_at":"2025-03-10T22:59:15.081Z","repository":{"id":104195608,"uuid":"283610908","full_name":"Sergeileduc/pyphpbb-sl","owner":"Sergeileduc","description":"Interact with phpbb forums with python","archived":false,"fork":false,"pushed_at":"2024-09-17T16:39:51.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-17T16:26:56.193Z","etag":null,"topics":["forum","forums","phpbb","phpbb-forums","python","python3"],"latest_commit_sha":null,"homepage":"https://pyphpbb-sl.readthedocs.io/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sergeileduc.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-29T22:01:24.000Z","updated_at":"2024-09-17T16:39:28.000Z","dependencies_parsed_at":"2025-01-17T16:26:21.558Z","dependency_job_id":"cfe58e34-4e7c-4768-81f4-ed516296fb4b","html_url":"https://github.com/Sergeileduc/pyphpbb-sl","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sergeileduc%2Fpyphpbb-sl","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sergeileduc%2Fpyphpbb-sl/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sergeileduc%2Fpyphpbb-sl/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sergeileduc%2Fpyphpbb-sl/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sergeileduc","download_url":"https://codeload.github.com/Sergeileduc/pyphpbb-sl/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242940018,"owners_count":20209883,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["forum","forums","phpbb","phpbb-forums","python","python3"],"created_at":"2024-10-12T01:47:02.966Z","updated_at":"2025-03-10T22:59:15.060Z","avatar_url":"https://github.com/Sergeileduc.png","language":"Python","readme":"![Python package](https://github.com/Sergeileduc/pyphpbb-sl/workflows/Python%20package/badge.svg)\n[![Documentation Status](https://readthedocs.org/projects/pyphpbb-sl/badge/?version=latest)](https://pyphpbb-sl.readthedocs.io/en/latest/?badge=latest)\n[![codecov](https://codecov.io/gh/Sergeileduc/pyphpbb-sl/branch/master/graph/badge.svg)](https://codecov.io/gh/Sergeileduc/pyphpbb-sl)\n\n# pyphpbb-sl\n\nInteract with phpbb forums.\n\n* Free software: MIT license\n* Documentation: \u003chttps://pyphpbb-sl.readthedocs.io/\u003e\n\n## Installation\n\n```shell\npip install git+https://github.com/Sergeileduc/pyphpbb-sl.git\n```\n\nor put this line in your `requirements.txt`\n\n`git+https://github.com/Sergeileduc/pyphpbb-sl.git`\n\nTo install specific version (git tag), use the following syntax with `@`:\n\n`pip install git+https://github.com/Sergeileduc/pyphpbb-sl.git@v0.12.0`\n\n### Features\n\n* Log-in\n* Send Private-Messages\n* Read Private-Messages\n* Delete Private-Messages\n* Fetch forum birthdays\n\n### Usage\n\n#### To send *Private Message*\n\n```python\nimport asyncio\nimport logging\nfrom pyphpbb_sl import PhpBB\n\n# Credentials\nhost = \"http://myforum.fr/\"\nusername = \"Username\"\npassword = \"Pass1234\"\n\n# Message\nreceiver = \"ReceiverPseudo\"\nsubject = \"Sent from Python\"\nmessage = \"Message sent from Python.\\nSee yah !\"\n\nasync def main():\n    # Here is the code :\n    phpbb = PhpBB(host)\n    await phpbb.login(username, password)\n    await phpbb.send_private_message(receiver=receiver,\n                                     subject=subject,\n                                     message=message)\n\n    await phpbb.logout()\n    await phpbb.close()\n\n# Run sample\nasyncio.run(main())\n```\n\nYou can also use a context manager with the keyword `with`(automatic logout and close)\n\n```python\nimport asyncio\nimport logging\nfrom pyphpbb_sl import PhpBB\n\nlogging.basicConfig(level=logging.INFO)\n\n# Credentials\nhost = \"http://myforum.fr/\"\nusername = \"Username\"\npassword = \"Pass1234\"\n\n# Message\nreceiver = \"ReceiverPseudo\"\nsubject = \"Sent from Python\"\nmessage = \"Message sent from Python.\\nSee yah !\"\n\n# With context manager\nasync def main():\n    async with PhpBB(host) as phpbb:\n        await phpbb.login(username, password)\n        await phpbb.send_private_message(receiver=receiver,\n                                         subject=subject,\n                                         message=message)\n\n# Run sample\nasyncio.run(main())\n```\n\n#### To read *Private Message*\n\n```python\nimport asyncio\nimport logging\nfrom pyphpbb_sl import PhpBB\n\nlogging.basicConfig(level=logging.INFO)\n\nhost = \"http://myforum.fr/\"\nusername = \"Username\"\npassword = \"Pass1234\"\n\n\n# Context Manager code\nasync def main():\n    async with PhpBB(host) as phpbb:\n        await phpbb.login(username, password)\n        unread_mess_list = await phpbb.fetch_unread_messages()\n        print(\"Here are your unread messages :\")\n        print(*unread_mess_list, sep='\\n')\n\n        print(\"\\nHere are the contents of messages (messages have been marked as read) :\")\n        for unread_mess in unread_mess_list:\n            message = await phpbb.read_private_message(unread_mess)\n            print(message)\n\nasyncio.run(main())\n```\n\nOuput :\n\n```shell\nHere are your unread messages :\nMessage(subject='Sent by python. Number 2', url='./ucp.php?i=pm\u0026mode=view\u0026f=0\u0026p=14249', fromto='DC-Trad', content=None, unread=True)\nMessage(subject='Sent by python. Number 1', url='./ucp.php?i=pm\u0026mode=view\u0026f=0\u0026p=14248', fromto='DC-Trad', content=None, unread=True)\n\nHere are the contents of messages (messages have been marked as read) :\nMessage(subject='Sent by python. Number 2', url='./ucp.php?i=pm\u0026mode=view\u0026f=0\u0026p=14249', fromto='DC-Trad', content='This message was sent by python Number 2.', unread=False)\nMessage(subject='Sent by python. Number 1', url='./ucp.php?i=pm\u0026mode=view\u0026f=0\u0026p=14248', fromto='DC-Trad', content='This message was sent by python Number 1.', unread=False)\n```\n\n#### To read *PM* from expected user\n\n```python\nimport asyncio\nimport logging\nfrom pyphpbb_sl import PhpBB\n\nlogging.basicConfig(level=logging.INFO)\n\nhost = \"http://myforum.fr/\"\nusername = \"Username\"\npassword = \"Pass1234\"\n\nexpect_message_from_username = \"OtherName\"\n\n\n# Context Manager code\nasync def main():\n    async with PhpBB(host) as phpbb:\n        await phpbb.login(username_server, password_server)\n        await phpbb.fetch_unread_messages()\n        message_to_read = phpbb.find_expected_message_by_user(expect_message_from_username)\n        if message_to_read:\n            message = await phpbb.read_private_message(message_to_read)\n            print(message)\n\n\nasyncio.run(main())\n```\n\n#### To validate a token\n\nIn next code, we will :\n\n* generate a token\n* *not in code* : give the token to your user (by Discord, mail, etc...)\n* fetch our inbox every 30 seconds in a loop (with 5 minutes timeout)\n* read message from our expected user\n* compare token and message content to validate or not\n\n```python\nimport asyncio\nimport logging\nfrom secrets import token_hex\nimport time\nfrom pyphpbb_sl import PhpBB\n\nlogging.basicConfig(level=logging.INFO)\n\nhost = \"http://myforum.fr/\"\nusername = \"Username\"\npassword = \"Pass1234\"\n\nexpect_message_from_username = \"OtherName\"\n\ntoken = token_hex(16)\n\n# Here we pretend that we give the token to our user {OtherName}, by mail, discord, etc...\n\nasync def try_to_verify(username):\n    \"\"\"Fetch unread mail and try to read PM from OtherName.\n\n    Compare PM content to token.\n    \"\"\"\n    # Connect to phpbb forum and fetch unread PM\n    async with PhpBB(host) as phpbb:\n        await phpbb.login(username_server, password_server)\n        await phpbb.fetch_unread_messages()\n        # Read message from expected user\n        message_to_read = phpbb.find_expected_message_by_user(expect_message_from_username)\n        if message_to_read:\n            message = await phpbb.read_private_message(message_to_read)\n            if message.content == token:\n                print(\"Valid token ! GOOD\")\n                return True\n            else:\n                print(\"Invalid token ! BAD !\")\n                return False\n        return False\n\n\nasync def main():\n    \"\"\"Main loop : lauch try_to_verify() every 30 seconds, with a 5 minutes timeout.\"\"\"\n    print(f\"Please send me the token :\\n{token}\")\n    timeout = time.time() + 5 * 60   # 5 minutes from now\n    while True:\n        await asyncio.sleep(30)  # will fetch PM every 30 seconds\n        if time.time() \u003e timeout:\n            break\n        valid = await try_to_verify(expect_message_from_username)\n        if valid:\n            # do_stuff()\n            break\n\n\nasyncio.run(main())\n```\n\n#### Fetch forum members birthdays\n\n```python\nimport asyncio\nimport logging\nfrom pyphpbb_sl import PhpBB\n\n# Credentials\nhost = \"http://myforum.fr/\"\nusername = \"Username\"\npassword = \"Pass1234\"\n\n\nasync def main():\n    async with PhpBB(host) as phpbb:\n        await phpbb.login(username, password)\n        out = await phpbb.get_birthdays()\n        print(*out, sep='\\n')\n\n\nasyncio.run(main())\n```\n\nOutput :\n\n```shell\n{'name': 'Foo', 'age': 45}\n{'name': 'Bar', 'age': 27}\n{'name': 'FooBar', 'age': 22}\n```\n\n#### Fetch rank of a member\n\n```python\nimport asyncio\nimport logging\nfrom pyphpbb_sl import PhpBB\n\n# Credentials\nhost = \"http://myforum.fr/\"\nusername = \"Username\"\npassword = \"Pass1234\"\n\nmember_name = \"Foobar\"\n\n\nasync def main():\n    async with PhpBB(host) as phpbb:\n        await phpbb.login(username, password)\n        rank = await phpbb.get_member_rank(member_name)\n        print(rank)\n\n\nasyncio.run(main())\n```\n\n## Fetch infos (uid and rank) of a member\n\n```python\nimport asyncio\nimport logging\nfrom pyphpbb_sl import PhpBB\n\n# Credentials\nhost = \"http://myforum.fr/\"\nusername = \"Username\"\npassword = \"Pass1234\"\n\nmember_name = \"Foobar\"\n\n\nasync def main():\n    async with PhpBB(host) as phpbb:\n        uid, rank = await phpbb.get_member_infos(querry_user)\n        print(uid)\n        print(rank)\n\nasyncio.run(main())\n```\n\n### Credits\n\nThis package was created with Cookiecutter and the `audreyr/cookiecutter-pypackage` project template.\n\n.. Cookiecutter: \u003chttps://github.com/audreyr/cookiecutter\u003e\n.. `audreyr/cookiecutter-pypackage`: \u003chttps://github.com/audreyr/cookiecutter-pypackage\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergeileduc%2Fpyphpbb-sl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsergeileduc%2Fpyphpbb-sl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsergeileduc%2Fpyphpbb-sl/lists"}