Compare commits
1 Commits
master
...
pagedGVAWa
Author | SHA1 | Date |
---|---|---|
poka | d6937aac93 |
|
@ -1,6 +1,10 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys, re, os.path, json, ast
|
||||
import sys
|
||||
import re, time
|
||||
import os.path
|
||||
import json
|
||||
import ast
|
||||
from termcolor import colored
|
||||
from lib.natools import fmt, sign, get_privkey
|
||||
from gql import gql, Client
|
||||
|
@ -8,8 +12,8 @@ from gql.transport.aiohttp import AIOHTTPTransport
|
|||
|
||||
PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
|
||||
|
||||
class ListWallets:
|
||||
|
||||
class ListWallets:
|
||||
def __init__(self, node, brut, mbr, nonMbr, larf):
|
||||
self.mbr = mbr
|
||||
self.larf = larf
|
||||
|
@ -18,14 +22,14 @@ class ListWallets:
|
|||
# Define Duniter GVA node
|
||||
transport = AIOHTTPTransport(url=node)
|
||||
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
||||
self.count = 0
|
||||
|
||||
def sendDoc(self):
|
||||
def sendDoc(self, jsonBrut=[], cursor=None):
|
||||
# Build wallets generation document
|
||||
|
||||
queryBuild = gql(
|
||||
"""
|
||||
{
|
||||
wallets(pagination: { cursor: null, ord: ASC, pageSize: 0 }) {
|
||||
query ($cursor: String!) { wallets(pagination: { cursor: $cursor, ord: ASC, pageSize: 999 }) {
|
||||
pageInfo {
|
||||
hasNextPage
|
||||
endCursor
|
||||
|
@ -45,32 +49,68 @@ class ListWallets:
|
|||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
"""
|
||||
)
|
||||
paramsBuild = {
|
||||
"cursor": cursor,
|
||||
}
|
||||
|
||||
# Send wallets document
|
||||
try:
|
||||
queryResult = self.client.execute(queryBuild)
|
||||
queryResult = self.client.execute(queryBuild, variable_values=paramsBuild)
|
||||
except Exception as e:
|
||||
sys.stderr.write("Echec de récupération de la liste:\n" + str(e) + "\n")
|
||||
sys.exit(1)
|
||||
|
||||
jsonBrut = queryResult['wallets']['edges']
|
||||
# Merge result
|
||||
jsonBrut.extend(queryResult["wallets"]["edges"])
|
||||
|
||||
# Check pagination
|
||||
endCursor = queryResult["wallets"]["pageInfo"]["endCursor"]
|
||||
hasNextPage = queryResult["wallets"]["pageInfo"]["hasNextPage"]
|
||||
|
||||
if hasNextPage:
|
||||
# print(jsonBrut[-1:][0]["node"]["script"])
|
||||
print(self.count)
|
||||
print(endCursor)
|
||||
print(len(jsonBrut))
|
||||
# print("---")
|
||||
# if self.count % 3 == 1 and self.count != 0:
|
||||
# time.sleep(3)
|
||||
self.count += 1
|
||||
self.sendDoc(jsonBrut, endCursor)
|
||||
else:
|
||||
return self.transformData(jsonBrut)
|
||||
|
||||
def transformData(self, jsonBrut):
|
||||
walletList = []
|
||||
for i, trans in enumerate(jsonBrut):
|
||||
dataWork = trans['node']
|
||||
if (self.mbr and (dataWork['idty'] == None or dataWork['idty']['isMember'] == False)): continue
|
||||
if (self.nonMbr and (dataWork['idty'] == None or dataWork['idty']['isMember'] == True)): continue
|
||||
if (self.larf and (dataWork['idty'] != None)): continue
|
||||
walletList.append({'pubkey': dataWork['script'],'balance': dataWork['balance']['amount']/100,'id': dataWork['idty']})
|
||||
dataWork = trans["node"]
|
||||
if self.mbr and (
|
||||
dataWork["idty"] == None or dataWork["idty"]["isMember"] == False
|
||||
):
|
||||
continue
|
||||
if self.nonMbr and (
|
||||
dataWork["idty"] == None or dataWork["idty"]["isMember"] == True
|
||||
):
|
||||
continue
|
||||
if self.larf and (dataWork["idty"] != None):
|
||||
continue
|
||||
walletList.append(
|
||||
{
|
||||
"pubkey": dataWork["script"],
|
||||
"balance": dataWork["balance"]["amount"] / 100,
|
||||
"id": dataWork["idty"],
|
||||
}
|
||||
)
|
||||
|
||||
if (self.brut):
|
||||
if self.brut:
|
||||
names = []
|
||||
for dataWork in walletList:
|
||||
if (self.mbr or self.nonMbr):
|
||||
names.append(dataWork['pubkey'] + ' ' + dataWork['id']['username'])
|
||||
if self.mbr or self.nonMbr:
|
||||
names.append(dataWork["pubkey"] + " " + dataWork["id"]["username"])
|
||||
else:
|
||||
names.append(dataWork['pubkey'])
|
||||
names.append(dataWork["pubkey"])
|
||||
|
||||
return "\n".join(names)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue