Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: persian-tools/py-persian-tools
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.0.8
Choose a base ref
...
head repository: persian-tools/py-persian-tools
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
14 changes: 7 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -7,19 +7,19 @@ on:

jobs:
test:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9]
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11']

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Test
run: bash scripts/test.sh
- name: Upload coverage
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v3
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
venv
.idea
.coverage
coverage.xml
.pytest_cache
__pycache__
96 changes: 94 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -18,7 +18,10 @@ An anthology of a variety of tools for the Persian language in Python
1. [card number](#card-number)
2. [sheba](#sheba)
5. [national id](#national-id)
6. [phone number](#phone-number)
6. [legal id](#legal-id)
7. [phone number](#phone-number)
8. [bill](#bill)
9. [plate](#plate)

## Usage
Let's take a look at what an example test case would look like using `persian-tools`.
@@ -53,6 +56,20 @@ digits.convert_to_word(500443, ordinal=True) # پانصد هزار و چها
digits.convert_to_word(30000000000) # سی میلیارد
```

to convert words to number, you can use this function with different args:
```python
from persian_tools import digits

digits.convert_from_word('منفی سه هزارمین') # -3000
digits.convert_from_word('منفی سه هزارم', digits='fa') # -۳۰۰۰
digits.convert_from_word('منفی سه هزار') # -3000
digits.convert_from_word('سه هزار دویست و دوازده') # 3212
digits.convert_from_word('دوازده هزار بیست دو', separator=True) # '12,022'
digits.convert_from_word('حقوق شیش صد و ۲۷ میلیون تومان سالانه') # 627000000
```

Note: as you can see in examples, this function will remove ordinal suffix by default.

### separator
Adding or removing thousands separators will handle; default separator is ',' but can change with second input.

@@ -180,8 +197,21 @@ national_id.find_place('0906582709') # {'code': ['089', '090'], 'city': 'کا
national_id.find_place('0643005846') # {'code': ['064', '065'], 'city': 'بیرجند', 'province': 'خراسان جنوبی'}
```

### legal id
This module contains two functions to generate random iranian legal id (shenas-e melli) and validate any given id.

```python
from persian_tools import legal_id

legal_id.validate('10380284790') # True
legal_id.validate('11053639140') # False

legal_id.generate_random() # '10100387143'
legal_id.generate_random() # '77111986110'
```

### phone number
This module can validate and give you some data from a phone number.
This module can validate, normalize and give you some data from a phone number.

```python
from persian_tools import phone_number
@@ -191,9 +221,71 @@ phone_number.validate('+989123456789') # True
phone_number.validate('989123456789') # True
phone_number.validate('98912345678') # False

phone_number.normalize('00989022002580') # 09022002580
phone_number.normalize('+989022002580') # 09022002580
phone_number.normalize('9022002580') # 09022002580
phone_number.normalize('9022002580', '0') # 09022002580
phone_number.normalize('9022002580', '+98') # +989022002580

phone_number.operator_data('09123456789')
# {'province': ['البرز', 'زنجان', 'سمنان', 'قزوین', 'قم', 'برخی از شهرستان های استان مرکزی'], 'base': 'تهران', 'type': ['permanent'], 'operator': 'همراه اول'}
phone_number.operator_data('09303456789')
# {'province': [], 'base': 'کشوری', 'type': ['permanent', 'credit'], 'operator': 'ایرانسل'}
```

### bill
With `bill_id` and `payment_id` (or just `barcode`), you can get detail of a `bill`.

```python
from persian_tools import bill

bill.get_detail(bill_id=7748317800142, payment_id=1770160)
# result
# {'amount': 1700,
# 'barcode': '77483178001420001770160',
# 'bill_id': 7748317800142,
# 'is_valid': True,
# 'is_valid_bill_id': True,
# 'is_valid_payment_id': True,
# 'payment_id': 1770160,
# 'type': 'تلفن ثابت'}

bill.get_detail(barcode='77483178001420001770160')
# same result

# default currency is set to Toman, but can change like as below
bill.get_detail(barcode='77483178001420001770160', currency=bill.CURRENCY_RIAL)
# result
# {'amount': 17000,
# ...
```

### plate
Get information(province, category, type) about vehicles plate.

```python
from persian_tools import plate

plate.get_info('12D45147')
# result
# {'category': 'دیپلمات',
# 'province': 'مرکزی',
# 'template': '12D451ایران47',
# 'type': 'Car'}

plate.get_info('12345678')
# result
# {'category': None,
# 'province': 'مرکز تهران',
# 'template': '123-45678',
# 'type': 'Motorcycle'}

plate.is_valid('12D45147') # True
plate.is_valid('12345678') # True
plate.is_valid('1234567') # False
plate.is_valid('1204567') # False
```

Note: Plates that have farsi digits in them(like: الف، ب، ص) will be returned in this template:

`{first_two_digits}{plate_character}{next_three_digits}ایران{province_code}`
4 changes: 2 additions & 2 deletions persian_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
__author__ = 'Ali Madihi (mrunderline)'
__version__ = '0.0.8'
__date__ = '2021-02-20'
__version__ = '0.0.11'
__date__ = '2023-03-19'

from persian_tools import *
Loading