How Can I Retrieve a Python Script From GitHub

AngusAU293

I have this Python program and it should retrive the contents of a Python script I have stored in GitHub and then write it to a text document but instead it does nothing.

I've looked at other content on StackOverflow plus, I did some research on the internet but nothing worked.

And that is stuff like:

import requests
from os import getcwd

url = "https://raw.githubusercontent.com/AngusAU293/Installer-Test-Files/main/Hello.txt"
directory = getcwd()
filename = directory + 'Hello.txt'
r = requests.get(url)

f = open(filename,'w')
f.write(r.content)
RASFI

When you are trying to open the file with open function you are using the directory variable but you didn't concatenate it with the filename 'Hello.txt'. Also, you need to close the file after you write the content to it.

This code works fine for me

import requests
from os import getcwd

url = "https://raw.githubusercontent.com/AngusAU293/Installer-Test-Files/main/Hello.txt"
directory = getcwd()
filename = directory + '/Hello.txt'
r = requests.get(url)

with open(filename,'w') as f:
    f.write(r.content.decode())

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I run a Python script from Ubuntu Dash?

How can I run a python script from within Flask

How can I store and retrieve objects from Google Apps Script Project Properties?

How can I retrieve my GitHub comments

How do I retrieve individual video URLs from a playlist, using youtube-dl within a python script?

How can I retrieve objects from back4app using python 3?

How can I run a Python 3 script with imports from a subfolder?

Can I retrieve a variable from a express function into a script of a pug template?

How to retrieve the values from the database with column name using python script?

How can I commit changes to GitHub from within a R script?

how can i exit from a running windows program by a python script?

How Can I Run a Streamlit App from within a Python Script?

How can I create stored procedure from within Python script?

How can I Install a theme from Github

How can I install a library from github?

how can I restart the computer from python script and make the script automatically continue from where it stopped?

How can I get the username from a python script run with pkexec?

How can I retrieve values from the database from a specific users?

How can I retrieve data from a page?

How can I retrieve the value from an enum?

How can I send "user input" to python script from another python script (or php execute)?

How to retrieve global var values from a script using selenium (python)

How can I run 3 functions in python from a different script?

How can I load in constants from a python file to a bash script?

How can I add a project from Github to Github without the commits?

How can I send a value from a python script to another script?

How can I transfer data from NodeJS to Python script

How can I retrieve the latest donation information in real-time from Streamlabs API using Python?

How can I retrieve "TSV SCHOTT Mainz" from HTML using Python