Use a new SQLite db every week
This commit is contained in:
parent
97f92221dc
commit
1772cf0321
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,6 @@
|
||||
__pycache__
|
||||
config.py
|
||||
*.db
|
||||
*.sql
|
||||
*.pyc
|
||||
data/
|
||||
|
9
LICENSE
Normal file
9
LICENSE
Normal file
@ -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.
|
10
README.md
10
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.
|
||||
|
13
velib.py
13
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(" +
|
||||
|
Loading…
Reference in New Issue
Block a user