Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
DevilWillReign authored Apr 26, 2020
1 parent bc5397f commit 60dbc99
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions getdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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, "%"))
Expand Down

0 comments on commit 60dbc99

Please sign in to comment.