Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4980390

Browse files
author
Mark Brewster
committed
create public repo for python-soap API library
0 parents  commit 4980390

15 files changed

Lines changed: 730 additions & 0 deletions

.coveragerc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[run]
2+
source = src
3+
omit = tests/*

.gitignore

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
/lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
TEST-*.xml
47+
*.cover
48+
.hypothesis/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
58+
# Flask stuff:
59+
instance/
60+
.webassets-cache
61+
62+
# Scrapy stuff:
63+
.scrapy
64+
65+
# Sphinx documentation
66+
docs/_build/
67+
68+
# PyBuilder
69+
target/
70+
71+
# Jupyter Notebook
72+
.ipynb_checkpoints
73+
74+
# pyenv
75+
.python-version
76+
77+
# celery beat schedule file
78+
celerybeat-schedule
79+
80+
# SageMath parsed files
81+
*.sage.py
82+
83+
# dotenv
84+
.env
85+
86+
# virtualenv
87+
.venv
88+
venv/
89+
ENV/
90+
91+
# Spyder project settings
92+
.spyderproject
93+
.spyproject

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include README.rst
2+
include version.py

examples/usage_example.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# flake8: noqa
2+
from panopto_api.AuthenticatedClientFactory import AuthenticatedClientFactory
3+
from panopto_api.ClientWrapper import ClientWrapper
4+
from datetime import datetime, timedelta
5+
from math import ceil
6+
7+
host = 'localhost'
8+
username = 'admin'
9+
password = '<insert local password>'
10+
11+
# create a client factory for making authenticated API requests
12+
auth = AuthenticatedClientFactory(
13+
host, username, password, verify_ssl=host != 'localhost')
14+
15+
# let's get the admin user
16+
user = auth.get_client('UserManagement')
17+
lu_response = user.call_service(
18+
'ListUsers',
19+
searchQuery='admin',
20+
parameters={})
21+
# 'admin' user is guaranteed to exist! pluck it out, excluding any other users that might match the query
22+
match_pattern = '<span class="match">admin</span>' # the span will contain the matching portion of the username
23+
admin = [r for r in lu_response['PagedResults']['User'] if r['UserKey'] == match_pattern][0]
24+
25+
# what has the admin user been watching?
26+
page_size = 10
27+
usage = auth.get_client('UsageReporting')
28+
gudu_response = usage.call_service(
29+
'GetUserDetailedUsage',
30+
userId=admin['UserId'],
31+
pagination={ 'MaxNumberResults': page_size }
32+
)
33+
if gudu_response['TotalNumberResponses'] > 0:
34+
# get the last page!
35+
gudu_response = usage.call_service(
36+
'GetUserDetailedUsage',
37+
userId=admin['UserId'],
38+
pagination={
39+
'MaxNumberResults': page_size,
40+
'PageNumber': int(ceil(gudu_response['TotalNumberResponses'] / float(page_size)) - 1)
41+
}
42+
)
43+
endRange = datetime.utcnow()
44+
beginRange = endRange - timedelta(days=7)
45+
week_views = [v for v in gudu_response['PagedResponses']['DetailedUsageResponseItem'] if v['Time'] > beginRange]
46+
if week_views:
47+
# let's get the sessionId of the first view and see who else has been watching it in the past week
48+
sessionId = week_views[0]['SessionId']
49+
print 'admin viewed session {} in the past week'.format(sessionId)
50+
51+
ssu_response = usage.call_service(
52+
'GetSessionSummaryUsage',
53+
sessionId=sessionId,
54+
beginRange=beginRange,
55+
endRange=endRange,
56+
granularity='Daily' # zeep doesn't currently support parsing enumeration types, so this is a magic string
57+
)
58+
view_days = [r for r in ssu_response if r['Views'] > 0]
59+
for day in sorted(view_days, key=lambda d:d['Time']):
60+
day_offset = int(ceil((endRange - day['Time'].replace(tzinfo=None)).total_seconds() / (3600 * 24)))
61+
print '{} day{} ago: {} unique users viewed {} minutes in {} distinct views'.format(
62+
day_offset,
63+
's' if day_offset > 1 else ' ',
64+
day['UniqueUsers'],
65+
day['MinutesViewed'],
66+
day['Views'])
67+
else:
68+
print 'no admin views in the past week'

readme.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# python-soap
2+
a python soap Panopto API client that wraps the zeep library for the heavy lifting
3+
4+
5+
Updating dependencies
6+
---------------------
7+
This package has dependencies defined in two places: setup.py and requirements-dev.txt
8+
The **abstract** dependencies defined in setup.py are required for **module dependencies**.
9+
The **abstract** dependencies defined in requirements-dev.txt are only needed for **test and development** dependencies.
10+
11+
The following command will combine both of those abstract dependency files in order to generate the **pinned**
12+
requirements.txt file. This is what is used by the test systems in order to guarantee a stable testing environment.
13+
14+
.. code:: console
15+
$ pip-compile --output-file requirements.txt --annotate --header requirements-dev.txt
16+
17+
To update all packages, periodically re-run ``pip-compile --upgrade requirements.txt``.
18+
19+
To update a specific package to the latest or a specific version use the
20+
``--upgrade-package`` or ``-P`` flag:
21+
22+
.. code:: console
23+
24+
$ pip-compile --upgrade-package requests --output-file requirements.txt --annotate --header requirements-dev.txt
25+
26+
Pushing a new build of the package
27+
----------------------------------
28+
29+
Make sure everything builds
30+
31+
.. code:: console
32+
33+
tox
34+
35+
If that succeeds, then you can push a source package to artifactory
36+
(This assumes that you've defined our local artifactory as "local" in
37+
~/.pypirc).
38+
39+
.. code:: console
40+
python setup.py bdist_wheel --universal upload -r local

requirements-dev.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
flake8
2+
pip-conflict-checker
3+
pip-tools
4+
pytest
5+
pytest-cov
6+
pytest-runner
7+
8+
# This will use the current directory's dependencies i.e. the package dependencies from setup.py
9+
-e .
10+

requirements.txt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# This file is autogenerated by pip-compile
3+
# To update, run:
4+
#
5+
# pip-compile --upgrade-package requests --output-file requirements.txt --annotate --header requirements-dev.txt
6+
#
7+
8+
-e .
9+
appdirs==1.4.3 # via zeep
10+
attrs==17.3.0 # via pytest
11+
cached-property==1.3.1 # via zeep
12+
certifi==2017.11.5 # via requests
13+
chardet==3.0.4 # via requests
14+
click==6.7 # via pip-tools
15+
colorama==0.3.9 # via pytest
16+
configparser==3.5.0 # via flake8
17+
coverage==4.4.2 # via pip-conflict-checker, pytest-cov
18+
defusedxml==0.5.0 # via zeep
19+
enum34==1.1.6 # via flake8
20+
first==2.0.1 # via pip-tools
21+
flake8==3.5.0
22+
funcsigs==1.0.2 # via mock, pytest
23+
idna==2.6 # via requests
24+
isodate==0.6.0 # via zeep
25+
lxml==4.1.1 # via zeep
26+
mccabe==0.6.1 # via flake8
27+
mock==2.0.0 # via pip-conflict-checker
28+
nose==1.3.7 # via pip-conflict-checker
29+
pbr==3.1.1 # via mock
30+
pip-conflict-checker==0.5.0
31+
pip-tools==1.10.2
32+
pluggy==0.6.0 # via pytest
33+
py==1.5.2 # via pytest
34+
pycodestyle==2.3.1 # via flake8
35+
pyflakes==1.6.0 # via flake8
36+
pytest-cov==2.5.1
37+
pytest-runner==3.0
38+
pytest==3.3.0
39+
pytz==2017.3 # via zeep
40+
requests-toolbelt==0.8.0 # via zeep
41+
requests==2.18.4 # via requests-toolbelt, zeep
42+
six==1.11.0 # via isodate, mock, pip-tools, pytest, zeep
43+
urllib3==1.22 # via requests
44+
zeep==2.4.0

setup.cfg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[aliases]
2+
test=pytest
3+
4+
[tool:pytest]
5+
addopts = --verbose

setup.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/python
2+
3+
from setuptools import setup, find_packages
4+
from version import get_version
5+
6+
7+
def readme():
8+
with open('README.rst') as f:
9+
return f.read()
10+
11+
12+
setup(
13+
name='panopto-python-soap',
14+
version=get_version('short'),
15+
author='Mark Brewster',
16+
author_email='[email protected]',
17+
description=('Panopto API client that wraps the zeep library for the heavy lifting'),
18+
long_description=readme(),
19+
keywords=['python', 'panopto', 'lambda', 'api', 'soap'],
20+
install_requires=[
21+
're',
22+
'urllib3',
23+
'zeep'
24+
],
25+
package_dir={'': 'src'},
26+
packages=find_packages('src')
27+
)

0 commit comments

Comments
 (0)