Skip to content

Commit 0cfb955

Browse files
committed
Fix caching problems with DiviaVélodi API + bump version n° to 2.3
1 parent fc58ba5 commit 0cfb955

3 files changed

Lines changed: 17 additions & 4 deletions

File tree

divia_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
__author__ = 'Firmin Launay'
2626
__license__ = 'LGPL-3.0'
2727
__copyright__ = 'divia_api Copyright (C) 2021 Firmin Launay'
28-
__version__ = '2.2'
28+
__version__ = '2.3'
2929

3030
from .api import DiviaAPI

divia_api/velodi.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def __init__(self, code: str, raw_name: str, friendly_name: str):
5050
self.raw_name = raw_name
5151
self.friendly_name = friendly_name
5252

53-
def check(self):
53+
def check_cached(self): # Checking method used in previous versions, that is signficantly faster but did not really provide realtime results because of caching issues.
54+
"""This may not be realtime data !!!!"""
5455
velodi_data = update_source()
5556
query_result = list(item for item in velodi_data if (item["infos"]["code_cykleo"] == self.code))
5657
try:
@@ -59,6 +60,18 @@ def check(self):
5960
except IndexError:
6061
raise Exception("Data not found.")
6162

63+
def check(self):
64+
velodi_data = update_source()
65+
query_result = list(item for item in velodi_data if (item["infos"]["code_cykleo"] == self.code))
66+
try:
67+
response = get("https://www.divia.fr" + query_result[0]["url"]).content.decode("utf-8")
68+
response = response.split("<span class=\"uk-indicateur-value\">")
69+
free_bikes = int(response[1].split("</span>")[0])
70+
free_docks = int(response[2].split("</span>")[0])
71+
return FreeVelodi(self, free_bikes, free_docks)
72+
except IndexError:
73+
raise Exception("Data not found.")
74+
6275

6376
class Velodi:
6477
def __init__(self):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
setup(
3232
name='divia_api',
3333
packages=['divia_api'],
34-
version='2.2',
34+
version='2.3',
3535
license='LGPL-3.0',
3636
description='divia_api is a Python library that allows to retrieve the timetable of Divia’s bus and tramways, along with some infos about DiviaVélodi bikes, straight from a Python script.',
3737
long_description=long_description,
3838
long_description_content_type='text/markdown',
3939
author='Firmin Launay',
4040
author_email='hey@firminlaunay.me',
4141
url='https://github.com/filau/python_divia_api',
42-
download_url='https://github.com/filau/python_divia_api/archive/refs/tags/2.2.tar.gz',
42+
download_url='https://github.com/filau/python_divia_api/archive/refs/tags/2.3.tar.gz',
4343
keywords=['divia', 'api', 'firmin', 'launay', 'dijon', 'bus', 'tram'],
4444
install_requires=[
4545
'requests'

0 commit comments

Comments
 (0)