Skip to content

Commit

Permalink
thread safe download
Browse files Browse the repository at this point in the history
  • Loading branch information
rking32 committed Feb 12, 2021
1 parent 7b7e7cd commit 00d0b9e
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ covid
cowpy
dnspython
emoji==0.6.0
feedparser
gitpython
google-api-python-client
google-auth-httplib2
Expand Down
3 changes: 1 addition & 2 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ run() {
bash -c "$cmd" $0 "$@" &
setProc $!
waitProc
local code=$?
test $code -eq $usr1 && run "$@"
test $? -eq $usr1 && run "$@"
}

run "$@"
4 changes: 2 additions & 2 deletions userge/plugins/fun/memes.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import requests
from cowpy import cow

from userge import userge, Message
from userge import userge, Message, pool


@userge.on_cmd(r"(?:Kek|:/)$",
Expand Down Expand Up @@ -348,7 +348,7 @@ async def decide_(message: Message):
r = requests.get(f"https://yesno.wtf/api?force={decision}").json()
else:
r = requests.get("https://yesno.wtf/api").json()
path = wget.download(r["image"])
path = await pool.run_in_thread(wget.download)(r["image"])
chat_id = message.chat.id
message_id = message.reply_to_message.message_id if message.reply_to_message else None
await message.delete()
Expand Down
2 changes: 1 addition & 1 deletion userge/plugins/misc/rss_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async def add_rss_feed(msg: Message):

@userge.on_cmd("delfeed", about={
'header': "Delete a existing Feed Url from Database.",
'usage': "{tr}deletefeed title | url"})
'usage': "{tr}delfeed title | url"})
async def delete_rss_feed(msg: Message):
""" Delete to a existing Feed Url """
if not (msg.input_str and '|' in msg.input_str):
Expand Down
3 changes: 2 additions & 1 deletion userge/plugins/misc/utube.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ async def ytinfo(message: Message):
{table}
""".format_map(_exracted)
if _exracted['thumb']:
_tmp = wget.download(_exracted['thumb'], os.path.join(Config.DOWN_PATH, f"{time()}.jpg"))
_tmp = await pool.run_in_thread(wget.download)(
_exracted['thumb'], os.path.join(Config.DOWN_PATH, f"{time()}.jpg"))
await message.reply_photo(_tmp, caption=out)
await message.delete()
os.remove(_tmp)
Expand Down
4 changes: 2 additions & 2 deletions userge/plugins/tools/alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
FileIdInvalid, FileReferenceEmpty, BadRequest, ChannelInvalid, MediaEmpty
)

from userge.core.ext import RawClient
from userge.core.ext import RawClient, pool
from userge.utils import get_file_id_of_media
from userge import userge, Message, Config, versions, get_version, logging

Expand Down Expand Up @@ -179,7 +179,7 @@ def _set_data(errored: bool = False) -> None:
async def _send_telegraph(msg: Message, text: str, reply_markup: Optional[InlineKeyboardMarkup]):
path = os.path.join(Config.DOWN_PATH, os.path.split(Config.ALIVE_MEDIA)[1])
if not os.path.exists(path):
wget.download(Config.ALIVE_MEDIA, path)
await pool.run_in_thread(wget.download)(Config.ALIVE_MEDIA, path)
if path.lower().endswith((".jpg", ".jpeg", ".png", ".bmp")):
await msg.client.send_photo(
chat_id=msg.chat.id,
Expand Down
4 changes: 2 additions & 2 deletions userge/plugins/utils/speedtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import wget
import speedtest
from userge import userge, Message
from userge import userge, Message, pool
from userge.utils import humanbytes

CHANNEL = userge.getCLogger(__name__)
Expand All @@ -30,7 +30,7 @@ async def speedtst(message: Message):
except Exception as e:
await message.err(text=e)
return
path = wget.download(result['share'])
path = await pool.run_in_thread(wget.download)(result['share'])
output = f"""**--Started at {result['timestamp']}--
Client:
Expand Down

0 comments on commit 00d0b9e

Please sign in to comment.