From e08fd7813106c3df7ca0072c13e1debe6528b548 Mon Sep 17 00:00:00 2001 From: poka Date: Wed, 18 Nov 2020 01:13:16 +0100 Subject: [PATCH] First work of readmsg.py --- .gitignore | 2 ++ readmsg.py | 61 +++++++++++++++++++++++++++++++++++++++++++++ userEnv.py.template | 3 +++ 3 files changed, 66 insertions(+) create mode 100755 readmsg.py create mode 100644 userEnv.py.template diff --git a/.gitignore b/.gitignore index 4c49bd7..7d8f797 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ .env +userEnv.py +__pycache__ diff --git a/readmsg.py b/readmsg.py new file mode 100755 index 0000000..4604c66 --- /dev/null +++ b/readmsg.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 + +import os, sys, requests, json, base58, base64 +from userEnv import dunikey, pod +from natools import fmt, sign, get_privkey +from datetime import datetime + +#recipient = sys.argv[1] +recipient = get_privkey(dunikey, "pubsec").pubkey +nbrMsg = 5 +boxType = "inbox" + +def configDoc(recipient, nbrMsg): + return { + "sort": { "time": "desc" }, + "from": 0, + "size": nbrMsg, + "_source":[ + "issuer", + "recipient", + "title", + "content", + "time", + "nonce", + "read_signature" + ],"query":{ + "bool":{ + "filter":{ + "term":{ + "recipient": recipient + } + } + } + } +} +document = json.dumps(configDoc(recipient, nbrMsg)) +# print(json.dumps(document)) + +headers = { + 'Content-type': 'application/json', +} +msgJSON = requests.post('{0}/message/{1}/_search'.format(pod, boxType), headers=headers, data=document).json()["hits"] + +total = msgJSON["total"] +for hits in msgJSON["hits"]: + isMsg = hits["_id"] + msgSrc = hits["_source"] + issuer = msgSrc["issuer"] + title = msgSrc["title"] + content = msgSrc["content"] + nonce = msgSrc["nonce"] + date = datetime.fromtimestamp(msgSrc["time"]).strftime("Le %d/%m/%Y à %H:%M") + + + print("----------") + print(date) + print("Objet: " + title) + print("Message: " + content) + + + diff --git a/userEnv.py.template b/userEnv.py.template new file mode 100644 index 0000000..f1bca2d --- /dev/null +++ b/userEnv.py.template @@ -0,0 +1,3 @@ +dunikey = "" # Chemin de la clé privé Ḡ1 de l'émetteur, au format PubSec +pod = "https://g1.data.duniter.fr" # Adresse du pod Cesium ou Gchange à utiliser +#pod = "https://data.gchange.fr"