Created
December 8, 2013 11:30
-
-
Save shinriyo/7856207 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 sys | |
import hashlib | |
from datetime import datetime | |
from pymongo import Connection | |
from pymongo.errors import ConnectionFailure | |
def main(): | |
try: | |
c = Connection(host="localhost", port=27017) | |
except(ConnectionFailure, e): | |
sys.stderr.write("Could not connect to MongoDB: %s" % e) | |
sys.exit(1) | |
secret_key = 'mySecretKey' | |
name = 'shinriyo' | |
score = '10' | |
dbh = c["mydb"] | |
real_hash = hashlib.md5(bytes(name + score + secret_key, "utf-8")).digest() | |
assert dbh.connection == c | |
user_doc = { | |
"name" : name, | |
"score" : score | |
} | |
dbh.users.insert(user_doc, safe=True) | |
print("Successfully inserted document: %s" % user_doc) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment