Browse Source

Use a new SQLite db every week

Phyks (Lucas Verney) 3 years ago
parent
commit
1772cf0321
4 changed files with 32 additions and 2 deletions
  1. 2
    0
      .gitignore
  2. 9
    0
      LICENSE
  3. 9
    1
      README.md
  4. 12
    1
      velib.py

+ 2
- 0
.gitignore View File

@@ -1,4 +1,6 @@
1 1
 __pycache__
2 2
 config.py
3 3
 *.db
4
+*.sql
4 5
 *.pyc
6
+data/

+ 9
- 0
LICENSE View File

@@ -0,0 +1,9 @@
1
+The MIT License (MIT)
2
+
3
+Copyright (c) 2017 Phyks (Lucas Verney)
4
+
5
+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:
6
+
7
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+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.

+ 9
- 1
README.md View File

@@ -1,7 +1,9 @@
1 1
 VelibDataSet
2 2
 ============
3 3
 
4
-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).
4
+This code can be used to dump periodically all the available data from the
5
+Velib API, the bike sharing system in Paris. The data are under an OpenData
6
+license.
5 7
 
6 8
 ## Usage
7 9
 
@@ -14,3 +16,9 @@ This code can be used to dump periodically all the available data from the Velib
14 16
 
15 17
 * Velib API: https://developer.jcdecaux.com/#/home
16 18
 * Velib website: http://velib.paris/
19
+
20
+## License
21
+
22
+Data is under [an Open Data license](https://developer.jcdecaux.com/#/opendata/license).
23
+
24
+Code is released under MIT license.

+ 12
- 1
velib.py View File

@@ -1,8 +1,10 @@
1 1
 #!/usr/bin/env python3
2 2
 from config import *
3 3
 
4
+import datetime
4 5
 import json
5 6
 import requests
7
+import os
6 8
 import sqlite3
7 9
 import sys
8 10
 import time
@@ -14,7 +16,16 @@ def db_init():
14 16
 
15 17
     Returns a new connection.
16 18
     """
17
-    conn = sqlite3.connect("data.db")
19
+    now = datetime.datetime.now()
20
+    db_name = "week_%s.db" % now.strftime("%V")
21
+    db_folder = os.path.join(
22
+        'data',
23
+        now.strftime('%Y')
24
+    )
25
+    if not os.path.isdir(db_folder):
26
+        os.makedirs(db_folder)
27
+
28
+    conn = sqlite3.connect(os.path.join(db_folder, db_name))
18 29
     c = conn.cursor()
19 30
     # Init tables
20 31
     c.execute("CREATE TABLE IF NOT EXISTS stations(" +