Skip to content

Instantly share code, notes, and snippets.

@monk1337
Created April 22, 2018 06:59
Show Gist options
  • Save monk1337/146ef56c6455db13d5442c7df9224e78 to your computer and use it in GitHub Desktop.
Save monk1337/146ef56c6455db13d5442c7df9224e78 to your computer and use it in GitHub Desktop.
import hashlib
import csv
import csv
import random
from pymongo import MongoClient
data_base={}
with open('data.csv','r') as f:
reader=csv.reader(f)
next(reader, None)
for line in reader:
id_uni = int(hashlib.md5(line[0].encode('utf-8')).hexdigest(), 16)
data_base[str(id_uni)]=line[0]
client = MongoClient()
client = MongoClient('mongodb://localhost:27017/')
db = client.test_database
db = client['test_databse']
entities = db.entities
post_id = entities.insert_one(data_base).inserted_id
def random_sentence():
random_sen=random.choice(list(entities.find_one().keys()))
entities.delete_one({random_sen: entities.find_one().get(random_sen)})
return [random_sen,entities.find_one().get(random_sen)]
print(random_sentence())
print(entities.find_one())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment