diff --git a/.gitignore b/.gitignore index c6c00bc..204377b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,3 @@ # Byte-compiled Python __pycache__/ *.pyc - -# Poetry venv directories and files -.venv/ -poetry.lock - -# Keys and tokens of the Twitter API -credentials.py diff --git a/README.md b/README.md index 4166caf..f71abec 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,13 @@ -# info_tbm +# What's this? -A twitter bot to know if my tram will arrive soon ⏰ +This is a set of libraries to gather real time data from TBM. + +They all work around [the dynamic map](https://www.infotbm.com/fr/plans/plan-dynamique/). + +## What's TBM? + +TBM is a French public transport company in Bordeaux. + +## Licence + +These libraries are under GNU GPL v3. See [license](LICENSE) for more details. diff --git a/assets/pp.png b/assets/pp.png deleted file mode 100644 index caa46d3..0000000 Binary files a/assets/pp.png and /dev/null differ diff --git a/assets/tram.png b/assets/tram.png deleted file mode 100644 index 5cf21e7..0000000 Binary files a/assets/tram.png and /dev/null differ diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index 76cc75d..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,16 +0,0 @@ -[tool.poetry] -name = "info_tbm" -version = "0.1.0" -description = "" -authors = ["mdeboute "] - -[tool.poetry.dependencies] -python = "^3.9" -gmplot = "^1.4.1" -tweepy = "^4.8.0" - -[tool.poetry.dev-dependencies] - -[build-system] -requires = ["poetry-core>=1.0.0"] -build-backend = "poetry.core.masonry.api" diff --git a/src/autoreply.py b/src/autoreply.py deleted file mode 100644 index 0bfb789..0000000 --- a/src/autoreply.py +++ /dev/null @@ -1,37 +0,0 @@ -import tweepy -from config import * -import time - - -logging.basicConfig(level=logging.INFO) -logger = logging.getLogger() - - -def check_mentions(api, keywords, since_id): - logger.info("Retrieving mentions") - new_since_id = since_id - for tweet in tweepy.Cursor(api.mentions_timeline, since_id=since_id).items(): - new_since_id = max(tweet.id, new_since_id) - if tweet.in_reply_to_status_id is not None: - continue - if any(keyword in tweet.text.lower() for keyword in keywords): - logger.info(f"Answering to {tweet.user.name}") - api.update_status( - status="Please reach us via DM", - in_reply_to_status_id=tweet.id, - auto_populate_reply_metadata=True, - ) - return new_since_id - - -def main(): - api = create_api() - since_id = 1 - while True: - since_id = check_mentions(api, ["help", "support"], since_id) - logger.info("Waiting...") - time.sleep(10) - - -if __name__ == "__main__": - main() diff --git a/src/config.py b/src/config.py deleted file mode 100644 index 3e063dc..0000000 --- a/src/config.py +++ /dev/null @@ -1,19 +0,0 @@ -import tweepy -import logging -from credentials import * - - -logger = logging.getLogger() - - -def create_api(): - auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) - auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) - api = tweepy.API(auth, wait_on_rate_limit=True) - try: - api.verify_credentials() - except Exception as e: - logger.error("Error creating API", exc_info=True) - raise e - logger.info("API created") - return api diff --git a/src/main.py b/src/main.py index 6a3969a..e03f4c4 100644 --- a/src/main.py +++ b/src/main.py @@ -1,7 +1,7 @@ import sys -from tbm_api.stop_area import * -from tbm_api.stop import * -from tbm_api.stop_route import StopRoute +from stop_area import * +from stop import * +from stop_route import StopRoute from datetime import datetime diff --git a/src/tbm_api/route.py b/src/route.py similarity index 100% rename from src/tbm_api/route.py rename to src/route.py diff --git a/src/tbm_api/stop.py b/src/stop.py similarity index 95% rename from src/tbm_api/stop.py rename to src/stop.py index 16102e1..5d96a19 100644 --- a/src/tbm_api/stop.py +++ b/src/stop.py @@ -1,8 +1,8 @@ -from tbm_api.utils import get_data_from_json +from utils import get_data_from_json from urllib.parse import quote -from tbm_api.stop_point import StopPoint +from stop_point import StopPoint from re import search -from tbm_api.route import Route +from route import Route INFO_URL = "https://ws.infotbm.com/ws/1.0/network/stoparea-informations/%s" diff --git a/src/tbm_api/stop_area.py b/src/stop_area.py similarity index 92% rename from src/tbm_api/stop_area.py rename to src/stop_area.py index b1f3479..3dbeb3e 100644 --- a/src/tbm_api/stop_area.py +++ b/src/stop_area.py @@ -1,4 +1,4 @@ -from tbm_api.utils import get_data_from_json +from utils import get_data_from_json from urllib.parse import quote diff --git a/src/tbm_api/stop_point.py b/src/stop_point.py similarity index 100% rename from src/tbm_api/stop_point.py rename to src/stop_point.py diff --git a/src/tbm_api/stop_route.py b/src/stop_route.py similarity index 92% rename from src/tbm_api/stop_route.py rename to src/stop_route.py index 16f4a65..c769a31 100644 --- a/src/tbm_api/stop_route.py +++ b/src/stop_route.py @@ -1,6 +1,6 @@ -from tbm_api.utils import get_data_from_json, hms2seconds +from utils import get_data_from_json, hms2seconds from time import time -from tbm_api.vehicle import Vehicle +from vehicle import Vehicle SCHEDULE_URL = "https://ws.infotbm.com/ws/1.0/get-realtime-pass/%d/%s" @@ -8,7 +8,7 @@ SCHEDULE_URL = "https://ws.infotbm.com/ws/1.0/get-realtime-pass/%d/%s" class Line: """ - Information on the line served at a stop + Information on the line served at a stop. """ def __init__(self, vehicles): @@ -41,7 +41,7 @@ class StopRoute: def update(self, auto=False): """ - Update data + Update data. """ data = get_data_from_json(SCHEDULE_URL % (self.number, self.line)) @@ -80,7 +80,7 @@ class StopRoute: def data_age(self): """ - Returns the age of the data + Returns the age of the data. """ return time() - self.last_update diff --git a/src/tbm_api/utils.py b/src/utils.py similarity index 88% rename from src/tbm_api/utils.py rename to src/utils.py index 94129c9..90314d2 100644 --- a/src/tbm_api/utils.py +++ b/src/utils.py @@ -5,7 +5,7 @@ from urllib.error import HTTPError def get_data_from_json(url): """ - Gets data from json at url + Gets data from json at url. """ opener = request.build_opener() @@ -17,7 +17,7 @@ def get_data_from_json(url): def hms2seconds(hhmmss): """ - Convert H:M:S string to time in seconds + Convert H:M:S string to time in seconds. """ try: diff --git a/src/tbm_api/vcub.py b/src/vcub.py similarity index 69% rename from src/tbm_api/vcub.py rename to src/vcub.py index 855772a..259bddd 100644 --- a/src/tbm_api/vcub.py +++ b/src/vcub.py @@ -1,33 +1,17 @@ """ -Provides all info about V³ stations +Provides all info about V³ stations. """ -from tbm_api.utils import get_data_from_json +from utils import get_data_from_json from time import time + vcub_url = "https://ws.infotbm.com/ws/1.0/vcubs" class Vcub: """ - Retrieves information from V³ stations - - Data format, as returned by the infotbm website: - { - lists: [ - { - 'id': station number, - 'name': str, - 'connexionState': 'CONNECTED' if in service 'DISCONNECTED' otherwise, - 'typeVlsPlus': 'VLS_PLUS' if V³+ 'PAS_VLS_PLUS' otherwise, - 'nbPlaceAvailable': 33, - 'nbBikeAvailable': 0 - 'nbElectricBikeAvailable': 6 - 'latitude': float, - 'longitude': float, - }, - ] - } + Retrieves information from V³ stations. """ def __init__( @@ -49,9 +33,7 @@ class Vcub: def update(self, auto=False, data=None): """ - Updates data - auto optionnal param is to set if a update is a automatic one, - and must be performed as defined in autoupdate_delay variable + Updates data. """ if data is None or type(data) != dict: @@ -77,14 +59,14 @@ class Vcub: def data_age(self): """ - Computes the data's age + Computes the data's age. """ return time() - self.last_update def get_names(self): """ - Returns all names in a dict with id as data + Returns all names in a dict with id as data. """ r = {} @@ -94,7 +76,7 @@ class Vcub: def get_locations(self): """ - Returns all locations in a dict with id as data + Returns all locations in a dict with id as data. """ r = {} @@ -104,7 +86,7 @@ class Vcub: def get_by_id(self, id): """ - Returns a station by its id + Returns a station by its id. """ class Station: diff --git a/src/tbm_api/vehicle.py b/src/vehicle.py similarity index 100% rename from src/tbm_api/vehicle.py rename to src/vehicle.py