Forums

Reading a csv file from own PC

Hello I've managed to get an app running on here, which essentially just reads a csv file that I have uploaded into my files (eg / home/username etc). However, this file is updated daily with new info. Is it possible for my script to read this file automatically off of my own laptop where it is updated everyday and saved, or from my dropbox files, instead of me having to upload it on here everyday? If not, are there any suggestions for how to easily do this elsewhere? Thanks!

Sure! You could write a scheduled task that would run daily on PythonAnywhere, and that could use the Dropbox API to download the file into your file storage here.

Ok great. There wouldn't be a simple tutorial for how to do this anywhere, would there? :)

This example looks like it would be a good one. One thing -- before you run through it, it's probably a good idea to make sure you have the most recent version of the Dropbox API installed for your account. Just run

pip3.5 install --user --upgrade dropbox

...replacing 3.5 with the version of Python you're using, before you follow that example.

Thanks @Giles. On that last bit - I can't seem to do the dropbox upgrade. Is this correct to run in the bash console? : 'pip2.7 install warrenfitzhenry upgrade dropbox' It's giving me all sorts of errors! Thanks

Don't forget the "--user" flag!

OK. I've made an attempt at a scheduled task to copy a file from my dropbox into my files here once a day. This works on my home laptop (from dropbox-> desktop folder). This is the code, and below it is the error message on the schedule task log that I am getting. I upgraded the dropbox as described above. Any suggestions?

import sys
import dropbox
from dropbox.files import WriteMode
from dropbox.exceptions import ApiError, AuthError

TOKEN = 'my_token'

pyanywherelocalfile = '/home/myusername/ishack/client_db.csv'
mydboxfile = '/client_db.csv'

def restore(rev=None):
    dbx.files_download_to_file(pyanywherelocalfile, mydboxfile, rev)


if __name__ == '__main__':
    # Check for an access token
    dbx = dropbox.Dropbox(TOKEN)
    if (len(TOKEN) == 0):
        sys.exit("ERROR")
    restore()

error log:

warrenfitzhenry: unable to open X server `' @ error/import.c/ImportImageCommand/368.
warrenfitzhenry: unable to open X server `' @ error/import.c/ImportImageCommand/368.
from: can't read /var/mail/dropbox.files
from: can't read /var/mail/dropbox.exceptions
/home/warrenfitzhenry/ishack/schedules/schedule1: line 6: TOKEN: command not found
/home/warrenfitzhenry/ishack/schedules/schedule1: line 9: pyanywherelocalfile: command not found
/home/warrenfitzhenry/ishack/schedules/schedule1: line 10: mydboxfile: command not found
/home/warrenfitzhenry/ishack/schedules/schedule1: line 12: syntax error near unexpected token `('
/home/warrenfitzhenry/ishack/schedules/schedule1: line 12: `def restore(rev=None):'

2016-11-21 06:58:11 -- Completed task, took 1.00 seconds, return code was 2.

what is the command that you have in the scheduled task?

Sounds almost like it is running the file as a bash/shell script instead of as a python file.

Try using a hashbang or explicitly say python3.5 /my/script.py?

Thanks. The problem was that I didn't save it as a python file (.py). Scheduled task ran successfully!