wikipedia

is this needed? who knows its meshing about!
This commit is contained in:
SpudGunMan
2024-08-28 23:10:36 -07:00
parent 9f0d3c9d3b
commit 76a7d1dba7
6 changed files with 34 additions and 1 deletions
+2
View File
@@ -36,6 +36,7 @@ Full list of commands for the bot.
- `wx` and `wxc` returns local weather forecast, (wxc is metric value), NOAA or Open Meteo for weather forecasting.
- `wxa` and `wxalert` return NOAA alerts. Short title or expanded details
- `joke` tells a joke
- `wiki:` search wikipedia, return the first few sentances of first result if a match
- `messages` Replay the last messages heard, like Store and Forward
- `motd` or to set the message `motd $New Message Of the day`
- `lheard` returns the last 5 heard nodes with SNR, can also use `sitrep`
@@ -186,6 +187,7 @@ pip install beautifulsoup4
pip install dadjokes
pip install geopy
pip install schedule
pip install wikipedia
```
The following is needed for open-meteo use
```
+2
View File
@@ -34,6 +34,8 @@ welcome_message = MeshBot, here for you like a friend who is not. Try sending: p
DadJokes = True
# enable or disable the Solar module
spaceWeather = True
# enable or disable the wikipedia search module
wikipedia = True
# StoreForward Enabled and Limits
StoreForward = True
StoreLimit = 3
+9
View File
@@ -22,6 +22,7 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi
"wxa": lambda: handle_wxalert(message_from_id, deviceID, message),
"wxc": lambda: handle_wxc(message_from_id, deviceID, 'wxc'),
"wx": lambda: handle_wxc(message_from_id, deviceID, 'wx'),
"wiki:": lambda: handle_wiki(message),
"joke": tell_joke,
"bbslist": bbs_list_messages,
"bbspost": lambda: handle_bbspost(message, message_from_id, deviceID),
@@ -93,6 +94,14 @@ def handle_wxalert(message_from_id, deviceID, message):
return weatherAlert
def handle_wiki(message):
if "wiki:" in message.lower():
search = message.split(":")[1]
search = search.rstrip()
return get_wikipedia_summary(search)
else:
return "Please add a search term example:wiki: travelling gnome"
def handle_wxc(message_from_id, deviceID, cmd):
location = get_node_location(message_from_id, deviceID)
if use_meteo_wxApi and not "wxc" in cmd and not use_metric:
+3 -1
View File
@@ -25,6 +25,7 @@ max_retry_count2 = 4 # max retry count for interface 2
retry_int1 = False
retry_int2 = False
scheduler_enabled = False # enable the scheduler currently config via code only
wiki_return_limit = 3 # limit the number of sentences returned off the first paragraph first hit
# Read the config file, if it does not exist, create basic config file
config = configparser.ConfigParser()
@@ -93,7 +94,8 @@ try:
welcome_message = (f"{welcome_message}").replace('\\n', '\n') # allow for newlines in the welcome message
motd_enabled = config['general'].getboolean('motdEnabled', True)
dad_jokes_enabled = config['general'].getboolean('DadJokes', True)
solar_conditions_enabled = config['general'].getboolean('spaceWeather', True)
solar_conditions_enabled = config['general'].getboolean('spaceWeather', True)
wikipedia_enabled = config['general'].getboolean('wikipedia', True)
sentry_enabled = config['sentry'].getboolean('SentryEnabled', False) # default False
secure_channel = config['sentry'].getint('SentryChannel', 2) # default 2
+16
View File
@@ -64,6 +64,12 @@ if dad_jokes_enabled:
trap_list = trap_list + ("joke",)
help_message = help_message + ", joke"
# Wikipedia Search Configuration
if wikipedia_enabled:
import wikipedia # pip install wikipedia
trap_list = trap_list + ("wiki:",)
help_message = help_message + ", wiki:"
# Scheduled Broadcast Configuration
if scheduler_enabled:
import schedule # pip install schedule
@@ -483,6 +489,16 @@ def tell_joke():
else:
return ''
def get_wikipedia_summary(search_term):
# search wikipedia for a summary of the search term
try:
logger.debug(f"System: Searching Wikipedia for:{search_term}")
summary = wikipedia.summary(search_term, sentences=wiki_return_limit)
return summary
except Exception as e:
logger.warning(f"System: Error searching Wikipedia:{e}")
return ERROR_FETCHING_DATA
def messageTrap(msg):
# Check if the message contains a trap word
message_list=msg.split(" ")
+2
View File
@@ -12,3 +12,5 @@ retry_requests
numpy
geopy
schedule
wikipedia