In [1]:
import json
import pymongo
import subprocess
import os
from collections import defaultdict
from bson import BSON
In [14]:
base_dir = '/home/mohitsharma44/assignments/python_core/'
# Every folder has a Submission attachment(s) subfolder
sub_dir2 = 'Submission_attachment_s_'
dirs = os.listdir(base_dir)
In [15]:
dirs[0][:-1]
Out[15]:
In [16]:
os.listdir(os.path.join(base_dir,dirs[0]))
Out[16]:
In [17]:
# Store output to a variable with whitespaces removed.
#files = subprocess.check_output(['ls', os.path.join(base_dir,dirs[0],sub_dir2)]).rstrip()
files = os.listdir(os.path.join(base_dir,dirs[0],sub_dir2))
In [24]:
all_files = []
all_users = []
for root, dirs, files in os.walk(base_dir):
if files:
for i in files:
if i.endswith('py'):
all_users.append(root.split('/')[5])
all_files.append(os.path.join(root,i))
In [19]:
a = subprocess.Popen(['pylint', all_files[0], '--rcfile=pylintrc.txt','-f', 'json'], stdout=subprocess.PIPE).stdout.read()
In [20]:
j_a = json.loads(a)
In [21]:
d_a = defaultdict(list)
for i in j_a:
for k, v in i.iteritems():
d_a[k].append(v)
d_a['name'].append(all_users[0])
In [22]:
d_a.keys()
Out[22]:
In [1]:
from patoolib import extract_archive
In [ ]:
extract_archive
In [60]:
j_b = json.dumps(d_a, sort_keys=True, indent=4)
In [61]:
j_c = json.loads(j_b)
In [39]:
temp_f = []
for root, dirs, files in os.walk(base_dir):
temp_f.append(files)
In [47]:
In [ ]:
In [ ]:
In [2]:
conn = pymongo.MongoClient()
In [3]:
conn.database_names()
Out[3]:
In [4]:
db = conn.test_1
In [5]:
db.collection_names()
Out[5]:
In [6]:
collection = db.testcollection
In [7]:
collection.count()
Out[7]:
In [34]:
collection.insert(j_c)
Out[34]:
In [35]:
for i in collection.find():
temp_id = i['_id']
In [244]:
collection.remove({'_id':temp_id})
Out[244]:
In [39]:
for i in collection.find({'name':'TestUser'}):
print i['name']
In [13]:
collection.find().sort([{'_id',-1}]).limit(10)
Out[13]:
In [25]:
os.path.join(root,,i)
Out[25]:
In [ ]: