-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6309423
Showing
13 changed files
with
411 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
* trainline version: | ||
* Python version: | ||
* Operating System: | ||
|
||
### Description | ||
|
||
Describe what you were trying to get done. | ||
Tell us what happened, what went wrong, and what you expected to happen. | ||
|
||
### What I Did | ||
|
||
``` | ||
Paste the command(s) you ran and the output. | ||
If there was a crash, please include the traceback here. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Config file for automatic testing at travis-ci.org | ||
|
||
language: python | ||
python: | ||
- 3.6 | ||
|
||
# command to install dependencies | ||
before_script: | ||
- pip install -r requirements.txt | ||
- pip install python-coveralls | ||
- pip install pytest-cov | ||
install: | ||
- pip install . | ||
# command to run tests | ||
script: | ||
- pytest | ||
after_success: | ||
coveralls | ||
deploy: | ||
provider: pypi | ||
user: thibdct | ||
password: | ||
secure: REPLACE_ME | ||
on: | ||
tags: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018, Thibault Ducret | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include *.py | ||
include *.txt | ||
include MANIFEST.in | ||
recursive-include tests * | ||
recursive-exclude * __pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Trainline | ||
|
||
[](https://travis-ci.org/tducret/trainline-python) | ||
[](https://coveralls.io/github/tducret/trainline-python) | ||
[](https://pypi.org/project/trainline/) | ||
 | ||
|
||
## Description | ||
|
||
Non-official Python wrapper and CLI tool for Trainline | ||
|
||
# Requirements | ||
|
||
- Python 3 | ||
- pip3 | ||
|
||
## Installation | ||
|
||
```bash | ||
pip3 install -U trainline | ||
``` | ||
|
||
## Package usage | ||
|
||
```python | ||
# -*- coding: utf-8 -*- | ||
import trainline | ||
|
||
TODO : Insert a package usage | ||
``` | ||
|
||
Example output : | ||
|
||
```bash | ||
|
||
TODO : Insert output | ||
``` | ||
|
||
## TODO | ||
|
||
- [ ] Update the package usage | ||
- [ ] Update the example output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
addopts = --doctest-modules --cov trainline |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
requests>=2.6.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[metadata] | ||
description-file = README.md | ||
|
||
[aliases] | ||
# Define setup.py command aliases here | ||
test = pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""The setup script.""" | ||
|
||
from setuptools import setup, find_packages | ||
try: # For pip >= 10 | ||
from pip._internal.req import parse_requirements | ||
except ImportError: # For pip <= 9 | ||
from pip.req import parse_requirements | ||
|
||
|
||
__version__ = '0.0.1' # Should match with __init.py__ | ||
_GITHUB_URL = 'https://github.com/tducret/trainline-python' | ||
_KEYWORDS = ['api', 'trainline', 'parsing', 'train', 'sncf', | ||
'python-wrapper', 'scraping', 'scraper', 'parser'] | ||
|
||
|
||
install_reqs = parse_requirements('requirements.txt', session='hack') | ||
requirements = [str(ir.req) for ir in install_reqs] | ||
|
||
setup( | ||
name='trainline', | ||
packages=find_packages(), | ||
package_data={}, | ||
|
||
version=__version__, | ||
license="MIT license", | ||
platforms='Posix; MacOS X', | ||
description="Non-official Python wrapper and CLI tool for Trainline", | ||
long_description="Non-official Python wrapper and CLI tool for Trainline", | ||
author="Thibault Ducret", | ||
author_email='[email protected]', | ||
url=_GITHUB_URL, | ||
download_url='{github_url}/tarball/{version}'.format( | ||
github_url=_GITHUB_URL, | ||
version=__version__), | ||
keywords=_KEYWORDS, | ||
setup_requires=requirements, | ||
install_requires=requirements, | ||
classifiers=[ | ||
'License :: OSI Approved :: MIT License', | ||
'Programming Language :: Python :: 3', | ||
], | ||
python_requires='>=3', | ||
tests_require=['pytest'], | ||
) | ||
|
||
# ------------------------------------------ | ||
# To upload a new version on pypi | ||
# ------------------------------------------ | ||
# Make sure everything was pushed (with a git status) | ||
# (or git commit --am "Comment" and git push) | ||
# export VERSION=<VERSION>; git tag $VERSION -m "First version"; git push --tags | ||
|
||
# If you need to delete a tag | ||
# git push --delete origin $VERSION; git tag -d $VERSION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Tests for `trainline` package.""" | ||
|
||
# To be tested with : python3 -m pytest -vs tests/test_trainline.py | ||
|
||
import pytest | ||
import os | ||
from trainline import trainline | ||
|
||
# Get useful environment variables | ||
VAR = os.environ.get('VAR', None) | ||
|
||
|
||
def test_class_MyClass(): | ||
myclass_object = MyClass(param1=1, param2="abc") | ||
assert myclass_object.attribute == 1 | ||
assert str(myclass_object) == "1 abc" | ||
|
||
|
||
def test_class_MyClass_errors(): | ||
with pytest.raises(KeyError): | ||
MyClass(param1=1, param2="UNKNOWN") | ||
|
||
with pytest.raises(TypeError): | ||
MyClass(param1="abc", param2="abc") | ||
|
||
with pytest.raises(ValueError): | ||
MyClass(param2="abc") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Top-level package for Trainline.""" | ||
|
||
import requests | ||
from requests import ConnectionError | ||
|
||
__author__ = """Thibault Ducret""" | ||
__email__ = '[email protected]' | ||
__version__ = '0.0.1' | ||
|
||
|
||
class Client(object): | ||
""" Do the requests with the servers """ | ||
def __init__(self): | ||
self.session = requests.session() | ||
self.headers = { | ||
'Host': 'myhost.com', | ||
'User-Agent': 'User agent', | ||
} | ||
|
||
def _get(self, url, expected_status_code=200): | ||
ret = self.session.get(url=url, headers=self.headers) | ||
if (ret.status_code != expected_status_code): | ||
raise ConnectionError( | ||
'Status code {status} for url {url}\n{content}'.format( | ||
status=ret.status_code, url=url, content=ret.text)) | ||
return ret | ||
|
||
def _post(self, url, post_data, expected_status_code=200): | ||
ret = self.session.post(url=url, | ||
headers=self.headers, | ||
data=post_data) | ||
if (ret.status_code != expected_status_code): | ||
raise ConnectionError( | ||
'Status code {status} for url {url}\n{content}'.format( | ||
status=ret.status_code, url=url, content=ret.text)) | ||
return ret | ||
|
||
|
||
class MyClass(object): | ||
""" Class to... """ | ||
def __init__(self, param1, list1, dict1): | ||
self.param1 = param1 | ||
self.list1 = list1 | ||
self.dict1 = dict1 | ||
|
||
def get_param1(self): | ||
""" Get the param1 """ | ||
return(self.param1) | ||
|
||
def __str__(self): | ||
return('{}'.format(self.param1)) | ||
|
||
def __repr__(self): | ||
return("Myclass(param1={})".format(self.param1)) | ||
|
||
def __len__(self): | ||
return len(self.list1) | ||
|
||
def __getitem__(self, key): | ||
""" Méthod to access the object as a list | ||
(ex : list1[1]) """ | ||
return self.list[key] | ||
|
||
def __getattr__(self, attr): | ||
""" Method to access a dictionnary key as an attribute | ||
(ex : dict1.my_key) """ | ||
return self.dict1.get(attr, "") |
Oops, something went wrong.