cool!
This commit is contained in:
parent
0eedc2a638
commit
b69be7c05e
|
@ -4,4 +4,7 @@ __pycache__/
|
|||
|
||||
# Poetry venv directories and files
|
||||
.venv/
|
||||
poetry.lock
|
||||
poetry.lock
|
||||
|
||||
# Keys and tokens of the Twitter API
|
||||
credentials.py
|
||||
|
|
12
README.md
12
README.md
|
@ -1,11 +1 @@
|
|||
# What's this?
|
||||
|
||||
This is a set of libraries to gather data from TBM.
|
||||
|
||||
## What's TBM?
|
||||
|
||||
TBM is a french compagny that operates Bordeaux's public transportation.
|
||||
|
||||
## Licence
|
||||
|
||||
These libraries are under GNU GPL v3. See [license](LICENSE) for more details.
|
||||
# info_tbm
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 76 KiB |
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
27
main.py
27
main.py
|
@ -1,27 +0,0 @@
|
|||
from src.stop import *
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from gmplot import gmplot
|
||||
|
||||
if __name__ == "__main__":
|
||||
for word in sys.argv[1:]:
|
||||
for area in search_stop_by_name(word):
|
||||
for stop in show_stops_from_ref(area["ref"])["stop_points"]:
|
||||
for route in stop["routes"]:
|
||||
if "Tram" in route["line_human"]:
|
||||
sr = StopRoute(stop["id"], route["line_id"])
|
||||
line = sr.get_line()
|
||||
v = line.get_vehicle(0)
|
||||
if v.is_realtime:
|
||||
print(
|
||||
str(v.wait_time_text)
|
||||
+ " ("
|
||||
+ datetime.fromtimestamp(v.arrival).strftime("%H:%M")
|
||||
+ ") → "
|
||||
+ v.destination
|
||||
+ " "
|
||||
+ str(v.location)
|
||||
)
|
||||
gmap = gmplot.GoogleMapPlotter(v.location[0], v.location[1], 13)
|
||||
gmap.marker(v.location[0], v.location[1], "cornflowerblue")
|
||||
gmap.draw("map.html")
|
31
map.html
31
map.html
|
@ -1,31 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||||
<title>Google Maps - gmplot</title>
|
||||
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=visualization"></script>
|
||||
<script type="text/javascript">
|
||||
function initialize() {
|
||||
var map = new google.maps.Map(document.getElementById("map_canvas"), {
|
||||
zoom: 13,
|
||||
center: new google.maps.LatLng(44.828156, -0.574932)
|
||||
});
|
||||
|
||||
var marker_icon_6495ED = {
|
||||
url: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAiCAYAAACwaJKDAAAABmJLR0QA/wD/AP+gvaeTAAADFUlEQVRIia2VW0gUYRiGn91lrGwj0qCsbS9qpZN5UaFlUQmF1IUURN0FkVFeSEQgdBcZBN10hEqipLoxjKjoXG5ZFh6y8tBKanmazLRd0t1Wx935u3AG121tx9X35me+/32f4eP//hkT/9dyYD0wHzADKiADb4CGKNl/tBmoBIQ1wSbsKVnCkbZL2FOyhDXBJgCh7W+OFDZFeD6JyZS/aOUOU+qWPBJtK8A02varo5baZ+dpqbkjEOIUcFR70T9QE3Bammo9lLm3EHtKVtR22use4yw6wNCA9yxwWAdbQjyHLNKUY1vzbjN/8caoQICZcxwkJWfQUl2yRqhBD1ARCp0H3E3bfkxauGqHIaAu6ywbUlw8na7SDUAR0G/W9nKtCQvil2/aPy6grmUbc5iRaI8HcmF4TACyk9N3Y7ZIMUHNFglH+m6AbB1qAZYkJa+LCagryZEBsASwmAEJiJs+yzYhqJaPAyTzSFmMYTeqkbwZUADF6+6YEFLLK4Ci32dXV1P5hKBa3gWoevv3miqKUQNKTEA1OERTRTHAPRgZqYs+j+ytd16KCdrgvIzPI3uBizByo7xAf1fzu21zHWuZkWg3DPzR/JayG3kINXgEKA2FAlQKNZjQ+vF+um1pJvEz50YF9nbU8ujCTgLKn3PAcb1uCfM9UQNKcnv90xWLVu9EmmodEzjoc/PgTDYD3t5bQE7onjnMK4CcP79/1JXdzAMx9uyWF+fj88hfgH2EDXk4FMAP7On8/CLQXF0SESg3vuLr+zsA+xk+j1GKBAX4CFyqultAMDAY1oug+v4JgBKgLFJ4LChAgc8j+5srb40qdjWV09NaIwg5mPFAfwLXG15eGVV0vb4Gw6NTFwsUoNAt1+OWh//Gir+PtrpHAFf/F4oGrQG+tH16CECnq5Tg0KAf7TrGCgV4IDe+BEB2OQGcRDjx8UKdPW0fUAOK/iV6Hi1gBFoVDAzS/a2Kvt5WgHcGMobUk5J5UAABYNpkQatmL0gVQIsRs5H2AXq11tsmE+pW/H0A/ZMJ7dbW75MJ7dLWViPmv887IG8sMF4/AAAAAElFTkSuQmCC",
|
||||
labelOrigin: new google.maps.Point(10, 11)
|
||||
};
|
||||
|
||||
new google.maps.Marker({
|
||||
position: new google.maps.LatLng(44.828156, -0.574932),
|
||||
icon: marker_icon_6495ED,
|
||||
map: map
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body style="margin:0px; padding:0px;" onload="initialize()">
|
||||
<div id="map_canvas" style="width: 100%; height: 100%;" />
|
||||
</body>
|
||||
</html>
|
|
@ -7,6 +7,7 @@ authors = ["mdeboute <martin.deboute@gmail.com>"]
|
|||
[tool.poetry.dependencies]
|
||||
python = "^3.9"
|
||||
gmplot = "^1.4.1"
|
||||
tweepy = "^4.8.0"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
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()
|
|
@ -0,0 +1,19 @@
|
|||
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
|
|
@ -0,0 +1,43 @@
|
|||
from tbm_api_lib.stop import *
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from gmplot import gmplot
|
||||
|
||||
if __name__ == "__main__":
|
||||
for word in sys.argv[1:]:
|
||||
for area in search_stop_by_name(word):
|
||||
for stop in show_stops_from_ref(area["ref"])["stop_points"]:
|
||||
for route in stop["routes"]:
|
||||
if "Tram" in route["line_human"]:
|
||||
sr = StopRoute(stop["id"], route["line_id"])
|
||||
line = sr.get_line()
|
||||
for vehicule in line.vehicles():
|
||||
v = line.get_vehicle(vehicule)
|
||||
if v.is_realtime:
|
||||
print(
|
||||
str(v.wait_time_text)
|
||||
+ " ("
|
||||
+ datetime.fromtimestamp(v.arrival).strftime(
|
||||
"%H:%M"
|
||||
)
|
||||
+ ") → "
|
||||
+ v.destination
|
||||
+ " "
|
||||
+ str(v.location)
|
||||
)
|
||||
else:
|
||||
print(
|
||||
"~"
|
||||
+ str(v.wait_time_text)
|
||||
+ " ("
|
||||
+ datetime.fromtimestamp(v.arrival).strftime(
|
||||
"%H:%M"
|
||||
)
|
||||
+ ") → "
|
||||
+ v.destination
|
||||
+ " "
|
||||
+ str(v.location)
|
||||
)
|
||||
# gmap = gmplot.GoogleMapPlotter(v.location[0], v.location[1], 13)
|
||||
# gmap.marker(v.location[0], v.location[1], "cornflowerblue")
|
||||
# gmap.draw("map.html")
|
|
@ -2,7 +2,7 @@
|
|||
Provides stop information
|
||||
"""
|
||||
|
||||
from src.libs import get_data_from_json, hms2seconds
|
||||
from tbm_api_lib.libs import get_data_from_json, hms2seconds
|
||||
from time import time
|
||||
from urllib.parse import quote
|
||||
from re import search
|
|
@ -2,7 +2,7 @@
|
|||
Provides all info about V³ stations
|
||||
"""
|
||||
|
||||
from src.libs import get_data_from_json
|
||||
from tbm_api_lib.libs import get_data_from_json
|
||||
from time import time
|
||||
|
||||
vcub_url = "https://ws.infotbm.com/ws/1.0/vcubs"
|
Loading…
Reference in New Issue