parent
8978457a67
commit
4b5b74aa76
|
@ -3,8 +3,19 @@
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import urlparse
|
import urlparse
|
||||||
from datetime import datetime
|
from datetime import datetime, date
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
class DatetimeEncoder(json.JSONEncoder):
|
||||||
|
def default(self, obj):
|
||||||
|
if isinstance(obj, datetime):
|
||||||
|
return obj.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
elif isinstance(obj, date):
|
||||||
|
return obj.strftime('%Y-%m-%d')
|
||||||
|
# Let the base class default method raise the TypeError
|
||||||
|
return json.JSONEncoder.default(self, obj)
|
||||||
|
|
||||||
|
|
||||||
class PyLevel2(object):
|
class PyLevel2(object):
|
||||||
|
@ -17,7 +28,7 @@ class PyLevel2(object):
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.session.headers.update({'content-type': 'application/json'})
|
self.session.headers.update({'content-type': 'application/json'})
|
||||||
|
|
||||||
def events(self, count=None, year=None, month=None):
|
def events(self, count=None, year=None, month=None, json_dump=False):
|
||||||
"""
|
"""
|
||||||
Get the events.
|
Get the events.
|
||||||
"""
|
"""
|
||||||
|
@ -55,12 +66,14 @@ class PyLevel2(object):
|
||||||
else:
|
else:
|
||||||
# invalid query
|
# invalid query
|
||||||
pass
|
pass
|
||||||
|
if json_dump:
|
||||||
|
return json.dumps(to_return, cls=DatetimeEncoder)
|
||||||
return to_return
|
return to_return
|
||||||
else:
|
else:
|
||||||
# Something bad happened
|
# Something bad happened
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def spaceapi(self):
|
def spaceapi(self, json_dump=False):
|
||||||
"""
|
"""
|
||||||
Gives information about Level2.
|
Gives information about Level2.
|
||||||
"""
|
"""
|
||||||
|
@ -73,6 +86,8 @@ class PyLevel2(object):
|
||||||
else:
|
else:
|
||||||
# invalid query
|
# invalid query
|
||||||
pass
|
pass
|
||||||
|
if json_dump:
|
||||||
|
return json.dumps(data, cls=DatetimeEncoder)
|
||||||
return data
|
return data
|
||||||
else:
|
else:
|
||||||
# Something bad happened
|
# Something bad happened
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -4,7 +4,7 @@ from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='pylevel2',
|
name='pylevel2',
|
||||||
version='1.0',
|
version='1.1',
|
||||||
author='Raphaël Vinot',
|
author='Raphaël Vinot',
|
||||||
author_email='raphael.vinot@gmail.com',
|
author_email='raphael.vinot@gmail.com',
|
||||||
maintainer='Raphaël Vinot',
|
maintainer='Raphaël Vinot',
|
||||||
|
|
Loading…
Reference in New Issue