Last active
March 24, 2020 19:55
-
-
Save sathinduga/c11dfe9fb2fc7f85941231175f90d534 to your computer and use it in GitHub Desktop.
Heroku Python Script
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 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