Skip to content

Commit

Permalink
installation + example
Browse files Browse the repository at this point in the history
  • Loading branch information
MalikAza committed May 24, 2024
1 parent fafa3f8 commit a483dcf
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 4 deletions.
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,52 @@ ZUnivers API python wrapper

[Documentation](https://malikaza.github.io/pyZUnivers/)
## Installation
Copy the `pyZUnivers` folder inside your Python `site-packages` folder.
And don't forget to install dependencies:
**Disclaimers:**
- It is recommended to install the module (with your project using it) in a [virtual environment](https://docs.python.org/3/library/venv.html).
- `pyZUnivers` module is not available on PyPi yet, so you can use the `installation` python script to add required dependencies and add the module to your python `site-packages` folder, making it globally available on your machine.
```bash
pip install requirements.txt
python installation.py
```
or
```bash
pip3 install requirements.txt
python3 installation.py
```

## Example
```python
import discord
from discord.ext import commands
import pyZUnivers as ZU

class Zunivers(commands.Cog):
def __init__(self, bot):
self.bot = bot

@commands.command(name="zuchecker", help="Permets de faire un récap' de qui à besoin de faire quoi.")
async def zuchecker(self, ctx: commands.Context):
server = self.bot.get_guild(<your_guild_id>)
zu_role = server.get_role(<specific_role_id_in_your_guild>)
journa, bonus, nowel = list(), list(), list()
msg = await ctx.send("Je vérifie qui doit faire quelque chose...")
try:
for i in zu_role.members:
konar_profile = ZU.User.get_checker(i.name)
if not konar_profile["journa"]: journa.append(i.name)
if not konar_profile["bonus"]: bonus.append(i.name)
if not konar_profile["advent"] and konar_profile["advent"] is not None: nowel.append(i.name)

embed = discord.Embed(color=discord.Colour(value=0x19BC14), description=f"<#{ZU.utils.JOURNA_BONUS_TICKET_CHANNEL_ID}>")
embed.set_author(name="ZUnivers - Checker")
if len(journa) != 0: embed.add_field(name="📅 Journa", value="".join([f"- {x}\n" for x in journa]))
if len(bonus) != 0: embed.add_field(name="🎁 Bonus", value="".join([f"- {x}\n" for x in bonus]))
if len(nowel) != 0: embed.add_field(name="🎄 Advent", value="".join([f"- {x}\n" for x in nowel]))
if len(journa) == 0 and len(bonus) == 0 and len(nowel) == 0: embed.description = "Personne a besoin de faire quoi que ce soit."

await msg.edit(embed=embed, content="")
except ZU.ZUniversAPIError as e:
await msg.edit("`Erreur dans la command 'zu checker'."
f" {e.message}`\n`Endpoint: {e.url}`")

async def setup(bot):
await bot.add_cog(Zunivers(bot))
```
31 changes: 31 additions & 0 deletions installation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import site
import shutil
import subprocess
from pathlib import Path

def manual_installation():
"""
This function manually installs the required packages and copies the current folder to site-packages.
"""
print("=== Manual installation ===")

print('Installing required dependencies...')
try:
subprocess.run(['pip', 'install', '-r', 'requirements.txt'], check=True)
except subprocess.CalledProcessError as e:
print('Error: ' + str(e))
return

print('Copying the module to site-packages...')
try:
site_packages_folder = Path(site.getsitepackages()[0])
module_folder = (Path(__file__).resolve().parent / 'pyZUnivers')
shutil.copytree(module_folder, site_packages_folder / 'pyZUnivers')
except shutil.Error as e:
print('Error: ' + str(e))
return

print('Installation completed successfully!')

if __name__ == '__main__':
manual_installation()

0 comments on commit a483dcf

Please sign in to comment.