WIP: fuck GVA antispam, cannot request all paged wallets without whitlist...
https://git.duniter.org/nodes/rust/modules/duniter-gva/-/merge_requests/6
This commit is contained in:
parent
ab50340595
commit
d6937aac93
|
@ -1,6 +1,10 @@
|
||||||
#!/usr/bin/env python3
|
#!/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 termcolor import colored
|
||||||
from lib.natools import fmt, sign, get_privkey
|
from lib.natools import fmt, sign, get_privkey
|
||||||
from gql import gql, Client
|
from gql import gql, Client
|
||||||
|
@ -8,8 +12,8 @@ from gql.transport.aiohttp import AIOHTTPTransport
|
||||||
|
|
||||||
PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
|
PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
|
||||||
|
|
||||||
class ListWallets:
|
|
||||||
|
|
||||||
|
class ListWallets:
|
||||||
def __init__(self, node, brut, mbr, nonMbr, larf):
|
def __init__(self, node, brut, mbr, nonMbr, larf):
|
||||||
self.mbr = mbr
|
self.mbr = mbr
|
||||||
self.larf = larf
|
self.larf = larf
|
||||||
|
@ -18,14 +22,14 @@ class ListWallets:
|
||||||
# Define Duniter GVA node
|
# Define Duniter GVA node
|
||||||
transport = AIOHTTPTransport(url=node)
|
transport = AIOHTTPTransport(url=node)
|
||||||
self.client = Client(transport=transport, fetch_schema_from_transport=True)
|
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
|
# Build wallets generation document
|
||||||
|
|
||||||
queryBuild = gql(
|
queryBuild = gql(
|
||||||
"""
|
"""
|
||||||
{
|
query ($cursor: String!) { wallets(pagination: { cursor: $cursor, ord: ASC, pageSize: 999 }) {
|
||||||
wallets(pagination: { cursor: null, ord: ASC, pageSize: 0 }) {
|
|
||||||
pageInfo {
|
pageInfo {
|
||||||
hasNextPage
|
hasNextPage
|
||||||
endCursor
|
endCursor
|
||||||
|
@ -45,32 +49,68 @@ class ListWallets:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
paramsBuild = {
|
||||||
|
"cursor": cursor,
|
||||||
|
}
|
||||||
|
|
||||||
# Send wallets document
|
# Send wallets document
|
||||||
try:
|
try:
|
||||||
queryResult = self.client.execute(queryBuild)
|
queryResult = self.client.execute(queryBuild, variable_values=paramsBuild)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.stderr.write("Echec de récupération de la liste:\n" + str(e) + "\n")
|
sys.stderr.write("Echec de récupération de la liste:\n" + str(e) + "\n")
|
||||||
sys.exit(1)
|
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 = []
|
walletList = []
|
||||||
for i, trans in enumerate(jsonBrut):
|
for i, trans in enumerate(jsonBrut):
|
||||||
dataWork = trans['node']
|
dataWork = trans["node"]
|
||||||
if (self.mbr and (dataWork['idty'] == None or dataWork['idty']['isMember'] == False)): continue
|
if self.mbr and (
|
||||||
if (self.nonMbr and (dataWork['idty'] == None or dataWork['idty']['isMember'] == True)): continue
|
dataWork["idty"] == None or dataWork["idty"]["isMember"] == False
|
||||||
if (self.larf and (dataWork['idty'] != None)): continue
|
):
|
||||||
walletList.append({'pubkey': dataWork['script'],'balance': dataWork['balance']['amount']/100,'id': dataWork['idty']})
|
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 = []
|
names = []
|
||||||
for dataWork in walletList:
|
for dataWork in walletList:
|
||||||
if (self.mbr or self.nonMbr):
|
if self.mbr or self.nonMbr:
|
||||||
names.append(dataWork['pubkey'] + ' ' + dataWork['id']['username'])
|
names.append(dataWork["pubkey"] + " " + dataWork["id"]["username"])
|
||||||
else:
|
else:
|
||||||
names.append(dataWork['pubkey'])
|
names.append(dataWork["pubkey"])
|
||||||
|
|
||||||
return "\n".join(names)
|
return "\n".join(names)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue