Dennis Posted April 30, 2019 Share Posted April 30, 2019 I threw together a quick script for Python that allows your clients to install mods directly from TCAdmin by inputting a URL. import sys sys.path.append(ThisServer.CustomField1) sys.path.append(ThisServer.CustomField2) import clr; clr.AddReference("TCAdmin.SDK") from TCAdmin.SDK.Misc import WebClient; import bs4 import urllib, urlparse, os wc = WebClient(); site = str(ThisService.Variables['umodurl']) split = urlparse.urlsplit(site) filename = str(ThisService.RootDirectory) + '\oxide\\plugins\\' + split.path.split("/")[-1] if ".cs" in site: wc.DownloadFile(site, filename); Script.WriteToConsole('The plugin was downloaded successfully') else: try: wc = WebClient(); html=wc.DownloadData(site); only_copyurl_tags = bs4.SoupStrainer('a', {"class":"btn btn-primary btn-block"}) soup = bs4.BeautifulSoup(html.encode('utf-8'), 'html.parser', parse_only=only_copyurl_tags) for a in soup.find_all('a', href=True)[0:1]: download_link = a['href'] except: Script.WriteToConsole('Couldn\'t parse URL. Please contact support.') modname = download_link.replace('https://umod.org/plugins/', '') try: with open(str(ThisService.RootDirectory) + '\oxide\\plugins\\' + modname, 'wb') as output: output.write(wc.DownloadData(download_link)) except: Script.WriteToConsole('Failed to download\nfile from ' + download_link + '.\nTrying another URL...') try: os.remove(str(ThisService.RootDirectory) + '\oxide\\plugins\\' + modname) filename = str(ThisService.RootDirectory) + '\oxide\\plugins\\' + split.path.split("/")[-1] +'.cs' wc.DownloadFile(site + '.cs', filename) Script.WriteToConsole('The plugin was downloaded successfully') except: Script.WriteToConsole('Couldn\'t download the plugin.\nPlease contact support') A few things to note: - Install Python 2.7 on your server and go to Servers > Custom Fields. In Custom Field 1, input the path to the Python 2.7 library on your server (like C:\Python27\Lib) - Install BeautifulSoup4 on your server and go to Servers > Custom Fields. In Custom Field 2, input the path to the BeautifulSoup4 library on your server (like C:\beautifulsoup4-4.1.0\) - You need to create a variable called 'umodurl'. To avoid cases where your client enters an incorrect URL, use regex validation like so: ^https\:\/\/umod\.org\/plugins\/[a-zA-Z0-9-#]+(.cs)? - Remember to set the script to ask for variables Clients can both enter the URL for the plugin page (eg. https://umod.org/plugins/absolut-gifts) and for the plugin download (eg. https://umod.org/plugins/AbsolutGifts.cs). In some cases the script will fail when the client enters the link for the plugin page, and in this case the script will try to append '.cs' and see if that works. Link to comment Share on other sites More sharing options...
MrLuke82 Posted May 1, 2019 Share Posted May 1, 2019 getting this: unexpected token 'from' when trying to download plugin with that and other script, any clue? Link to comment Share on other sites More sharing options...
Dennis Posted May 1, 2019 Author Share Posted May 1, 2019 Please send a screenshot of the script in TCAdmin so I can investigate. Link to comment Share on other sites More sharing options...
MrLuke82 Posted May 4, 2019 Share Posted May 4, 2019 okey, should i send it on email or here? Link to comment Share on other sites More sharing options...
MrLuke82 Posted May 4, 2019 Share Posted May 4, 2019 i send to your email, to big to upload it says here Link to comment Share on other sites More sharing options...
MarkMozza Posted May 20, 2020 Share Posted May 20, 2020 I prefere just to link directly to the latest download that way i can setup configuration files etc, i have message support to include an Updater feature, however in the latest update you have to provide a version number, this makes updating a pain, the update button should appear constantly and it just downloads the latest. This method is nice, it just lacks in UI side (being able to manage plugin produce configs in Configuration Files). Link to comment Share on other sites More sharing options...
numpty Posted November 20, 2020 Share Posted November 20, 2020 i am having issue where im gettimg No module named bs4 No module named bs4 i have searched for bs4 on the server and found this location /usr/lib/python2.7/dist-packages/bs4 so i put that into the scrpts and still get the error. any help is appreciated Link to comment Share on other sites More sharing options...
Jimmy-CS Posted November 22, 2020 Share Posted November 22, 2020 On 11/19/2020 at 8:23 PM, numpty said: i am having issue where im gettimg No module named bs4 No module named bs4 i have searched for bs4 on the server and found this location /usr/lib/python2.7/dist-packages/bs4 so i put that into the scrpts and still get the error. any help is appreciated Turn /usr/lib/python2.7/dist-packages/bs4 into /usr/lib/python2.7/dist-packages/ That's what worked for me. Link to comment Share on other sites More sharing options...
Dennis Posted November 24, 2020 Author Share Posted November 24, 2020 Yes, as @Jimmy-CS says, you'll need to enter the path to where you can see the bs4 folder - you shouldn't include /bs4. Link to comment Share on other sites More sharing options...
numpty Posted November 24, 2020 Share Posted November 24, 2020 Yes, as @Jimmy-CS says, you'll need to enter the path to where you can see the bs4 folder - you shouldn't include /bs4.Man my mind was not working last few weeks thanks guys. I feel dumb now. Lol. Sent from my iPhone using Tapatalk Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now