I'm storing tweets into a CSV, when I run the following code in Jupyter Notebook it'll save to tweets.csv successfully.
with open(fName, 'a') as f:
while True:
try:
if (max_id <= 0):
# to the beginning of twitter time
if (not sinceId):
results = api.search(q=query, count=tweetCount)
# go to last tweet we downloaded
else:
results = api.search(q=query, since_id=sinceId, count=tweetCount)
# if max_id > 0
else:
# results from beginning of twitter time to max_id
if (not sinceId):
results = api.search(q=query, max_id=str(max_id - 1), count=tweetCount)
# results from since_id to max_id
else:
results = api.search(q=searchQuery, count=tweetCount,
max_id=str(max_id - 1),
since_id=sinceId)
if not results:
print("No more tweets found")
break
for result in results:
tweets_DF = pd.DataFrame({"text": [x.text for x in results]},
index =[x.id for x in results])
tweets_DF.name = 'Tweets'
tweets_DF.index.name = "ID"
tweets_DF.to_csv(f, header=False)
tweetCount += len(results)
print("Downloaded {0} tweets".format(tweetCount))
max_id = results[-1].id
except (KeyboardInterrupt, SystemExit):
print ("Downloaded {0} tweets, Saved to {1}".format(tweetCount, os.path.abspath(fName)))
quit()
except tweepy.TweepError as e:
print("Error : " + str(e))
break
When run in a Docker container and issued a Keyboard Interrupt it returns
Downloaded 520 tweets, Saved to /app/tweets.csv
but nothing is saved.
How do I get the script to write out in the container, also what is happening under the hood here?
Edit:
Commands Run:
docker build -t dock .
docker run dock
Here's the Dockerfile:
# Use an official Python runtime as a parent image
FROM python:3.6-slim
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
ADD . /app
# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["python", "app.py"]
enter code here