better stats-managing, clock functionality.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import requests
|
||||
# import api.keys
|
||||
import datetime
|
||||
|
||||
class WeatherFetch():
|
||||
@@ -59,3 +58,25 @@ class WeatherFetch():
|
||||
ret_weather = self.last_weather
|
||||
|
||||
return ret_weather
|
||||
|
||||
# def get_weather_by_city(self, city):
|
||||
# loc = get_coords_from_city(self, city)
|
||||
# weather = self.show_weather(loc)
|
||||
# return weather
|
||||
|
||||
|
||||
# def get_coords_from_city(self, city):
|
||||
# url = "https://devru-latitude-longitude-find-v1.p.rapidapi.com/latlon.php"
|
||||
# data = {"location": city}
|
||||
# headers = {
|
||||
# "x-rapidapi-key" : "d4e0ab7ab3mshd5dde5a282649e0p11fd98jsnc93afd98e3aa",
|
||||
# "x-rapidapi-host" : "devru-latitude-longitude-find-v1.p.rapidapi.com",
|
||||
# }
|
||||
|
||||
# #try:
|
||||
# resp = requests.request("GET", url, headers=headers, params=data)
|
||||
# result = resp.text
|
||||
# #except:
|
||||
# # result = "???"
|
||||
# return result
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
from .template import *
|
||||
import time
|
||||
import numpy
|
||||
from PIL import Image
|
||||
import io
|
||||
|
||||
CHOOSE, ADDARG = range(2)
|
||||
MESSAGE, WAKE, ALARM, IMAGE, ART = range(3,8)
|
||||
@@ -59,7 +61,7 @@ class Clock(BotFunc):
|
||||
query.answer()
|
||||
|
||||
query.edit_message_text("Ok. How long should it blink? (In seconds)")
|
||||
self.next_state = {"ALARM" : "What frequency (Hertz)"}
|
||||
self.next_state = {ALARM : "What frequency (Hertz)"}
|
||||
return ADDARG
|
||||
|
||||
def show_message(self, update: Update, context: CallbackContext) -> None:
|
||||
@@ -74,7 +76,7 @@ class Clock(BotFunc):
|
||||
query.answer()
|
||||
|
||||
query.edit_message_text("How long (in minutes) should the image be displayed?")
|
||||
self.next_state = {"IMAGE" : "Please send me the photo to display."}
|
||||
self.next_state = {IMAGE : "Please send me the photo to display."}
|
||||
return ADDARG
|
||||
|
||||
def art_gallery(self, update: Update, context: CallbackContext) -> None:
|
||||
@@ -98,7 +100,7 @@ class Clock(BotFunc):
|
||||
duration = update.message.text
|
||||
|
||||
def output(duration):
|
||||
self.clock.set_brightness(value=0.1)
|
||||
self.clock.set_brightness(value=1)
|
||||
start_color = numpy.array([153, 0, 51])
|
||||
end_color = numpy.array([255, 255, 0])
|
||||
empty = numpy.zeros((16,32))
|
||||
@@ -137,19 +139,37 @@ class Clock(BotFunc):
|
||||
if not(duration == 0 or frequency == 0):
|
||||
update.message.reply_text("Now blinking")
|
||||
self.clock.run(output,(duration, frequency))
|
||||
print("DOOONE")
|
||||
return ConversationHandler.END
|
||||
|
||||
|
||||
|
||||
def exec_show_image(self, update: Update, context: CallbackContext) -> None:
|
||||
duration = self.additional_argument
|
||||
img = update.message.photo
|
||||
i = update.message.photo
|
||||
img = update.message.photo[0]
|
||||
bot = img.bot
|
||||
id = img.file_id
|
||||
|
||||
file = bot.getFile(id).download_as_bytearray()
|
||||
width = self.clock.IO.width
|
||||
height = self.clock.IO.height
|
||||
|
||||
img = Image.open(io.BytesIO(file))
|
||||
im_height = img.height
|
||||
im_width = img.width
|
||||
|
||||
scalex = im_width // width
|
||||
scaley = im_height // height
|
||||
scale = min(scalex, scaley)
|
||||
|
||||
t = img.resize((width, height),box=(0,0,width*scale,height*scale))
|
||||
a = numpy.asarray(t)
|
||||
|
||||
def output(image, duration):
|
||||
self.clock.IO.set_matrix_rgb([100,0,0])
|
||||
self.clock.IO.set_matrix(image)
|
||||
time.sleep(int(duration) * 60)
|
||||
|
||||
self.clock.run(output,("image", duration))
|
||||
self.clock.run(output,(a, duration))
|
||||
return ConversationHandler.END
|
||||
|
||||
|
||||
|
@@ -26,7 +26,7 @@ class Help(BotFunc):
|
||||
# ]
|
||||
},
|
||||
fallbacks=[CommandHandler('help', self.entry_point)],
|
||||
# conversation_timeout=5,
|
||||
conversation_timeout=15,
|
||||
)
|
||||
return conv_handler
|
||||
|
||||
@@ -92,10 +92,11 @@ class Help(BotFunc):
|
||||
|
||||
query.edit_message_text(
|
||||
text= message,
|
||||
#reply_markup = reply_markup,
|
||||
reply_markup = reply_markup,
|
||||
parse_mode = ParseMode.MARKDOWN_V2
|
||||
)
|
||||
return ConversationHandler.END #EXECUTE
|
||||
return EXECUTE
|
||||
|
||||
|
||||
def execute_now(self, update: Update, context: CallbackContext) -> None:
|
||||
query = update.callback_query
|
||||
@@ -105,9 +106,10 @@ class Help(BotFunc):
|
||||
for func in funcs:
|
||||
if name == func.entry_points[0].command[0]:
|
||||
break
|
||||
callback = func.entry_points[0].callback
|
||||
func.callback(update, context)
|
||||
return FIRST
|
||||
callback = func.entry_points[0].handle_update
|
||||
callback(update, context.dispatcher, check_result=True, context=context)
|
||||
return ConversationHandler.END
|
||||
|
||||
|
||||
def timeout(self, update: Update, context: CallbackContext) -> None:
|
||||
"""For dying conversation. Currently unused."""
|
||||
|
@@ -40,7 +40,7 @@ class Search(BotFunc):
|
||||
# formating
|
||||
self.results = results
|
||||
first = results[0]
|
||||
message = first["text"] + "\n(" + first["url"] + ")\n"
|
||||
message = first["text"] + "\n(" + first["url"] + ")\n\n"
|
||||
|
||||
update.message.reply_text(text = message, reply_markup=reply_markup)
|
||||
return MORE
|
||||
@@ -52,7 +52,7 @@ class Search(BotFunc):
|
||||
|
||||
message = ""
|
||||
for r in self.results:
|
||||
message += r["text"] + "\n(" + r["url"] + ")\n"
|
||||
message += r["text"] + "\n(" + r["url"] + ")\n\n"
|
||||
|
||||
query.edit_message_text(message)
|
||||
return ConversationHandler.END
|
Reference in New Issue
Block a user