I suspect this is a very newbie question but I can't find any solutions that are helping :( I've been trying to get started with Python by building a simple Twitter bot which replies to people who tweet at it. It worked locally, and it doesn't work on Heroku.
A quick rundown: Each time the bot tweets, it uses a script called mainscript.py which writes the ID of the last tweet replied to into a separate file called lastid.py. The next time the script runs, it opens lastid.py, checks the number inside against the current list of tweets, and only responds to those with a larger ID number than the one stored in lastid.py.
fp = open("lastid.py", 'r')
last_id_replied = fp.read()
fp.close()
#(snipped - the bot selects the tweet and sends it here...)
fp = open("lastid.py", 'w')
fp.write(str(status.id))
fp.close()
This works great locally. Runs fine. However, when I upload it to Heroku I get this error:
Traceback (most recent call last):
File "/app/workspace/mainscript.py", line 60, in <module>
fp = open("lastid.py", 'r')
IOError: [Errno 2] No such file or directory: u'lastid.py'
I am absolutely 100% positive lastid.py and mainscript.py are on the server and inside the same directory - I have triple-checked this by running bash on heroku. My .gitignore file is blank so it isn't anything to do with that.
I don't understand why such a simple command as 'open a file in the same directory and read it' doesn't work on the server. What on earth have I done wrong?
(I realise I should have worked through some tutorials before trying to build something custom in a new language, but now I've started this I'd really love to finish it - any help anyone can offer would be very much appreciated.)