This repository has been archived by the owner on Sep 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 917
Add Weather module #31
Open
AyraHikari
wants to merge
5
commits into
PaulSonOfLars:master
Choose a base branch
from
AyraHikari:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ sqlalchemy | |
python-telegram-bot>=10.1.0 | ||
psycopg2-binary | ||
feedparser | ||
pyowm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pyowm | ||
from pyowm import timeutils, exceptions | ||
from telegram import Message, Chat, Update, Bot | ||
from telegram.ext import run_async | ||
|
||
from tg_bot import dispatcher, updater, API_WEATHER | ||
from tg_bot.modules.disable import DisableAbleCommandHandler | ||
|
||
@run_async | ||
def weather(bot, update, args): | ||
if len(args) == 0: | ||
update.effective_message.reply_text("Write a location to check the weather.") | ||
return | ||
|
||
location = " ".join(args) | ||
if location.lower() == bot.first_name.lower(): | ||
update.effective_message.reply_text("I will keep an eye on both happy and sad times!") | ||
bot.send_sticker(update.effective_chat.id, BAN_STICKER) | ||
return | ||
|
||
try: | ||
owm = pyowm.OWM(API_WEATHER) | ||
observation = owm.weather_at_place(location) | ||
getloc = observation.get_location() | ||
thelocation = getloc.get_name() | ||
if thelocation == None: | ||
thelocation = "Unknown" | ||
theweather = observation.get_weather() | ||
temperature = theweather.get_temperature(unit='celsius').get('temp') | ||
if temperature == None: | ||
temperature = "Unknown" | ||
|
||
status = theweather._detailed_status | ||
|
||
update.message.reply_text("Today in {} is being {}, around {}°C.\n".format(thelocation, | ||
status, temperature)) | ||
|
||
except pyowm.exceptions.not_found_error.NotFoundError: | ||
update.effective_message.reply_text("Sorry, location not found.") | ||
|
||
|
||
__help__ = """ | ||
- /weather <city>: get weather info in a particular place | ||
""" | ||
|
||
__mod_name__ = "Weather" | ||
|
||
WEATHER_HANDLER = DisableAbleCommandHandler("weather", weather, pass_args=True) | ||
|
||
dispatcher.add_handler(WEATHER_HANDLER) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ class Config(object): | |
SQLALCHEMY_DATABASE_URI = 'sqldbtype://username:pw@hostname:port/db_name' # needed for any database modules | ||
MESSAGE_DUMP = None # needed to make sure 'save from' messages persist | ||
LOAD = [] | ||
NO_LOAD = ['translation', 'rss'] | ||
NO_LOAD = ['translation', 'rss', 'weather'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
WEBHOOK = False | ||
URL = None | ||
|
||
|
@@ -34,6 +34,7 @@ class Config(object): | |
WORKERS = 8 # Number of subthreads to use. This is the recommended amount - see for yourself what works best! | ||
BAN_STICKER = 'CAADAgADOwADPPEcAXkko5EB3YGYAg' # banhammer marie sticker | ||
ALLOW_EXCL = False # Allow ! commands as well as / | ||
API_OPENWEATHER = None # OpenWeather API | ||
|
||
|
||
class Production(Config): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If len(args) == 0:
inform user to give a location and then return