Skip to content

Commit

Permalink
ff
Browse files Browse the repository at this point in the history
  • Loading branch information
odilxon committed Sep 14, 2023
1 parent 03661cc commit 3026aa0
Show file tree
Hide file tree
Showing 4 changed files with 264 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
DS_Store
.env
.flaskenv
*.pyc
*.pyo
env/
venv/
.venv/
env*
dist/
build/
*.egg
*.egg-info/
.tox/
.cache/
.pytest_cache/
.idea/
docs/_build/
.vscode
# Coverage reports
htmlcov/
.coverage
.coverage.*
*,cover

# Dev
static/*
database.db
trash/
99 changes: 99 additions & 0 deletions railwagonlocation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import httpx

class RailWagonLocation:

base_url = None
username = None
password = None
return_formats = [
"xml",
"xmlZipped",
"json",
"jsonZipped"
]

def __init__(self, username: str, password: str, base_url: str, return_format : str ="json"):
if return_format not in self.return_formats:
raise ValueError("return_format must be one of {}".format(self.return_formats))
if not username:
raise ValueError("username is required")
if not password:
raise ValueError("password is required")
if not base_url:
raise ValueError("base_url is required")
self.username = username
self.password = password
self.return_format = return_format
self.base_url = base_url
self.client = httpx.Client(http2=True)
pass

def make_request(self, **args):
args["name"] = self.username
args["password"] = self.password
args["return_format"] = self.return_format
response = self.client.get(self.base_url, params=args)
return response.json() if self.return_format == "json" else r.text


def get_wagon_info(self, vagon_number: str):
"""Получение данных о конкретном вагоне, стоящем на слежении
Аргументы:
vagon_number (str): Номер вагона
Возвращает:
Объект: Полная информация о вагоне
"""
return self.make_request(request_type="view_vagon",vagon_no=vagon_number)

def get_wagon_repair_history(self, vagon_number: str):
"""Получение истории ремонтов конкретного вагона по номеру вагона
Аргументы:
vagon_number (str): Номер вагона
Возвращает:
Cписок: Cписок ремонтов, произведённых с вагоном
"""
return self.make_request(request_type="view_vagon_repairs",vagon_no=vagon_number)

def get_wagon_history(self, vagon_number: str, days_limit: int = 30):
"""Получение истории передвижения конкретного вагона
Аргументы:
vagon_number (str): Номер вагона
days_limit (int, optional): Количество дней, за которые получить историю. Значение по умолчанию – 30.
Возвращает:
Cписок: Cписок истории передвижения вагона
"""
return self.make_request(request_type="view_vagon_history",vagon_no=vagon_number,days_limit=days_limit)

def get_all_wagons_info(self, all_operations=False, added_last_minutes="60", calendar_date=None):
"""Получение данных о всех вагонах пользователя
Аргументы:
all_operations (str, optional): Показывать все последние операции по каждому вагону или нет. Возможные значения: y – все операции, n – только самую последнюю операцию. Значение по умолчанию – n.
added_last_minutes (str, optional): Опционально можно указать за какой период выгружать операции (в этом примере за последние 60 минут). Имеет смысл только с параметром all_operations=y
calendar_date (_type_, optional): дата, за которую даются данные о дислокации. Опционально, по умолчанию берутся самые свежие данные.
Возвращает:
Объект: Вагоны пользователя
"""
all_operations = "y" if all_operations else "n"
if calendar_date:
return self.make_request(request_type="get_user_vagons",all_operations=all_operations,calendar_date=calendar_date)
return self.make_request(request_type="get_user_vagons",all_operations=all_operations,added_last_minutes=added_last_minutes)

def get_inquiries(self, period_start, period_end):
"""Получение справок
Аргументы:
period_start (str): Начало периода в формате YYYY-MM-DD
period_end (str): Конец периода в формате YYYY-MM-DD
Возвращает:
Cписок: Cписок справок
"""
return self.make_request(request_type="get_inquiries",period_start=period_start,period_end=period_end)
49 changes: 49 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# RailwagonLocation

![GitHub top language](https://img.shields.io/github/languages/top/Odya-LLC/flask_html)
![LICENCE](https://img.shields.io/github/license/Odya-LLC/railwagonlocation)
![Odya](https://img.shields.io/static/v1?label=Developed_by&message=Odya&color=green&logo=python)

Python client for the RailwagonLocation API.


## Installation

```bash
pip install railwagonlocation
```

## Usage

```python
from railwagonlocation import RailWagonLocation

# Create client
# username - username for RailwagonLocation API
# password - password for RailwagonLocation API
# base_url - base url for RailwagonLocation API
# return_format - json or xml, default json
client = RailWagonLocation('username', 'password', 'base_url',return_format='json',)

# Get wagon info
wagons = client.get_wagon_info('12345678')
# Get wagon repair s history
history = client.get_wagon_repair_history('12345678')
# Get vagon info with history
wagon_history = client.get_wagon_history('12345678',days_limit=30)

# Get all wagon info
# all_operations - get all operations for wagon
# added_last_minutes - get wagons added in last minutes without calendar_date
# calendar_date - get wagons added in calendar_date, added_last_minutes not work with calendar_date
wagons = client.get_all_wagons_info(all_operations=True, added_last_minutes=60, calendar_date="2021-01-01")

```

## Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## License

This project is licensed under the MIT License (see the LICENSE file for details).
87 changes: 87 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
"""
RailWagonLocation
-------------
Python client for the RailwagonLocation API.
"""
from setuptools import setup

long_description = """
# RailwagonLocation
![GitHub top language](https://img.shields.io/github/languages/top/Odya-LLC/flask_html)
![LICENCE](https://img.shields.io/github/license/Odya-LLC/railwagonlocation)
![Odya](https://img.shields.io/static/v1?label=Developed_by&message=Odya&color=green&logo=python)
Python client for the RailwagonLocation API.
## Installation
```bash
pip install railwagonlocation
```
## Usage
```python
from railwagonlocation import RailWagonLocation
# Create client
# username - username for RailwagonLocation API
# password - password for RailwagonLocation API
# base_url - base url for RailwagonLocation API
# return_format - json or xml, default json
client = RailWagonLocation('username', 'password', 'base_url',return_format='json',)
# Get wagon info
wagons = client.get_wagon_info('12345678')
# Get wagon repair s history
history = client.get_wagon_repair_history('12345678')
# Get vagon info with history
wagon_history = client.get_wagon_history('12345678',days_limit=30)
# Get all wagon info
# all_operations - get all operations for wagon
# added_last_minutes - get wagons added in last minutes without calendar_date
# calendar_date - get wagons added in calendar_date, added_last_minutes not work with calendar_date
wagons = client.get_all_wagons_info(all_operations=True, added_last_minutes=60, calendar_date="2021-01-01")
```
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
## License
This project is licensed under the MIT License (see the LICENSE file for details).
"""

setup(
name='RailWagonLocation',
version='1.0.0',
url='https://github.com/Odya-LLC/railwagonlocation',
license='MIT',
author='odya',
author_email='[email protected]',
description='Python client for the RailwagonLocation API.',
long_description=long_description,
long_description_content_type='text/markdown',
packages=['railwagonlocation'],
zip_safe=False,
include_package_data=True,
platforms=['3.8', '3.9', '3.10', '3.11', '3.12'],
install_requires=[
'httpx[http2]'
],
classifiers=[
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Software Development :: Libraries :: Python Modules'
]
)

0 comments on commit 3026aa0

Please sign in to comment.