add remote example
This commit is contained in:
parent
be4aba17dc
commit
285d7316be
1 changed files with 33 additions and 0 deletions
33
examples/remote/example.py
Normal file
33
examples/remote/example.py
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Hangman example
|
||||||
|
"""
|
||||||
|
from json import loads, dumps
|
||||||
|
from urllib.request import urlopen, Request
|
||||||
|
from tiramisu_json_api import Config
|
||||||
|
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteConfig(Config):
|
||||||
|
def __init__(self,
|
||||||
|
url):
|
||||||
|
json = loads(urlopen(url).read())
|
||||||
|
super().__init__(json)
|
||||||
|
self.url = url
|
||||||
|
|
||||||
|
def send_data(self,
|
||||||
|
updates):
|
||||||
|
request = Request(self.url, dumps(updates).encode(), method='POST')
|
||||||
|
return loads(urlopen(request).read())
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
config = RemoteConfig('http://localhost:8000')
|
||||||
|
parser = TiramisuCmdlineParser()
|
||||||
|
parser.add_arguments(config)
|
||||||
|
parser.parse_args()
|
||||||
|
config = parser.get_config()
|
||||||
|
print(config.value.dict())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in a new issue