2015-07-12 20:36:46 +02:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
import os
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
|
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
def queryFile(file_path, filter_path, filter_key=None, filter_val=None):
|
|
|
|
back = []
|
|
|
|
data = json.load(open(file_path))
|
|
|
|
if filter_path == ['']:
|
|
|
|
return [data]
|
|
|
|
for key in filter_path: # Get to the point
|
|
|
|
data = data.get(key)
|
|
|
|
if not data:
|
|
|
|
return
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
|
2019-01-10 14:09:50 +01:00
|
|
|
if type(data) == list:
|
|
|
|
for row in data:
|
|
|
|
if filter_val: # Filter by value
|
|
|
|
if row[filter_key] == filter_val:
|
|
|
|
back.append(row)
|
|
|
|
else:
|
2015-07-12 20:36:46 +02:00
|
|
|
back.append(row)
|
2019-01-10 14:09:50 +01:00
|
|
|
else:
|
|
|
|
back.append({"value": data})
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
return back
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Find in json files
|
2015-07-12 20:36:46 +02:00
|
|
|
# Return: [{u'body': u'Hello Topic 1!!', 'inner_path': '1KRxE1...beEp6', u'added': 1422740732, u'message_id': 1},...]
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
def query(path_pattern, filter):
|
2015-07-12 20:36:46 +02:00
|
|
|
if "=" in filter: # Filter by value
|
|
|
|
filter_path, filter_val = filter.split("=")
|
|
|
|
filter_path = filter_path.split(".")
|
|
|
|
filter_key = filter_path.pop() # Last element is the key
|
|
|
|
filter_val = int(filter_val)
|
|
|
|
else: # No filter
|
|
|
|
filter_path = filter
|
|
|
|
filter_path = filter_path.split(".")
|
|
|
|
filter_key = None
|
|
|
|
filter_val = None
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
|
2015-07-12 20:36:46 +02:00
|
|
|
if "/*/" in path_pattern: # Wildcard search
|
|
|
|
root_dir, file_pattern = path_pattern.replace("\\", "/").split("/*/")
|
|
|
|
else: # No wildcard
|
|
|
|
root_dir, file_pattern = re.match("(.*)/(.*?)$", path_pattern.replace("\\", "/")).groups()
|
|
|
|
for root, dirs, files in os.walk(root_dir, topdown=False):
|
|
|
|
root = root.replace("\\", "/")
|
|
|
|
inner_path = root.replace(root_dir, "").strip("/")
|
|
|
|
for file_name in files:
|
|
|
|
if file_pattern != file_name:
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
res = queryFile(root + "/" + file_name, filter_path, filter_key, filter_val)
|
|
|
|
if not res:
|
|
|
|
continue
|
|
|
|
except Exception: # Json load error
|
|
|
|
continue
|
|
|
|
for row in res:
|
|
|
|
row["inner_path"] = inner_path
|
|
|
|
yield row
|
version 0.2.0, new lib for bitcoin ecc, dont display or track notify errors, dont reload again within 1 sec, null peer ip fix, signingmoved to ContentManager, content.json include support, content.json multisig ready, content.json proper bitcoincore compatible signing, content.json include permissions, multithreaded publish, publish timeout 60s, no exception on invalid bitcoin address, testcase for new lib, bip32 based persite privatekey generation, multiuser ready, simple json database query command, websocket api fileGet, wrapper loading title stuck bugfix
2015-02-09 02:09:02 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2015-07-12 20:36:46 +02:00
|
|
|
for row in list(query("../../data/12Hw8rTgzrNo4DSh2AkqwPRqDyTticwJyH/data/users/*/data.json", "")):
|
2019-03-15 21:06:59 +01:00
|
|
|
print(row)
|