Skip to content

Lu-C4/Chomikuj-Client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chomikuj.pl Python API Wrapper

This project provides an unofficial Python class to interact with the Polish file-hosting service Chomikuj.pl. It automates actions such as logging in, managing folders, and uploading files by simulating web browser requests and parsing HTML content.

Features

  • Secure, session-based login to your Chomikuj.pl account.
  • Create new folders, with options for password protection and adult content flags.
  • Upload files directly from your local machine.
  • Upload files from a public URL.
  • Fetch and parse the complete folder/directory structure of your account into a nested dictionary.
  • List all files within a specific folder.

Requirements

  • Python 3.11+
  • requests library
  • beautifulsoup4 library

Installation

  1. Clone the repository or save the code: Save the provided code as a Python file (e.g., chomikuj_api.py).

  2. Install the required libraries: Open your terminal or command prompt and run the following command:

    pip install requests beautifulsoup4

Usage

First, import the Chomikuj class from your file. Then, create an instance of the class with your username and password.

# Assuming you saved the code in a file named chomikuj_api.py
from chomikuj_api import Chomikuj
import json

# --- CONFIGURATION ---
USERNAME = "your_chomikuj_username"
PASSWORD = "your_chomikuj_password"

# --- INITIALIZATION ---
try:
    # This will log you in upon initialization
    chomik = Chomikuj(USERNAME, PASSWORD)
    print("Successfully logged in!")
except Exception as e:
    print(f"Failed to initialize or log in: {e}")
    exit()

# --- EXAMPLE WORKFLOW ---

# 1. Get the entire directory structure
print("\nFetching directory structure...")
try:
    structure = chomik.GetDirectoryStructure()
    # Pretty print the JSON structure
    print(json.dumps(structure, indent=2, ensure_ascii=False))

    # You can now navigate this structure to find folder IDs
    # For example, to get the ID of the root folder (usually the first one)
    # NOTE: The root folder itself is not listed, its contents are. ID 0 is the root container.
    first_folder_name = next(iter(structure))
    first_folder_id = structure[first_folder_name]['id']
    print(f"\nFound top-level folder: '{first_folder_name}' with ID: {first_folder_id}")

except Exception as e:
    print(f"An error occurred while fetching the directory structure: {e}")


# 2. Create a new folder in the root directory (parent_folder_id=0)
print("\nCreating a new folder...")
try:
    chomik.CreateNewFolder(
        parent_folder_id=0,
        folder_name="My New API Folder",
        password="safe_password_123" # Optional
    )
    print("Folder 'My New API Folder' created successfully.")
    # You might need to re-fetch the structure to get the new folder's ID
except Exception as e:
    print(f"Failed to create folder: {e}")


# 3. Upload a file from your local computer
# NOTE: You need to know the destination folder ID. Let's use `first_folder_id` from above.
print(f"\nUploading local file to folder ID {first_folder_id}...")
try:
    # Create a dummy file for testing
    with open("test.txt", "w") as f:
        f.write("This is a test file from the API.")
    
    chomik.UploadLocalFile(
        upload_folder_id=first_folder_id,
        file_name="api_test.txt",
        local_file_path="test.txt"
    )
    print("Local file uploaded successfully.")
except Exception as e:
    print(f"Failed to upload local file: {e}")


# 4. Upload a file from a URL
print(f"\nUploading file from URL to folder ID {first_folder_id}...")
try:
    chomik.UploadFileViaURL(
        upload_folder_id=first_folder_id,
        file_name="sample_image.jpg",
        file_url="[https://via.placeholder.com/150](https://via.placeholder.com/150)" # Example image URL
    )
    print("File from URL uploaded successfully.")
except Exception as e:
    print(f"Failed to upload file from URL: {e}")


# 5. List files in a specific folder
print(f"\nListing files in folder ID {first_folder_id}...")
try:
    files = chomik.ListFiles(folder_id=first_folder_id)
    if files:
        print("Found files:")
        for file_name in files:
            print(f"- {file_name}")
    else:
        print("No files found or folder is empty.")
except Exception as e:
    print(f"Failed to list files: {e}")

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages