0

I am trying to create a program in Python that needs to read and write to a file that is hosted online on my website. I know how to read a text file that is online, but what are some possible ways that I can write to the same file, without the use of databases. Any possible methods will be appreciated!

Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

1

NO SERVER NEEDED , EASY TO EDIT AND READ

There is a method i am using which uses an online service http://freetexthost.com

so you can make a text with an admin password which will allow you to edit it later

function for editing text

import mechanize
br=mechanize.Browser()
response = br.open(url)
try:
    br.set_all_readonly(False)
except:
    pass
# url example http://freetexthost.com/xyz124
def edit(text,pas,url): # text you want to add/replace, admin password , url 
     response = br.open(url)
    try:
        br.set_all_readonly(False)
    except:
        pass
    br.select_form("editform")
    control = br.form.find_control("adminpass")
    control.value=pas
    response = br.submit()
    br.select_form("editform")
    control = br.form.find_control("text")
    control.value=text
    response = br.submit()

to read text

def read(url):
    response = br.open(url)
    txt=response.read()
    t1=re.findall(r'<div id="contentsinner">(.*?)<div style="clear: both;"><!-- --></div>',txt,re.DOTALL)
    t1=t1[0]
    t1=t1.strip()
    return t1
Rohan Arora
  • 303
  • 2
  • 12
0

Have you tried using SSH? Here is a primer for writing to a remote file

In Python, how to write a string to a file on a remote machine?

Cheers

Community
  • 1
  • 1
humanbeing
  • 1,617
  • 3
  • 17
  • 30