Giter VIP home page Giter VIP logo

mwxpy's Introduction

MWXpy

My tiny Python library

PyPI version

Documentation

Also there is a video for Persian users:

همچنین یک ویدیو آموزشی برای کاربران فارسی زبان موجوده:

YouTube | Aparat

Installation

pip install mwx

Functions

function cprint ( color:str , text:anything)

This function prints text colored in color in command line

color must be one of these (case insensitive): red 🔴 or green 🟢 or yellow 🟡 or blue 🔵 or white ⚪ or cyan 🌀 or magenta 🟣

text can be anything.It is the text which will be colored and printed to terminal (command line)

NOTE: color is case insensitive so red,RED,Red,ReD,REd,rED,reD and rEd are same 😄

Example:

from mwx import cprint
cprint('green','In the name of Allah')

It will print a green In the name of Allah

Errors:

  • TypeError if color is not str(String)
  • ValueError if color is not in the colors list

function rwjson ( path:str , content:dict-Optional=None ) :

A simple tool for reading & writing JSON files in a very easy way!

path : relative or absolute path to the target JSON file

Returns a dict including data of targeted JSON file if content = None (By default it is None)

Writes content(If it is a dict) into the targeted JSON file.

Example:

import mwx
data = {'name':'Amirreza','age':16}
mwxpy.rwjson('test.json',data)

It will write data to test.json

from mwx import rwjson
data = rwjson('test.json')
print(data)

It will print the whole thing in test.json in format of a python dict

Errors:

  • ValueError if filename does not end with .json

  • FileNotFoundError if path is not a file when you want to read the file (content = None)

  • TypeError if content is not dict or None


function rwfile ( path:str , content:anything-Optional=None ) :

A simple tool for reading & writing files in a very easy way!

path : relative or absolute path of the target file

Returns data of the targeted file if content = None (By default it is None)

Writes content(If it is not None) into the targeted file.

Example:

import mwx
data = 'Hey this is some thing! :)'
mwxpy.rwfile('test.txt',data)

It will write data to test.txt

from mwx import rwfile
data = rwfile('test.txt')
print(data)

It will print the whole thing in test.txt

Errors:

  • FileNotFoundError if path is not a file when you want to read the file (content = None)

function browse ( path:str , show_hidden_files:bool-Optional=False) :

A nice simple file explorer

Returns the information of files that exist in target directory in this way(i.e):

{'drives': [], 'folders': [{'name':'test1','type':'folder'},{'name':'test2','type':'folder'}], 'files': [{'name':'test.py','type':'python'}], 'links': [], 'unknowns': []}

path: relative or absolute path of target directory

If show_hidden_files is True the result will include Unix hidden file(starting with .) and if not result won't include.(By default it is Flase)

Supported types & extentions:

They are in this way:

{"type1":[".extention1",".extention2"],"type2": ...

:

extentions = {
                "css": [
                    ".css",
                    ".sass",
                    ".scss"
                ],
                "database": [
                    ".db",
                    ".sqlite3",
                    ".sqlite",
                    ".sql"
                ],
                "html": [
                    ".html",
                    ".htm"
                ],
                "image": [
                    ".png",
                    ".jpg",
                    ".jpeg",
                    ".svg",
                    ".bmp",
                    ".webp",
                    ".ico"
                ],
                "zip": [
                    ".zip",
                    ".rar",
                    ".tar",
                    ".taz",
                    ".tar.xz"
                ],
                "video": [
                    ".mp4",
                    ".avi",
                    ".wmv",
                    ".mkv",
                    ".gif",
                    ".ogg",
                    ".vob",
                    ".flv",
                    "webm",
                    ".ogv",
                    ".mov",
                    ".3gp",
                    ".m4v"
                ],
                "audio": [
                    ".mp3",
                    ".wav",
                    ".m4a",
                    ".ogg",
                    ".wma",
                    ".mp4a"
                ],
                "python": [
                    ".py"
                ],
                "txt": [
                    ".txt"
                ],
                "javascript": [
                    ".js"
                ],
                "json": [
                    ".json"
                ],
                "php": [
                    ".php"
                ],
                "pdf": [
                    ".pdf"
                ],
                "bash": [
                    ".sh"
                ]
            }

Other types: file(for unsupported file types) folder(for folders) drive(for drives) link(for links) unknown(for unknowns)

Example:

from mwx import browse
print(browse('folder1/folder2'))
import mwx
content = mwxpy.browse('/tmp/sub/test',True)

The second one will include hidden files too

Errors:

  • ValueError if path is not a directory

mwxpy's People

Contributors

openmindamir avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.