Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Munyal_jsonoe #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 35 additions & 29 deletions Munyal_jsonoe
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
import os
import json
import rethinkdb
import rethinkdb as r
import hashlib
directorio=os.getcwd()
cv=os.listdir(directorio)
def get_json(contenido):
def get_subir(parametro):
try:
r.connect( "localhost", 28015).repl()
#r.db("test").table_create("newcontedo").run()
r.table("newcontedo").insert(parametro).run()
print("insert in rethinkdb")
pass
except Exception as e:
print("Error, EN conexión o Tabla existente")

def get_chck(cont):
BLOCKSIZE = 10000
hasher = hashlib.sha1()
chck=0
with open(cont, 'rb') as afile:
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
hasher.update(buf)
buf = afile.read(BLOCKSIZE)
chck=hasher.hexdigest()
return chck
def get_json(parametro):
data=[]
teminado={}
principal={"contenido"}
contenido=os.listdir(parametro)
for cont in contenido:
name = cont
cont = os.path.join(parametro, cont)
if(os.path.isfile(cont)):
BLOCKSIZE = 10000
hasher = hashlib.sha1()
with open(cont, 'rb') as afile:
buf = afile.read(BLOCKSIZE)
while len(buf) > 0:
hasher.update(buf)
buf = afile.read(BLOCKSIZE)
chck=hasher.hexdigest()
data.append({cont:chck})
chck=get_chck(cont)
data.append({name:chck})
elif(os.path.isdir(cont)):
directorio=os.getcwd()
directorio=os.path.join(directorio, cont)
contenido=os.listdir(directorio)
if contenido:
data.append({cont:contenido})
get_json(contenido)
else:
data.append({cont:contenido})
teminado={"contenido":data}
principal=json.dumps(teminado)
print(principal)


get_json(cv)
contenido_nuevo=get_json(cont)
data.append({name:contenido_nuevo})
return data
directorio=os.getcwd()
jsonend=get_json(directorio)
print(jsonend)
get_subir(jsonend)