getElementsByName / tmp-doc

0 stars 0 forks source link

python #23

Open getElementsByName opened 3 years ago

getElementsByName commented 3 years ago

zip

from zipfile import ZipFile
import os
from os.path import basename

# Name of the Directory to be zipped
dirName = '/workspace/notebook_dir'

zip_file = '/tmp/pyfile.zip'
# create a ZipFile object
with ZipFile(zip_file, 'w') as zipObj:
    lenDirPath = len(dirName)
    # Iterate over all the files in directory
    for folderName, subfolders, filenames in os.walk(dirName):
        for filename in filenames:
           #create complete filepath of file in directory
           filePath = os.path.join(folderName, filename)
           # Add file to zip
           zipObj.write(filePath,  filePath[lenDirPath :] )
getElementsByName commented 3 years ago

pymongo

from pymongo import MongoClient
import time

user_pwd = 'username:password'

client = MongoClient(
    f'mongodb://{user_pwd}@---:27017/?readPreference=secondaryPreferred&authSource=admin'
)

db = client.myplace_abuse

start = time.time()

result = db.place.find({
    'place_id': 00000
}).limit(100)

# result = db.review.find({
#     'idno': "---"
# }).limit(100)

doc_list = [doc for doc in result]

print(doc_list)

end = time.time()
print(f'time: {end - start}')