Skip to content

Commit

Permalink
Fix wttr.in png generation
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki0iq committed Mar 9, 2024
1 parent 1d7df8d commit dc29a08
Show file tree
Hide file tree
Showing 4 changed files with 946 additions and 3 deletions.
10 changes: 7 additions & 3 deletions handlers/commands/wttr_in.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import utils.regex
import utils.str
import utils.locale
import utils.wttrin_png
import alterpy.context
import typing
import aiohttp
import asyncio
import json


Expand Down Expand Up @@ -54,7 +56,8 @@ async def weather(cm: utils.cm.CommandMessage) -> None:
await cm.int_cur.reply(LOC.obj('wait', cm.lang))

words = ' '.join(cm.arg.split()).lower()
other_dic = {True: cm.arg} | dict([(words.startswith(w), words[len(w):]) for w in LOC.obj('in', cm.lang)]) | dict([(words.startswith(w), '~' + words[len(w):]) for w in LOC.obj('near', cm.lang)])
other_dic = {True: cm.arg} | dict([(words.startswith(w), words[len(w):]) for w in LOC.obj('in', cm.lang)]) | dict([
(words.startswith(w), '~' + words[len(w):]) for w in LOC.obj('near', cm.lang)])

arg = other_dic[True]
argp = arg.strip().replace(' ', '+')
Expand All @@ -68,8 +71,9 @@ async def weather(cm: utils.cm.CommandMessage) -> None:
await cm.int_cur.reply(LOC.obj('err', cm.lang))
return

async with alterpy.context.session.get(f'https://v2.wttr.in/{argp}_lang={cm.lang}.png') as v2:
data_v2 = await v2.read()
# async with alterpy.context.session.get(f'https://v2.wttr.in/{argp}_lang={cm.lang}') as v2:
# data_v2 = await v2.read()
data_v2 = utils.wttrin_png.render_ansi(data_v1.decode('utf-8'))

await cm.int_cur.reply(' '.join([LOC.obj('weather', cm.lang), utils.str.escape(cm.arg)]), data_v2)
except asyncio.TimeoutError:
Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ aiodns
Brotli
lemminflect
git-up
pyte
emoji
grapheme
Loading

0 comments on commit dc29a08

Please sign in to comment.