From 60dbc99fbedeb35b0d9d30159aef5c4b61c50fa3 Mon Sep 17 00:00:00 2001 From: Pawel Skalny Date: Sun, 26 Apr 2020 13:03:39 +0200 Subject: [PATCH] Refactoring --- getdata.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/getdata.py b/getdata.py index 7efba6e..bfdc3b2 100644 --- a/getdata.py +++ b/getdata.py @@ -2,8 +2,8 @@ import json import sys -if len(sys.argv) < 3: - print("Provide MongoDB connection parameters -> hostAddress port") +if len(sys.argv) < 5: + print("Provide MongoDB connection parameters -> hostAddress port databaseName collectionName") sys.exit() try: @@ -24,9 +24,8 @@ def __init__(self, host='localhost', port=27017, database_name=None, collection_ if collection_name: self._collection = self._database[collection_name] - def clean(self, collection_name=None): - if collection_name is not None: - self._collection.remove({}) + def clean(self): + self._collection.remove({}) def insert(self, post): post_id = self._collection.insert_one(post).inserted_id @@ -87,10 +86,10 @@ def insert(self, post): print("Done!") print('[*] Peparing client form MongoDB ') -mongodbClient = MongoDBClient(host=sys.argv[1], port=int(sys.argv[2]), database_name='KasjopejaDB', collection_name=w) +mongodbClient = MongoDBClient(host=sys.argv[1], port=int(sys.argv[2]), database_name=sys.argv[3], collection_name=sys.argv[4]) -print('[!] Clearing old data from collection: ', w) -mongodbClient.clean(w) +print('[!] Clearing old data from collection: ', sys.argv[4]) +mongodbClient.clean() for i, collection in enumerate(subjectForCourse): print("[!] Inserting - %.2f%s done" % (i/len(subjectForCourse)*100, "%"))