Skip to content

Instantly share code, notes, and snippets.

@MemphisMeng
Created August 19, 2020 22:06
Show Gist options
  • Save MemphisMeng/974314bc9a05afbd8f9b52a167f8d74b to your computer and use it in GitHub Desktop.
Save MemphisMeng/974314bc9a05afbd8f9b52a167f8d74b to your computer and use it in GitHub Desktop.
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