diff --git a/.gitignore b/.gitignore index 882beab..b7fde93 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ __pycache__ config.py *.db +*.sql *.pyc +data/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..e2c5465 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2017 Phyks (Lucas Verney) + +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. diff --git a/README.md b/README.md index 99e1c3d..3c17753 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ VelibDataSet ============ -This code can be used to dump periodically all the available data from the Velib API. These data are under an OpenData license. (Velib is a bike sharing system in Paris). +This code can be used to dump periodically all the available data from the +Velib API, the bike sharing system in Paris. The data are under an OpenData +license. ## Usage @@ -14,3 +16,9 @@ This code can be used to dump periodically all the available data from the Velib * Velib API: https://developer.jcdecaux.com/#/home * Velib website: http://velib.paris/ + +## License + +Data is under [an Open Data license](https://developer.jcdecaux.com/#/opendata/license). + +Code is released under MIT license. diff --git a/velib.py b/velib.py index c9e2dd5..d8e80f5 100755 --- a/velib.py +++ b/velib.py @@ -1,8 +1,10 @@ #!/usr/bin/env python3 from config import * +import datetime import json import requests +import os import sqlite3 import sys import time @@ -14,7 +16,16 @@ def db_init(): Returns a new connection. """ - conn = sqlite3.connect("data.db") + now = datetime.datetime.now() + db_name = "week_%s.db" % now.strftime("%V") + db_folder = os.path.join( + 'data', + now.strftime('%Y') + ) + if not os.path.isdir(db_folder): + os.makedirs(db_folder) + + conn = sqlite3.connect(os.path.join(db_folder, db_name)) c = conn.cursor() # Init tables c.execute("CREATE TABLE IF NOT EXISTS stations(" +