I am trying to test a simple way to write a message from a python script running locally to a file (that may not exist at the time of the script run) that can be hosted in a shared directory (i.e. a dropbox link) and is whose path is specified by a url.
1) Dropbox is just chosen as an example since it is well known and easy. I have been able to retrieve contents from a file that already exists in a shared directory via a dropbox link if I change the last dl = 0 to dl = 1.
Example: (Not using a real link): I have a testfile.txt with a simple message written: 'this is my test file'
import urllib2
#this link would point directly to the shared file location
the_link = 'https://www.dropbox.com/.....blahblah....?dl=1'
response = urllib2.urlopen(the_link)
print response.read()
#print's the message written in the text file
>>: 'this is my test file'
2) What I would like to do is go the other direction - i.e. run my script that prints a message, and then saves this to a url based shared directory (dropbox?), creating the file if necessary.
I would like to avoid using the dropbox API (since I may not end up using dropbox at all in a final solution) and I may end up using a served directory or some other url based resource. The objective is to have the file read/writeable and hosted at a url that can be accessed from anywhere.
Where I am stuck/things I have considered:
1) using os? os.chdir() and getting directory info using the url. Then writing to file using open(filename, w), etc?
2) using urllib2 to make a file? And then write to it?
Any advice is greatly appreciated. Thanks in advance.