Merge branch 'refactoGeolocProfiles'
This commit is contained in:
commit
b1049bd7b7
348
jaklis.py
348
jaklis.py
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import argparse, sys, os, getpass, string, random
|
||||
import argparse, sys, os, string, random
|
||||
from os.path import join, dirname
|
||||
from shutil import copyfile
|
||||
from dotenv import load_dotenv
|
||||
|
@ -8,147 +8,249 @@ from duniterpy.key import SigningKey
|
|||
|
||||
__version__ = "0.0.5"
|
||||
|
||||
MY_PATH = os.path.realpath(sys.argv[0]).replace('jaklis.py','')
|
||||
MY_PATH = os.path.realpath(sys.argv[0]).replace("jaklis.py", "")
|
||||
|
||||
# Get variables environment
|
||||
if not os.path.isfile(MY_PATH + '.env'):
|
||||
copyfile(MY_PATH + ".env.template",MY_PATH + ".env")
|
||||
dotenv_path = join(dirname(__file__),MY_PATH + '.env')
|
||||
if not os.path.isfile(MY_PATH + ".env"):
|
||||
copyfile(MY_PATH + ".env.template", MY_PATH + ".env")
|
||||
dotenv_path = join(dirname(__file__), MY_PATH + ".env")
|
||||
load_dotenv(dotenv_path)
|
||||
|
||||
# Set global values (default parameters) , regarding variables environments
|
||||
node = os.getenv('DUNITER') + '/gva'
|
||||
node = os.getenv("DUNITER") + "/gva"
|
||||
if not node:
|
||||
node="https://g1v1.p2p.legal/gva"
|
||||
node = "https://g1v1.p2p.legal/gva"
|
||||
|
||||
pod = os.getenv('ESNODE')
|
||||
pod = os.getenv("ESNODE")
|
||||
if not pod:
|
||||
pod="https://g1.data.e-is.pro"
|
||||
pod = "https://g1.data.e-is.pro"
|
||||
|
||||
destPubkey = False
|
||||
|
||||
# Parse arguments
|
||||
parser = argparse.ArgumentParser(description="Client CLI pour Cesium+ et Ḡchange", epilog="current node: '" + node + "', current pod: '" + pod + "'.")
|
||||
parser.add_argument('-v', '--version', action='store_true', help="Affiche la version actuelle du programme")
|
||||
parser.add_argument('-k', '--key', help="Chemin vers mon trousseau de clé (PubSec)")
|
||||
parser.add_argument('-n', '--node', help="Adresse du noeud Cesium+, Gchange ou Duniter à utiliser")
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Client CLI pour Cesium+ et Ḡchange",
|
||||
epilog="current node: '" + node + "', current pod: '" + pod + "'.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-v",
|
||||
"--version",
|
||||
action="store_true",
|
||||
help="Affiche la version actuelle du programme",
|
||||
)
|
||||
parser.add_argument("-k", "--key", help="Chemin vers mon trousseau de clé (PubSec)")
|
||||
parser.add_argument(
|
||||
"-n", "--node", help="Adresse du noeud Cesium+, Gchange ou Duniter à utiliser"
|
||||
)
|
||||
|
||||
subparsers = parser.add_subparsers(title="Commandes de jaklis", dest="cmd")
|
||||
read_cmd = subparsers.add_parser('read', help="Lecture des messages")
|
||||
send_cmd = subparsers.add_parser('send', help="Envoi d'un message")
|
||||
delete_cmd = subparsers.add_parser('delete', help="Supression d'un message")
|
||||
getProfile_cmd = subparsers.add_parser('get', help="Voir un profile Cesium+")
|
||||
getPage_cmd = subparsers.add_parser('page', help="Voir une page Cesium+")
|
||||
setProfile_cmd = subparsers.add_parser('set', help="Configurer son profile Cesium+")
|
||||
eraseProfile_cmd = subparsers.add_parser('erase', help="Effacer son profile Cesium+")
|
||||
stars_cmd = subparsers.add_parser('stars', help="Voir les étoiles d'un profile / Noter un profile (option -s NOTE)")
|
||||
unstars_cmd = subparsers.add_parser('unstars', help="Supprimer un star")
|
||||
getoffer_cmd = subparsers.add_parser('getoffer', help="Obtenir les informations d'une annonce gchange")
|
||||
setoffer_cmd = subparsers.add_parser('setoffer', help="Créer une annonce gchange")
|
||||
deleteoffer_cmd = subparsers.add_parser('deleteoffer', help="Supprimer une annonce gchange")
|
||||
pay_cmd = subparsers.add_parser('pay', help="Payer en Ḡ1")
|
||||
history_cmd = subparsers.add_parser('history', help="Voir l'historique des transactions d'un compte Ḡ1")
|
||||
balance_cmd = subparsers.add_parser('balance', help="Voir le solde d'un compte Ḡ1")
|
||||
id_cmd = subparsers.add_parser('id', help="Voir l'identité d'une clé publique/username")
|
||||
id_balance_cmd = subparsers.add_parser('idBalance', help="Voir l'identité d'une clé publique/username et son solde")
|
||||
currentUd = subparsers.add_parser('currentUd', help="Affiche la montant actuel du dividende Universel")
|
||||
listWallets = subparsers.add_parser('listWallets', help="Liste de toutes les portefeuilles G1")
|
||||
read_cmd = subparsers.add_parser("read", help="Lecture des messages")
|
||||
send_cmd = subparsers.add_parser("send", help="Envoi d'un message")
|
||||
delete_cmd = subparsers.add_parser("delete", help="Supression d'un message")
|
||||
getProfile_cmd = subparsers.add_parser("get", help="Voir un profile Cesium+")
|
||||
getPage_cmd = subparsers.add_parser("page", help="Voir une page Cesium+")
|
||||
setProfile_cmd = subparsers.add_parser("set", help="Configurer son profile Cesium+")
|
||||
eraseProfile_cmd = subparsers.add_parser("erase", help="Effacer son profile Cesium+")
|
||||
stars_cmd = subparsers.add_parser(
|
||||
"stars", help="Voir les étoiles d'un profile / Noter un profile (option -s NOTE)"
|
||||
)
|
||||
unstars_cmd = subparsers.add_parser("unstars", help="Supprimer un star")
|
||||
getoffer_cmd = subparsers.add_parser(
|
||||
"getoffer", help="Obtenir les informations d'une annonce gchange"
|
||||
)
|
||||
setoffer_cmd = subparsers.add_parser("setoffer", help="Créer une annonce gchange")
|
||||
deleteoffer_cmd = subparsers.add_parser(
|
||||
"deleteoffer", help="Supprimer une annonce gchange"
|
||||
)
|
||||
pay_cmd = subparsers.add_parser("pay", help="Payer en Ḡ1")
|
||||
history_cmd = subparsers.add_parser(
|
||||
"history", help="Voir l'historique des transactions d'un compte Ḡ1"
|
||||
)
|
||||
balance_cmd = subparsers.add_parser("balance", help="Voir le solde d'un compte Ḡ1")
|
||||
id_cmd = subparsers.add_parser("id", help="Voir l'identité d'une clé publique/username")
|
||||
id_balance_cmd = subparsers.add_parser(
|
||||
"idBalance", help="Voir l'identité d'une clé publique/username et son solde"
|
||||
)
|
||||
currentUd = subparsers.add_parser(
|
||||
"currentUd", help="Affiche la montant actuel du dividende Universel"
|
||||
)
|
||||
listWallets = subparsers.add_parser(
|
||||
"listWallets", help="Liste de toutes les portefeuilles G1"
|
||||
)
|
||||
geolocProfiles = subparsers.add_parser(
|
||||
"geolocProfiles", help="Obtenir le JSON de tous les comptes géolocalisés"
|
||||
)
|
||||
|
||||
# Messages management
|
||||
read_cmd.add_argument('-n', '--number',type=int, default=3, help="Affiche les NUMBER derniers messages")
|
||||
read_cmd.add_argument('-j', '--json', action='store_true', help="Sort au format JSON")
|
||||
read_cmd.add_argument('-o', '--outbox', action='store_true', help="Lit les messages envoyés")
|
||||
read_cmd.add_argument(
|
||||
"-n", "--number", type=int, default=3, help="Affiche les NUMBER derniers messages"
|
||||
)
|
||||
read_cmd.add_argument("-j", "--json", action="store_true", help="Sort au format JSON")
|
||||
read_cmd.add_argument(
|
||||
"-o", "--outbox", action="store_true", help="Lit les messages envoyés"
|
||||
)
|
||||
|
||||
send_cmd.add_argument('-d', '--destinataire', required=True, help="Destinataire du message")
|
||||
send_cmd.add_argument('-t', '--titre', help="Titre du message à envoyer")
|
||||
send_cmd.add_argument('-m', '--message', help="Message à envoyer")
|
||||
send_cmd.add_argument('-f', '--fichier', help="Envoyer le message contenu dans le fichier 'FICHIER'")
|
||||
send_cmd.add_argument('-o', '--outbox', action='store_true', help="Envoi le message sur la boite d'envoi")
|
||||
send_cmd.add_argument(
|
||||
"-d", "--destinataire", required=True, help="Destinataire du message"
|
||||
)
|
||||
send_cmd.add_argument("-t", "--titre", help="Titre du message à envoyer")
|
||||
send_cmd.add_argument("-m", "--message", help="Message à envoyer")
|
||||
send_cmd.add_argument(
|
||||
"-f", "--fichier", help="Envoyer le message contenu dans le fichier 'FICHIER'"
|
||||
)
|
||||
send_cmd.add_argument(
|
||||
"-o", "--outbox", action="store_true", help="Envoi le message sur la boite d'envoi"
|
||||
)
|
||||
|
||||
delete_cmd.add_argument('-i', '--id', action='append', nargs='+', required=True, help="ID(s) du/des message(s) à supprimer")
|
||||
delete_cmd.add_argument('-o', '--outbox', action='store_true', help="Suppression d'un message envoyé")
|
||||
delete_cmd.add_argument(
|
||||
"-i",
|
||||
"--id",
|
||||
action="append",
|
||||
nargs="+",
|
||||
required=True,
|
||||
help="ID(s) du/des message(s) à supprimer",
|
||||
)
|
||||
delete_cmd.add_argument(
|
||||
"-o", "--outbox", action="store_true", help="Suppression d'un message envoyé"
|
||||
)
|
||||
|
||||
# Profiles management
|
||||
setProfile_cmd.add_argument('-n', '--name', help="Nom du profile")
|
||||
setProfile_cmd.add_argument('-d', '--description', help="Description du profile")
|
||||
setProfile_cmd.add_argument('-v', '--ville', help="Ville du profile")
|
||||
setProfile_cmd.add_argument('-a', '--adresse', help="Adresse du profile")
|
||||
setProfile_cmd.add_argument('-pos', '--position', nargs=2, help="Points géographiques (lat + lon)")
|
||||
setProfile_cmd.add_argument('-s', '--site', help="Site web du profile")
|
||||
setProfile_cmd.add_argument('-A', '--avatar', help="Chemin vers mon avatar en PNG")
|
||||
setProfile_cmd.add_argument("-n", "--name", help="Nom du profile")
|
||||
setProfile_cmd.add_argument("-d", "--description", help="Description du profile")
|
||||
setProfile_cmd.add_argument("-v", "--ville", help="Ville du profile")
|
||||
setProfile_cmd.add_argument("-a", "--adresse", help="Adresse du profile")
|
||||
setProfile_cmd.add_argument(
|
||||
"-pos", "--position", nargs=2, help="Points géographiques (lat + lon)"
|
||||
)
|
||||
setProfile_cmd.add_argument("-s", "--site", help="Site web du profile")
|
||||
setProfile_cmd.add_argument("-A", "--avatar", help="Chemin vers mon avatar en PNG")
|
||||
|
||||
getProfile_cmd.add_argument('-p', '--profile', help="Nom du profile")
|
||||
getProfile_cmd.add_argument('-a', '--avatar', action='store_true', help="Récupérer également l'avatar au format raw base64")
|
||||
getProfile_cmd.add_argument("-p", "--profile", help="Nom du profile")
|
||||
getProfile_cmd.add_argument(
|
||||
"-a",
|
||||
"--avatar",
|
||||
action="store_true",
|
||||
help="Récupérer également l'avatar au format raw base64",
|
||||
)
|
||||
|
||||
getPage_cmd.add_argument('-p', '--page', help="Nom de la page")
|
||||
getPage_cmd.add_argument('-a', '--avatar', action='store_true', help="Récupérer également l'avatar au format raw base64")
|
||||
getPage_cmd.add_argument("-p", "--page", help="Nom de la page")
|
||||
getPage_cmd.add_argument(
|
||||
"-a",
|
||||
"--avatar",
|
||||
action="store_true",
|
||||
help="Récupérer également l'avatar au format raw base64",
|
||||
)
|
||||
|
||||
# Likes management
|
||||
stars_cmd.add_argument('-p', '--profile', help="Profile cible")
|
||||
stars_cmd.add_argument('-n', '--number', type=int, help="Nombre d'étoile")
|
||||
unstars_cmd.add_argument('-p', '--profile', help="Profile à dénoter")
|
||||
stars_cmd.add_argument("-p", "--profile", help="Profile cible")
|
||||
stars_cmd.add_argument("-n", "--number", type=int, help="Nombre d'étoile")
|
||||
unstars_cmd.add_argument("-p", "--profile", help="Profile à dénoter")
|
||||
|
||||
# Offers management
|
||||
getoffer_cmd.add_argument('-i', '--id', help="Annonce cible à récupérer")
|
||||
setoffer_cmd.add_argument('-t', '--title', help="Titre de l'annonce à créer")
|
||||
setoffer_cmd.add_argument('-d', '--description', help="Description de l'annonce à créer")
|
||||
setoffer_cmd.add_argument('-c', '--category', help="Categorie de l'annonce à créer")
|
||||
setoffer_cmd.add_argument('-l', '--localisation', nargs=2, help="Localisation de l'annonce à créer (lat + lon)")
|
||||
setoffer_cmd.add_argument('-p', '--picture', help="Image de l'annonce à créer")
|
||||
setoffer_cmd.add_argument('-ci', '--city', help="Ville de l'annonce à créer")
|
||||
setoffer_cmd.add_argument('-pr', '--price', help="Prix de l'annonce à créer")
|
||||
deleteoffer_cmd.add_argument('-i', '--id', help="Annonce cible à supprimer")
|
||||
getoffer_cmd.add_argument("-i", "--id", help="Annonce cible à récupérer")
|
||||
setoffer_cmd.add_argument("-t", "--title", help="Titre de l'annonce à créer")
|
||||
setoffer_cmd.add_argument(
|
||||
"-d", "--description", help="Description de l'annonce à créer"
|
||||
)
|
||||
setoffer_cmd.add_argument("-c", "--category", help="Categorie de l'annonce à créer")
|
||||
setoffer_cmd.add_argument(
|
||||
"-l",
|
||||
"--localisation",
|
||||
nargs=2,
|
||||
help="Localisation de l'annonce à créer (lat + lon)",
|
||||
)
|
||||
setoffer_cmd.add_argument("-p", "--picture", help="Image de l'annonce à créer")
|
||||
setoffer_cmd.add_argument("-ci", "--city", help="Ville de l'annonce à créer")
|
||||
setoffer_cmd.add_argument("-pr", "--price", help="Prix de l'annonce à créer")
|
||||
deleteoffer_cmd.add_argument("-i", "--id", help="Annonce cible à supprimer")
|
||||
|
||||
# GVA usage
|
||||
pay_cmd.add_argument('-p', '--pubkey', help="Destinataire du paiement")
|
||||
pay_cmd.add_argument('-a', '--amount', type=float, help="Montant de la transaction")
|
||||
pay_cmd.add_argument('-c', '--comment', default="", help="Commentaire de la transaction", nargs='*')
|
||||
pay_cmd.add_argument('-m', '--mempool', action='store_true', help="Utilise les sources en Mempool")
|
||||
pay_cmd.add_argument('-v', '--verbose', action='store_true', help="Affiche le résultat JSON de la transaction")
|
||||
pay_cmd.add_argument("-p", "--pubkey", help="Destinataire du paiement")
|
||||
pay_cmd.add_argument("-a", "--amount", type=float, help="Montant de la transaction")
|
||||
pay_cmd.add_argument(
|
||||
"-c", "--comment", default="", help="Commentaire de la transaction", nargs="*"
|
||||
)
|
||||
pay_cmd.add_argument(
|
||||
"-m", "--mempool", action="store_true", help="Utilise les sources en Mempool"
|
||||
)
|
||||
pay_cmd.add_argument(
|
||||
"-v",
|
||||
"--verbose",
|
||||
action="store_true",
|
||||
help="Affiche le résultat JSON de la transaction",
|
||||
)
|
||||
|
||||
history_cmd.add_argument('-p', '--pubkey', help="Clé publique du compte visé")
|
||||
history_cmd.add_argument('-n', '--number',type=int, default=10, help="Affiche les NUMBER dernières transactions")
|
||||
history_cmd.add_argument('-j', '--json', action='store_true', help="Affiche le résultat en format JSON")
|
||||
history_cmd.add_argument('--nocolors', action='store_true', help="Affiche le résultat en noir et blanc")
|
||||
history_cmd.add_argument("-p", "--pubkey", help="Clé publique du compte visé")
|
||||
history_cmd.add_argument(
|
||||
"-n",
|
||||
"--number",
|
||||
type=int,
|
||||
default=10,
|
||||
help="Affiche les NUMBER dernières transactions",
|
||||
)
|
||||
history_cmd.add_argument(
|
||||
"-j", "--json", action="store_true", help="Affiche le résultat en format JSON"
|
||||
)
|
||||
history_cmd.add_argument(
|
||||
"--nocolors", action="store_true", help="Affiche le résultat en noir et blanc"
|
||||
)
|
||||
|
||||
balance_cmd.add_argument('-p', '--pubkey', help="Clé publique du compte visé")
|
||||
balance_cmd.add_argument('-m', '--mempool', action='store_true', help="Utilise les sources en Mempool")
|
||||
id_cmd.add_argument('-p', '--pubkey', help="Clé publique du compte visé")
|
||||
id_cmd.add_argument('-u', '--username', help="Username du compte visé")
|
||||
id_balance_cmd.add_argument('-p', '--pubkey', help="Pubkey du compte visé")
|
||||
currentUd.add_argument('-p', '--pubkey', help="Pubkey du compte visé")
|
||||
listWallets.add_argument('-b', '--balance', action='store_true', help="Affiche les soldes")
|
||||
listWallets.add_argument('--mbr', action='store_true', help="Affiche la liste de pubkey membres brut")
|
||||
listWallets.add_argument('--non_mbr', action='store_true', help="Affiche la liste de pubkey des identités non membres brut")
|
||||
listWallets.add_argument('--larf', action='store_true', help="Affiche la liste des pubkey non membres brut")
|
||||
listWallets.add_argument('--brut', action='store_true', help="Affiche la liste de toutes les pubkey brut")
|
||||
listWallets.add_argument('-p', '--pubkey', help="useless but needed")
|
||||
balance_cmd.add_argument("-p", "--pubkey", help="Clé publique du compte visé")
|
||||
balance_cmd.add_argument(
|
||||
"-m", "--mempool", action="store_true", help="Utilise les sources en Mempool"
|
||||
)
|
||||
id_cmd.add_argument("-p", "--pubkey", help="Clé publique du compte visé")
|
||||
id_cmd.add_argument("-u", "--username", help="Username du compte visé")
|
||||
id_balance_cmd.add_argument("-p", "--pubkey", help="Pubkey du compte visé")
|
||||
currentUd.add_argument("-p", "--pubkey", help="Pubkey du compte visé")
|
||||
listWallets.add_argument(
|
||||
"-b", "--balance", action="store_true", help="Affiche les soldes"
|
||||
)
|
||||
listWallets.add_argument(
|
||||
"--mbr", action="store_true", help="Affiche la liste de pubkey membres brut"
|
||||
)
|
||||
listWallets.add_argument(
|
||||
"--non_mbr",
|
||||
action="store_true",
|
||||
help="Affiche la liste de pubkey des identités non membres brut",
|
||||
)
|
||||
listWallets.add_argument(
|
||||
"--larf", action="store_true", help="Affiche la liste des pubkey non membres brut"
|
||||
)
|
||||
listWallets.add_argument(
|
||||
"--brut", action="store_true", help="Affiche la liste de toutes les pubkey brut"
|
||||
)
|
||||
listWallets.add_argument("-p", "--pubkey", help="useless but needed")
|
||||
|
||||
args = parser.parse_args()
|
||||
cmd = args.cmd
|
||||
|
||||
if args.version:
|
||||
print(__version__)
|
||||
sys.exit(0)
|
||||
print(__version__)
|
||||
sys.exit(0)
|
||||
|
||||
if not cmd:
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def createTmpDunikey():
|
||||
# Generate pseudo-random nonce
|
||||
nonce=[]
|
||||
nonce = []
|
||||
for _ in range(32):
|
||||
nonce.append(random.choice(string.ascii_letters + string.digits))
|
||||
nonce = ''.join(nonce)
|
||||
nonce = "".join(nonce)
|
||||
keyPath = "/tmp/secret.dunikey-" + nonce
|
||||
|
||||
# key = SigningKey.from_credentials(getpass.getpass("Identifiant: "), getpass.getpass("Mot de passe: "), None)
|
||||
key = SigningKey.from_credentials("sgse547yhd54xv6541srdh", "sfdgwdrhpkxdawsbszqpof1sdg65xc", None)
|
||||
key = SigningKey.from_credentials(
|
||||
"sgse547yhd54xv6541srdh", "sfdgwdrhpkxdawsbszqpof1sdg65xc", None
|
||||
)
|
||||
key.save_pubsec_file(keyPath)
|
||||
|
||||
return keyPath
|
||||
|
||||
|
||||
# Check if we need dunikey
|
||||
try:
|
||||
pubkey = args.pubkey
|
||||
|
@ -160,7 +262,9 @@ except:
|
|||
profile = False
|
||||
|
||||
# print(pubkey, profile)
|
||||
if cmd in ('history','balance','get','page','id','idBalance','listWallets') and (pubkey or profile):
|
||||
if cmd in ("history", "balance", "get", "page", "id", "idBalance", "listWallets") and (
|
||||
pubkey or profile
|
||||
):
|
||||
noNeedDunikey = True
|
||||
keyPath = False
|
||||
try:
|
||||
|
@ -173,7 +277,7 @@ else:
|
|||
dunikey = args.key
|
||||
keyPath = False
|
||||
else:
|
||||
dunikey = os.getenv('DUNIKEY')
|
||||
dunikey = os.getenv("DUNIKEY")
|
||||
if not dunikey:
|
||||
keyPath = createTmpDunikey()
|
||||
dunikey = keyPath
|
||||
|
@ -183,12 +287,28 @@ else:
|
|||
HOME = os.getenv("HOME")
|
||||
dunikey = HOME + dunikey
|
||||
if not os.path.isfile(dunikey):
|
||||
sys.stderr.write('Le fichier de trousseau {0} est introuvable.\n'.format(dunikey))
|
||||
sys.stderr.write(
|
||||
"Le fichier de trousseau {0} est introuvable.\n".format(dunikey)
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Construct CesiumPlus object
|
||||
if cmd in ("read","send","delete","set","get","page","erase","stars","unstars","getoffer","setoffer","deleteoffer"):
|
||||
if cmd in (
|
||||
"read",
|
||||
"send",
|
||||
"delete",
|
||||
"set",
|
||||
"get",
|
||||
"page",
|
||||
"erase",
|
||||
"stars",
|
||||
"unstars",
|
||||
"getoffer",
|
||||
"setoffer",
|
||||
"deleteoffer",
|
||||
"geolocProfiles",
|
||||
):
|
||||
from lib.cesium import CesiumPlus
|
||||
|
||||
if args.node:
|
||||
|
@ -201,10 +321,10 @@ if cmd in ("read","send","delete","set","get","page","erase","stars","unstars","
|
|||
cesium.read(args.number, args.outbox, args.json)
|
||||
elif cmd == "send":
|
||||
if args.fichier:
|
||||
with open(args.fichier, 'r') as f:
|
||||
with open(args.fichier, "r") as f:
|
||||
msgT = f.read()
|
||||
titre = msgT.splitlines(True)[0].replace('\n', '')
|
||||
msg = ''.join(msgT.splitlines(True)[1:])
|
||||
titre = msgT.splitlines(True)[0].replace("\n", "")
|
||||
msg = "".join(msgT.splitlines(True)[1:])
|
||||
if args.titre:
|
||||
titre = args.titre
|
||||
msg = msgT
|
||||
|
@ -222,13 +342,23 @@ if cmd in ("read","send","delete","set","get","page","erase","stars","unstars","
|
|||
|
||||
# Profiles
|
||||
elif cmd == "set":
|
||||
cesium.set(args.name, args.description, args.ville, args.adresse, args.position, args.site, args.avatar)
|
||||
cesium.set(
|
||||
args.name,
|
||||
args.description,
|
||||
args.ville,
|
||||
args.adresse,
|
||||
args.position,
|
||||
args.site,
|
||||
args.avatar,
|
||||
)
|
||||
elif cmd == "get":
|
||||
cesium.get(args.profile, args.avatar)
|
||||
elif cmd == "page":
|
||||
cesium.getPage(args.page, args.avatar)
|
||||
elif cmd == "erase":
|
||||
cesium.erase()
|
||||
elif cmd == "geolocProfiles":
|
||||
cesium.geolocProfiles(node)
|
||||
|
||||
# Stars
|
||||
elif cmd == "stars":
|
||||
|
@ -243,12 +373,28 @@ if cmd in ("read","send","delete","set","get","page","erase","stars","unstars","
|
|||
elif cmd == "getoffer":
|
||||
cesium.getOffer(args.id)
|
||||
elif cmd == "setoffer":
|
||||
cesium.setOffer(args.title, args.description, args.city, args.localisation, args.category, args.price, args.picture)
|
||||
cesium.setOffer(
|
||||
args.title,
|
||||
args.description,
|
||||
args.city,
|
||||
args.localisation,
|
||||
args.category,
|
||||
args.price,
|
||||
args.picture,
|
||||
)
|
||||
elif cmd == "deleteoffer":
|
||||
cesium.deleteOffer(args.id)
|
||||
|
||||
# Construct GVA object
|
||||
elif cmd in ("pay","history","balance","id","idBalance","currentUd","listWallets"):
|
||||
elif cmd in (
|
||||
"pay",
|
||||
"history",
|
||||
"balance",
|
||||
"id",
|
||||
"idBalance",
|
||||
"currentUd",
|
||||
"listWallets",
|
||||
):
|
||||
from lib.gva import GvaApi
|
||||
|
||||
if args.node:
|
||||
|
|
110
lib/cesium.py
110
lib/cesium.py
|
@ -1,17 +1,19 @@
|
|||
import json
|
||||
import re, string, random, base64
|
||||
from lib.cesiumCommon import CesiumCommon, PUBKEY_REGEX
|
||||
from lib.geolocProfiles import GeolocProfiles
|
||||
from lib.getPages import Pages
|
||||
from lib.messaging import ReadFromCesium, SendToCesium, DeleteFromCesium
|
||||
from lib.profiles import Profiles
|
||||
from lib.stars import ReadLikes, SendLikes, UnLikes
|
||||
from lib.offers import Offers
|
||||
|
||||
class CesiumPlus(CesiumCommon):
|
||||
|
||||
class CesiumPlus(CesiumCommon):
|
||||
#################### Messaging ####################
|
||||
|
||||
def read(self, nbrMsg, outbox, isJSON):
|
||||
readCesium = ReadFromCesium(self.dunikey, self.pod)
|
||||
readCesium = ReadFromCesium(self.dunikey, self.pod)
|
||||
jsonMsg = readCesium.sendDocument(nbrMsg, outbox)
|
||||
if isJSON:
|
||||
jsonFormat = readCesium.jsonMessages(jsonMsg, nbrMsg, outbox)
|
||||
|
@ -24,16 +26,18 @@ class CesiumPlus(CesiumCommon):
|
|||
sendCesium.recipient = recipient
|
||||
|
||||
# Generate pseudo-random nonce
|
||||
nonce=[]
|
||||
nonce = []
|
||||
for _ in range(32):
|
||||
nonce.append(random.choice(string.ascii_letters + string.digits))
|
||||
sendCesium.nonce = base64.b64decode(''.join(nonce))
|
||||
sendCesium.nonce = base64.b64decode("".join(nonce))
|
||||
|
||||
finalDoc = sendCesium.configDoc(sendCesium.encryptMsg(title), sendCesium.encryptMsg(msg)) # Configure JSON document to send
|
||||
sendCesium.sendDocument(finalDoc, outbox) # Send final signed document
|
||||
finalDoc = sendCesium.configDoc(
|
||||
sendCesium.encryptMsg(title), sendCesium.encryptMsg(msg)
|
||||
) # Configure JSON document to send
|
||||
sendCesium.sendDocument(finalDoc, outbox) # Send final signed document
|
||||
|
||||
def delete(self, idsMsgList, outbox):
|
||||
deleteCesium = DeleteFromCesium(self.dunikey, self.pod)
|
||||
deleteCesium = DeleteFromCesium(self.dunikey, self.pod)
|
||||
# deleteCesium.issuer = recipient
|
||||
for idMsg in idsMsgList:
|
||||
finalDoc = deleteCesium.configDoc(idMsg, outbox)
|
||||
|
@ -41,55 +45,74 @@ class CesiumPlus(CesiumCommon):
|
|||
|
||||
#################### Profiles ####################
|
||||
|
||||
def set(self, name=None, description=None, ville=None, adresse=None, position=None, site=None, avatar=None):
|
||||
setProfile = Profiles(self.dunikey, self.pod)
|
||||
document = setProfile.configDocSet(name, description, ville, adresse, position, site, avatar)
|
||||
result = setProfile.sendDocument(document,'set')
|
||||
def set(
|
||||
self,
|
||||
name=None,
|
||||
description=None,
|
||||
ville=None,
|
||||
adresse=None,
|
||||
position=None,
|
||||
site=None,
|
||||
avatar=None,
|
||||
):
|
||||
setProfile = Profiles(self.dunikey, self.pod)
|
||||
document = setProfile.configDocSet(
|
||||
name, description, ville, adresse, position, site, avatar
|
||||
)
|
||||
result = setProfile.sendDocument(document, "set")
|
||||
|
||||
print(result)
|
||||
return result
|
||||
|
||||
|
||||
def get(self, profile=None, avatar=None):
|
||||
getProfile = Profiles(self.dunikey, self.pod, self.noNeedDunikey)
|
||||
getProfile = Profiles(self.dunikey, self.pod, self.noNeedDunikey)
|
||||
if not profile:
|
||||
profile = self.pubkey
|
||||
if not re.match(PUBKEY_REGEX, profile) or len(profile) > 45:
|
||||
scope = 'title'
|
||||
scope = "title"
|
||||
else:
|
||||
scope = '_id'
|
||||
|
||||
scope = "_id"
|
||||
|
||||
document = getProfile.configDocGet(profile, scope, avatar)
|
||||
resultJSON = getProfile.sendDocument(document, 'get')
|
||||
resultJSON = getProfile.sendDocument(document, "get")
|
||||
result = getProfile.parseJSON(resultJSON)
|
||||
|
||||
print(result)
|
||||
|
||||
|
||||
def getPage(self, page=None, avatar=None):
|
||||
getPage = Pages(self.dunikey, self.pod, self.noNeedDunikey)
|
||||
getPage = Pages(self.dunikey, self.pod, self.noNeedDunikey)
|
||||
if not page:
|
||||
page = self.pubkey
|
||||
if not re.match(PUBKEY_REGEX, page) or len(page) > 45:
|
||||
scope = 'title'
|
||||
scope = "title"
|
||||
else:
|
||||
scope = '_id'
|
||||
|
||||
scope = "_id"
|
||||
|
||||
document = getPage.configDocGet(page, scope, avatar)
|
||||
resultJSON = getPage.sendDocument(document, 'get')
|
||||
resultJSON = getPage.sendDocument(document, "get")
|
||||
result = getPage.parseJSON(resultJSON)
|
||||
|
||||
print(result)
|
||||
|
||||
def erase(self):
|
||||
eraseProfile = Profiles(self.dunikey, self.pod)
|
||||
eraseProfile = Profiles(self.dunikey, self.pod)
|
||||
document = eraseProfile.configDocErase()
|
||||
result = eraseProfile.sendDocument(document,'erase')
|
||||
result = eraseProfile.sendDocument(document, "erase")
|
||||
|
||||
print(result)
|
||||
|
||||
def geolocProfiles(self, node):
|
||||
geolocProfiles = GeolocProfiles(self.dunikey, self.pod)
|
||||
cesiumProfiles = geolocProfiles.getCesiumProfiles()
|
||||
gvaProfiles = geolocProfiles.getGVAProfiles(node)
|
||||
result = geolocProfiles.formatProfiles(cesiumProfiles, json.loads(gvaProfiles))
|
||||
|
||||
print(json.dumps(result, indent=2))
|
||||
|
||||
#################### Likes ####################
|
||||
|
||||
def readLikes(self, profile=False):
|
||||
likes = ReadLikes(self.dunikey, self.pod, self.noNeedDunikey)
|
||||
likes = ReadLikes(self.dunikey, self.pod, self.noNeedDunikey)
|
||||
document = likes.configDoc(profile)
|
||||
result = likes.sendDocument(document)
|
||||
result = likes.parseResult(result)
|
||||
|
@ -97,13 +120,13 @@ class CesiumPlus(CesiumCommon):
|
|||
print(result)
|
||||
|
||||
def like(self, stars, profile=False):
|
||||
likes = SendLikes(self.dunikey, self.pod)
|
||||
likes = SendLikes(self.dunikey, self.pod)
|
||||
document = likes.configDoc(profile, stars)
|
||||
if document:
|
||||
likes.sendDocument(document, profile)
|
||||
|
||||
def unLike(self, pubkey, silent=False):
|
||||
likes = UnLikes(self.dunikey, self.pod)
|
||||
likes = UnLikes(self.dunikey, self.pod)
|
||||
idLike = likes.checkLike(pubkey)
|
||||
if idLike:
|
||||
document = likes.configDoc(idLike)
|
||||
|
@ -111,26 +134,37 @@ class CesiumPlus(CesiumCommon):
|
|||
|
||||
#################### Offer ####################
|
||||
|
||||
def setOffer(self, title=None, description=None, city=None, localisation=None, category=None, price=None, picture=None):
|
||||
setOffer = Offers(self.dunikey, self.pod)
|
||||
document = setOffer.configDocSet(title, description, city, localisation, category, price, picture)
|
||||
result = setOffer.sendDocumentSet(document,'set')
|
||||
def setOffer(
|
||||
self,
|
||||
title=None,
|
||||
description=None,
|
||||
city=None,
|
||||
localisation=None,
|
||||
category=None,
|
||||
price=None,
|
||||
picture=None,
|
||||
):
|
||||
setOffer = Offers(self.dunikey, self.pod)
|
||||
document = setOffer.configDocSet(
|
||||
title, description, city, localisation, category, price, picture
|
||||
)
|
||||
result = setOffer.sendDocumentSet(document, "set")
|
||||
|
||||
# print(result)
|
||||
return result
|
||||
|
||||
|
||||
def getOffer(self, id, avatar=None):
|
||||
getOffer = Offers(self.dunikey, self.pod, self.noNeedDunikey)
|
||||
|
||||
resultJSON = getOffer.sendDocumentGet(id, 'get')
|
||||
getOffer = Offers(self.dunikey, self.pod, self.noNeedDunikey)
|
||||
|
||||
resultJSON = getOffer.sendDocumentGet(id, "get")
|
||||
# print(resultJSON)
|
||||
result = getOffer.parseJSON(resultJSON)
|
||||
|
||||
print(result)
|
||||
|
||||
def deleteOffer(self, id):
|
||||
eraseOffer = Offers(self.dunikey, self.pod)
|
||||
eraseOffer = Offers(self.dunikey, self.pod)
|
||||
document = eraseOffer.configDocErase(id)
|
||||
result = eraseOffer.sendDocumentSet(document,'delete', id)
|
||||
result = eraseOffer.sendDocumentSet(document, "delete", id)
|
||||
|
||||
print(result)
|
||||
|
|
|
@ -0,0 +1,135 @@
|
|||
import requests
|
||||
from time import time
|
||||
from lib.cesiumCommon import CesiumCommon
|
||||
from lib.gvaWallets import ListWallets
|
||||
|
||||
|
||||
class GeolocProfiles(CesiumCommon):
|
||||
# Configure JSON document POST ready to send
|
||||
def getCesiumProfiles(self):
|
||||
response = requests.post(
|
||||
"https://g1.data.e-is.pro/user/profile/_search?scroll=2m",
|
||||
json={
|
||||
"query": {
|
||||
"constant_score": {
|
||||
"filter": [
|
||||
{"exists": {"field": "geoPoint"}},
|
||||
{
|
||||
"geo_bounding_box": {
|
||||
"geoPoint": {
|
||||
"top_left": {"lat": 90, "lon": -180},
|
||||
"bottom_right": {"lat": -90, "lon": 180},
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
"_source": [
|
||||
"title",
|
||||
"avatar._content_type",
|
||||
"description",
|
||||
"city",
|
||||
"address",
|
||||
"socials.url",
|
||||
"creationTime",
|
||||
"membersCount",
|
||||
"type",
|
||||
"geoPoint",
|
||||
],
|
||||
"size": 20000,
|
||||
},
|
||||
)
|
||||
|
||||
scroll_id = response.json()["_scroll_id"]
|
||||
finalResult = response.json()["hits"]["hits"]
|
||||
|
||||
while True:
|
||||
# Effectuez une requête de défilement pour obtenir la page suivante
|
||||
response_scroll = requests.post(
|
||||
"https://g1.data.e-is.pro/_search/scroll",
|
||||
json={"scroll_id": scroll_id, "scroll": "2m"},
|
||||
)
|
||||
|
||||
# Vérifiez si la réponse est vide (aucun résultat) ou si la durée du défilement est écoulée
|
||||
if (
|
||||
not response_scroll.json()["hits"]["hits"]
|
||||
or "error" in response_scroll.json()
|
||||
):
|
||||
break
|
||||
else:
|
||||
finalResult = finalResult + response_scroll.json()["hits"]["hits"]
|
||||
|
||||
# Traitez les résultats ici
|
||||
|
||||
# Une fois terminé, supprimez le contexte de défilement
|
||||
requests.delete(
|
||||
"https://g1.data.e-is.pro/_search/scroll", json={"scroll_id": [scroll_id]}
|
||||
)
|
||||
|
||||
return finalResult
|
||||
|
||||
def getGVAProfiles(self, node):
|
||||
gva = ListWallets(node, False, False, False, False)
|
||||
return gva.sendDoc()
|
||||
|
||||
def formatProfiles(self, cesiumProfiles, gvaProfiles):
|
||||
walletsResult = []
|
||||
for profile in cesiumProfiles:
|
||||
source = profile["_source"]
|
||||
pubkey = profile["_id"]
|
||||
try:
|
||||
isMember = gvaProfiles[pubkey]["id"]["isMember"]
|
||||
userId = gvaProfiles[pubkey]["id"]["username"]
|
||||
except:
|
||||
isMember = False
|
||||
userId = None
|
||||
|
||||
try:
|
||||
title = source["title"]
|
||||
except:
|
||||
title = None
|
||||
|
||||
try:
|
||||
city = source["city"]
|
||||
except:
|
||||
city = None
|
||||
|
||||
try:
|
||||
avatar = source["avatar"]
|
||||
except:
|
||||
avatar: None
|
||||
|
||||
try:
|
||||
socials = source["socials"]
|
||||
except:
|
||||
socials = None
|
||||
|
||||
try:
|
||||
description = source["description"]
|
||||
except:
|
||||
description = None
|
||||
|
||||
try:
|
||||
address = source["address"]
|
||||
except:
|
||||
address = None
|
||||
|
||||
walletsResult.append(
|
||||
{
|
||||
"pubkey": pubkey,
|
||||
**({"address": address} if address else {}),
|
||||
**({"city": city} if city else {}),
|
||||
**({"description": description} if description else {}),
|
||||
**({"avatar": avatar} if avatar else {}),
|
||||
**({"userId": userId} if userId else {}),
|
||||
"isMember": isMember,
|
||||
"geoPoint": source["geoPoint"],
|
||||
**({"socials": socials} if socials else {}),
|
||||
**({"title": title} if title else {}),
|
||||
}
|
||||
)
|
||||
|
||||
finalResult = {"wallets": walletsResult, "time": int(time())}
|
||||
|
||||
return finalResult
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys, re, os.path, json, ast
|
||||
import sys, json
|
||||
from termcolor import colored
|
||||
from lib.natools import fmt, sign, get_privkey
|
||||
from gql import gql, Client
|
||||
|
@ -8,8 +8,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
|
||||
|
@ -45,7 +45,8 @@ class ListWallets:
|
|||
}
|
||||
}
|
||||
}
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
# Send wallets document
|
||||
try:
|
||||
|
@ -54,24 +55,34 @@ class ListWallets:
|
|||
sys.stderr.write("Echec de récupération de la liste:\n" + str(e) + "\n")
|
||||
sys.exit(1)
|
||||
|
||||
jsonBrut = queryResult['wallets']['edges']
|
||||
jsonBrut = queryResult["wallets"]["edges"]
|
||||
|
||||
walletList = []
|
||||
walletMap = {}
|
||||
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
|
||||
walletMap[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'])
|
||||
for dataWork in walletMap:
|
||||
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:
|
||||
return json.dumps(walletList, indent=2)
|
||||
return json.dumps(walletMap, indent=2)
|
||||
|
|
138
lib/profiles.py
138
lib/profiles.py
|
@ -1,4 +1,4 @@
|
|||
import sys, re, json, requests, base64
|
||||
import sys, json, requests, base64
|
||||
from time import time
|
||||
from lib.cesiumCommon import CesiumCommon, PUBKEY_REGEX
|
||||
|
||||
|
@ -9,71 +9,74 @@ class Profiles(CesiumCommon):
|
|||
timeSent = int(time())
|
||||
|
||||
data = {}
|
||||
if name: data['title'] = name
|
||||
if description: data['description'] = description
|
||||
if address: data['address'] = address
|
||||
if city: data['city'] = city
|
||||
if pos:
|
||||
if name:
|
||||
data["title"] = name
|
||||
if description:
|
||||
data["description"] = description
|
||||
if address:
|
||||
data["address"] = address
|
||||
if city:
|
||||
data["city"] = city
|
||||
if pos:
|
||||
geoPoint = {}
|
||||
geoPoint['lat'] = pos[0]
|
||||
geoPoint['lon'] = pos[1]
|
||||
data['geoPoint'] = geoPoint
|
||||
geoPoint["lat"] = pos[0]
|
||||
geoPoint["lon"] = pos[1]
|
||||
data["geoPoint"] = geoPoint
|
||||
if socials:
|
||||
data['socials'] = []
|
||||
data['socials'].append({})
|
||||
data['socials'][0]['type'] = "web"
|
||||
data['socials'][0]['url'] = socials
|
||||
data["socials"] = []
|
||||
data["socials"].append({})
|
||||
data["socials"][0]["type"] = "web"
|
||||
data["socials"][0]["url"] = socials
|
||||
if avatar:
|
||||
avatar = open(avatar, 'rb').read()
|
||||
avatar = open(avatar, "rb").read()
|
||||
avatar = base64.b64encode(avatar).decode()
|
||||
data['avatar'] = {}
|
||||
data['avatar']['_content'] = avatar
|
||||
data['avatar']['_content_type'] = "image/png"
|
||||
data['time'] = timeSent
|
||||
data['issuer'] = self.pubkey
|
||||
data['version'] = 2
|
||||
data['tags'] = []
|
||||
data["avatar"] = {}
|
||||
data["avatar"]["_content"] = avatar
|
||||
data["avatar"]["_content_type"] = "image/png"
|
||||
data["time"] = timeSent
|
||||
data["issuer"] = self.pubkey
|
||||
data["version"] = 2
|
||||
data["tags"] = []
|
||||
|
||||
document = json.dumps(data)
|
||||
document = json.dumps(data)
|
||||
|
||||
return self.signDoc(document)
|
||||
|
||||
# Configure JSON document GET to send
|
||||
def configDocGet(self, profile, scope='title', getAvatar=None):
|
||||
|
||||
# Configure JSON document GET to send
|
||||
def configDocGet(self, profile, scope="title", getAvatar=None):
|
||||
if getAvatar:
|
||||
avatar = "avatar"
|
||||
else:
|
||||
avatar = "avatar._content_type"
|
||||
|
||||
data = {
|
||||
"query": {
|
||||
"query": {
|
||||
"bool": {
|
||||
"should":[
|
||||
{
|
||||
"match":{
|
||||
scope:{
|
||||
"query": profile,"boost":2
|
||||
}
|
||||
}
|
||||
},{
|
||||
"prefix": {scope: profile}
|
||||
}
|
||||
"should": [
|
||||
{"match": {scope: {"query": profile, "boost": 2}}},
|
||||
{"prefix": {scope: profile}},
|
||||
]
|
||||
}
|
||||
},"highlight": {
|
||||
"fields": {
|
||||
"title":{},
|
||||
"tags":{}
|
||||
}
|
||||
},"from":0,
|
||||
"size":100,
|
||||
"_source":["title", avatar,"description","city","address","socials.url","creationTime","membersCount","type","geoPoint"],
|
||||
"indices_boost":{"user":100,"page":1,"group":0.01
|
||||
}
|
||||
},
|
||||
"highlight": {"fields": {"title": {}, "tags": {}}},
|
||||
"from": 0,
|
||||
"size": 100,
|
||||
"_source": [
|
||||
"title",
|
||||
avatar,
|
||||
"description",
|
||||
"city",
|
||||
"address",
|
||||
"socials.url",
|
||||
"creationTime",
|
||||
"membersCount",
|
||||
"type",
|
||||
"geoPoint",
|
||||
],
|
||||
"indices_boost": {"user": 100, "page": 1, "group": 0.01},
|
||||
}
|
||||
|
||||
document = json.dumps(data)
|
||||
document = json.dumps(data)
|
||||
|
||||
return document
|
||||
|
||||
|
@ -82,44 +85,45 @@ class Profiles(CesiumCommon):
|
|||
timeSent = int(time())
|
||||
|
||||
data = {}
|
||||
data['time'] = timeSent
|
||||
data['id'] = self.pubkey
|
||||
data['issuer'] = self.pubkey
|
||||
data['version'] = 2
|
||||
data['index'] = "user"
|
||||
data['type'] = "profile"
|
||||
data["time"] = timeSent
|
||||
data["id"] = self.pubkey
|
||||
data["issuer"] = self.pubkey
|
||||
data["version"] = 2
|
||||
data["index"] = "user"
|
||||
data["type"] = "profile"
|
||||
|
||||
document = json.dumps(data)
|
||||
document = json.dumps(data)
|
||||
|
||||
return self.signDoc(document)
|
||||
|
||||
def sendDocument(self, document, type):
|
||||
|
||||
headers = {
|
||||
'Content-type': 'application/json',
|
||||
"Content-type": "application/json",
|
||||
}
|
||||
|
||||
# Send JSON document and get JSON result
|
||||
if type == 'set':
|
||||
reqQuery = '{0}/user/profile?pubkey={1}/_update?pubkey={1}'.format(self.pod, self.pubkey)
|
||||
elif type == 'get':
|
||||
reqQuery = '{0}/user,page,group/profile,record/_search'.format(self.pod)
|
||||
elif type == 'erase':
|
||||
reqQuery = '{0}/history/delete'.format(self.pod)
|
||||
if type == "set":
|
||||
reqQuery = "{0}/user/profile?pubkey={1}/_update?pubkey={1}".format(
|
||||
self.pod, self.pubkey
|
||||
)
|
||||
elif type == "get":
|
||||
reqQuery = "{0}/user,page,group/profile,record/_search".format(self.pod)
|
||||
elif type == "erase":
|
||||
reqQuery = "{0}/history/delete".format(self.pod)
|
||||
|
||||
result = requests.post(reqQuery, headers=headers, data=document)
|
||||
if result.status_code == 200:
|
||||
# print(result.text)
|
||||
return result.text
|
||||
else:
|
||||
sys.stderr.write("Echec de l'envoi du document...\n" + result.text + '\n')
|
||||
sys.stderr.write("Echec de l'envoi du document...\n" + result.text + "\n")
|
||||
|
||||
def parseJSON(self, doc):
|
||||
doc = json.loads(doc)['hits']['hits']
|
||||
doc = json.loads(doc)["hits"]["hits"]
|
||||
if doc:
|
||||
pubkey = { "pubkey": doc[0]['_id'] }
|
||||
rest = doc[0]['_source']
|
||||
pubkey = {"pubkey": doc[0]["_id"]}
|
||||
rest = doc[0]["_source"]
|
||||
final = {**pubkey, **rest}
|
||||
return json.dumps(final, indent=2)
|
||||
else:
|
||||
return 'Profile vide'
|
||||
return "Profile vide"
|
||||
|
|
Loading…
Reference in New Issue