Here is the code i tried:
Syntax: Select all
import os, urllib, shutil
from paths import GAME_PATH
from urllib import request
from commands.say import SayCommand
@SayCommand('download')
def download_command(command, index, team_only):
args = command.arg_string
if args:
download_map(args)
return False
def download_map(url):
try:
urllib.request.urlretrieve(url, "maps_file.rar")
shutil.move(os.getcwd() + '/maps_file.rar', GAME_PATH.joinpath('maps_file.rar'))
with open(GAME_PATH + '/maps_file.rar', 'rb') as open_file:
for i in open_file.readlines():
if i.lower().endswith('.bsp') or i.lower().endswith('.nav'):
shutil.move(GAME_PATH.joinpath(i), GAME_PATH + '/maps')
except urllib.error.URLError:
print('An error appeared')
Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\packages\source-python\commands\auth.py", line 44, in __call__
return self.callback(*args)
File "..\addons\source-python\plugins\test\test.py", line 10, in download_command
download_map(args)
File "..\addons\source-python\plugins\test\test.py", line 20, in download_map
if i.lower().endswith('.bsp') or i.lower().endswith('.nav'):
TypeError: endswith first arg must be bytes or a tuple of bytes, not str