Created
August 19, 2020 22:06
-
-
Save MemphisMeng/974314bc9a05afbd8f9b52a167f8d74b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from pymongo import MongoClient | |
# define on heroku settings tab | |
MONGODB_URI = os.environ['MONGODB_URI'] | |
cluster = MongoClient(MONGODB_URI) | |
db = cluster['QnA'] | |
collection = db['QnA'] | |
def insert(message, response): | |
# EST | |
time = (datetime.fromtimestamp(int(str(message['timestamp'])[:-3])) - timedelta(hours=4)).strftime( | |
'%Y-%m-%d %H:%M:%S') | |
collection.insert_one({"question": message['message'].get('text'), | |
"answer": response, 'time': time, 'source':'Facebook Messenger'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment