Skip to content

Instantly share code, notes, and snippets.

@SathinduGA
Last active March 24, 2020 19:55
Show Gist options
  • Save SathinduGA/c11dfe9fb2fc7f85941231175f90d534 to your computer and use it in GitHub Desktop.
Save SathinduGA/c11dfe9fb2fc7f85941231175f90d534 to your computer and use it in GitHub Desktop.
Heroku Python Script
import datetime
import pymongo
client = pymongo.MongoClient("mongodb://<user>:<password>@<host>:<port>/<db_namespace>")
def save_data_to_mongo(data):
db = client["<db_namespace>"]
collection = db["test_data"]
response = collection.insert_one(data)
if __name__ == "__main__":
date_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
data = {}
data["text"] = "Hello World"
data["date_time"] = date_time
save_data_to_mongo(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment