I loaded this code to trinket so that anyone can try it in one click, but, I'm testing it and every time I made a fix I have to paste my code to a new trinket link and I have to upload it back to my blog.
To skip this step I thinked about to execute the code directly from the raw link of the script from my Github page.
I tryed severals code but the one that worked in my case was this:
# read the data from the URL and print it
import urllib.request
# open a connection to a URL using urllib
webUrl = urllib.request.urlopen('https://raw.githubusercontent.com/Pymai73/bollettino_covid_giornaliero/main/bollettino_covid.py')
#get the result code and print it
#print ("result code: " + str(webUrl.getcode()))
# read the data from the URL and print it
data = webUrl.read()
exec(data)
You can edit the "exec" with a "print" if you don't want to run the code but you wanna only grab it. Make sure that the source of the code is reliable or preferable writed by you like in my case and remember always that you are executing code from an external source that can be changed from someone so be careful and do it also if your source is really reliable. I found the code above at guru99 website and like you can see I disabled with the # the code that get the confirm that the page have been founded and print it. If you need this confirm you can delete the # and reactivate the print ("result code: " + str(webUrl.getcode()))
If you wanna see the result you can take a look to the trinket frame here. The next time I will upload my code in my github Github page (Pymai73) the trinket frame will execute directly the new code without any manual update.
An alternative way with the urllib.request I founded at stackoverflow to retrieve all the code in a raw file uploaded online was this one:
# read the data from the URL and print it
#
import urllib.request
url = "https://raw.githubusercontent.com/Pymai73/bollettino_covid_giornaliero/main/bollettino_covid.py"
file = urllib.request.urlopen(url)
for line in file:
decoded_line = line.decode("utf-8")
print(decoded_line)
In this case the code will be printed to screen line by line but I haven't find a way to execute It directly because of some errors. I have to analize better the traceback. If someone have some idea how to edit this second code to execute it directly like the first one I will appreciate if you let me know in the comment section below.
This article is property of PC Wizard wroted by Michele (Italy). Please don't copy and paste without mentioning the blog and the author.
If you wanna help me donate here: https://www.paypal.com/donate?business=AUDLXGNQV6FAA&no_recurring=0&item_name=sostegno+del+blog+PC+Wizard¤cy_code=EUR
ore use the QR code:
Nessun commento:
Posta un commento