Skip to content

Commit

Permalink
added /wlan/host-list api endpoint and setup.py file
Browse files Browse the repository at this point in the history
  • Loading branch information
dopstar committed Feb 11, 2019
1 parent 4f6172f commit e26531b
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ venv
gw.py

*.csv
*.pyc

initial_skip
23 changes: 23 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
language: python
python:
- 2.7
- 3.5
- 3.6
matrix:
include:
- python: 3.7
dist: xenial
sudo: true
sudo: false
install:
- pip install -U pip
- pip install .
script:
- nosetests --stop --verbose tests
deploy:
provider: pypi
user: dopstar
password:
secure: UeBh7chwub2qlaCpG4C3/BShOZJfcz1LoTQk2KR6JLX6mVJgrNdPphnHMl1tQqWytNg1qtnkdvSgwqvxnx63z2UviuZlzPum6/KDTaoCfjfeAS3mVtnPRx6Di1LieVvpEeY+oLeheJdd8lXlS/GxRdGtxzgoc87fYpFFPXCx/HbL5GCXgXUMJ0tMdjcS2XrtX87iAmk7gYzPq5ovPvqTDdjLHwAKe7mfQUq61/osb9D3TeeVhXtOvLnfPIW6JylPVusgnUEXw2EpYJfZzKUITmIO5+STeRzhI9mlSa5bepUrs9wrcv4aMdXanC3MLlWfdTcafb2jr161OstXaVBhSxrw9UiSHolWE+ZOXIUVyd5l17AazZ0VckViWPMkj631gPhPLiOozq8rTNflYcuK/RZK7UM1a5rLiL78UOzyvmiKxS0YL7ATW/wC3BCN+QNqV4HMqSMqLdRcSJhAPnuWLRw9hHESlFBBHc4lq9InZP3GMddOed0nuYUDY207T87gclIhsBqFjj6Dxb9AED5gDt2m1KmX/hRQKGx9UUcqOhUeUOY/MjlvRIH+ReM14XXLMTriYX/hGwZIcOTnxSZ9bb7lWl95iflMC+5rLaV1/VCIhxhCazgKXwnTuicsSugCkFnwEqPhEPh2ZmKhLYI/LDjrJpZfC/zTVeKQkybIbyE=
on:
tags: true
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,31 @@ requests==2.0.0

### Installing

Todo: make it a `pip install` option for this package.
```bash
pip install huawei-modem-api-client
```

### Example
```python
import huaweisms.api.user
import huaweisms.api.wlan
import huaweisms.api.sms

ctx = huaweisms.api.user.quick_login("myusername", "mypassword")
print(ctx)
# output: <ApiCtx online>

# sending sms
huaweisms.api.sms.send_sms(
ctx,
'phone-number',
'this is the sms message'
)

# connected devices
device_list = huaweisms.api.wlan.get_connected_hosts(ctx)

```

## Built With

Expand Down
12 changes: 12 additions & 0 deletions huaweisms/api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ def __init__(self) -> None:
self.token = None
self.tokens = []

def __unicode__(self):
return '<{} {}>'.format(
self.__class__.__name__,
'online' if self.logged_in else 'offline'
)

def __repr__(self):
return self.__unicode__()

def __str__(self):
return self.__unicode__()


def common_headers():
return {
Expand Down
28 changes: 16 additions & 12 deletions huaweisms/api/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

import binascii

import json

import huaweisms.api.webserver
from huaweisms.api.config import API_URL
from huaweisms.api.common import common_headers, ApiCtx, post_to_url, get_from_url
from .config import API_URL


def b64_sha256(data: str) -> str:
Expand All @@ -16,21 +19,21 @@ def b64_sha256(data: str) -> str:
return base64.urlsafe_b64encode(hs256).decode('utf-8', 'ignore')


def quick_login(username: str, password: str):
ctx = ApiCtx()
token = huaweisms.api.webserver.SesTokInfo()
ctx.session_id = token['response']['SesInfo'].split("=")[1]
ctx.token = token['response']['TokInfo']
response = login(ctx, username, password)
if not ctx.logged_in:
raise ValueError(json.dumps(response))
return ctx


def login(ctx: ApiCtx, user_name: str, password: str):
headers = common_headers()
url = "{}/user/login".format(API_URL)

# original JS code:
# psd = base64encode(
# SHA256(
# name +
# base64encode(
# SHA256($('#password').val())
# ) +
# g_requestVerificationToken[0]
# )
# );

password_value = b64_sha256(user_name + b64_sha256(password) + ctx.token)

xml_data = """
Expand All @@ -53,6 +56,7 @@ def login(ctx: ApiCtx, user_name: str, password: str):

return r


def state_login(ctx: ApiCtx):
url = "{}/user/state-login".format(API_URL)
return get_from_url(url, ctx)
Expand Down
7 changes: 7 additions & 0 deletions huaweisms/api/wlan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from huaweisms.api.common import get_from_url, ApiCtx
from .config import API_URL


def get_connected_hosts(ctx: ApiCtx):
url = "{}/wlan/host-list".format(API_URL)
return get_from_url(url, ctx)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
47 changes: 47 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from setuptools import setup

version = '1.0.0'

with open('requirements.txt') as fd:
requirements = [line.strip() for line in fd if line.strip()]

with open('README.md') as fd:
long_description = fd.read()

if 'a' in version:
dev_status = '3 - Alpha'
elif 'b' in version:
dev_status = '4 - Beta'
else:
dev_status = '5 - Production/Stable'

setup_args = {
'name': 'huawei-modem-api-client',
'version': version,
'author': 'Pablo Santa Cruz, Mkhanyisi Madlavana',
'author_email': 'pablo@github.com, mkhanyisi@gmail.com',
'url': 'https://github.com/pablo/huawei-modem-python-api-client',
'download_url': 'https://github.com/pablo/huawei-modem-python-api-client/tarball/{0}'.format(version),
'package_dir': {'huaweisms': 'huaweisms'},
'description': 'huaweisms is a python api client for Huawei Modems.',
'long_description': long_description,
'long_description_content_type': 'text/markdown',
'packages': [
'huaweisms',
'huaweisms.api',
'huaweisms.xml',
],
'install_requires': requirements,
'keywords': 'Huawei Modem API',
'classifiers': [
'Development Status :: {0}'.format(dev_status),
'Intended Audience :: End Users/Desktop',
'Natural Language :: English',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
}

setup(**setup_args)

0 comments on commit e26531b

Please sign in to comment.