cool!
This commit is contained in:
37
src/autoreply.py
Normal file
37
src/autoreply.py
Normal file
@@ -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()
|
||||
19
src/config.py
Normal file
19
src/config.py
Normal file
@@ -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
|
||||
43
src/main.py
Normal file
43
src/main.py
Normal file
@@ -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"
|
||||
Reference in New Issue
Block a user