Skip to content

Commit b8e2280

Browse files
committed
upload to map
1 parent 2b706c7 commit b8e2280

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/meshcore_cli/meshcore_cli.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import time, datetime
88
import getopt, json, shlex, re
99
import logging
10+
import requests
1011
from pathlib import Path
1112
from prompt_toolkit.shortcuts import PromptSession
1213
from prompt_toolkit.shortcuts import CompleteStyle
@@ -186,6 +187,7 @@ def make_completion_dict(contacts):
186187
"classic_prompt":None},
187188
"reboot" : None,
188189
"card" : None,
190+
"upload_card" : None,
189191
"login" : None,
190192
"logout" : None,
191193
"req_status" : None,
@@ -194,6 +196,7 @@ def make_completion_dict(contacts):
194196
"contact_info": None,
195197
"path": None,
196198
"export_contact" : None,
199+
"upload_contact" : None,
197200
"reset_path" : None,
198201
"change_path" : None,
199202
"cli" : None,
@@ -321,6 +324,7 @@ def _(event):
321324
line.startswith("card") or \
322325
line.startswith("lc") or \
323326
line.startswith("script") or \
327+
line.startswith("upload_card") or \
324328
line == "infos" or line == "i" :
325329
args = shlex.split(line)
326330
await process_cmds(mc, args)
@@ -334,6 +338,7 @@ def _(event):
334338
# commands that take contact as second arg will be sent to recipient
335339
elif line == "sc" or line == "share_contact" or\
336340
line == "ec" or line == "export_contact" or\
341+
line == "uc" or line == "upload_contact" or\
337342
line == "rp" or line == "reset_path" or\
338343
line == "contact_info" or line == "ci" or\
339344
line == "path" or\
@@ -903,6 +908,28 @@ async def next_cmd(mc, cmds, json_output=False):
903908
else :
904909
print(res.payload['uri'])
905910

911+
case "upload_contact" | "uc" :
912+
argnum = 1
913+
await mc.ensure_contacts()
914+
contact = mc.get_contact_by_name(cmds[1])
915+
if contact is None:
916+
if json_output :
917+
print(json.dumps({"error" : "contact unknown", "name" : cmds[1]}))
918+
else:
919+
print(f"Unknown contact {cmds[1]}")
920+
else:
921+
res = await mc.commands.export_contact(contact)
922+
logger.debug(res)
923+
if res.type == EventType.ERROR:
924+
print(f"Error exporting contact: {res}")
925+
else :
926+
resp = requests.post("https://map.meshcore.dev/api/v1/nodes",
927+
json = {"links": [res.payload['uri']]})
928+
if json_output :
929+
print(json.dumps({"response", str(resp)}))
930+
else :
931+
print(resp)
932+
906933
case "card" :
907934
res = await mc.commands.export_contact()
908935
logger.debug(res)
@@ -913,6 +940,19 @@ async def next_cmd(mc, cmds, json_output=False):
913940
else :
914941
print(res.payload['uri'])
915942

943+
case "upload_card" :
944+
res = await mc.commands.export_contact()
945+
logger.debug(res)
946+
if res.type == EventType.ERROR:
947+
print(f"Error exporting contact: {res}")
948+
else :
949+
resp = requests.post("https://map.meshcore.dev/api/v1/nodes",
950+
json = {"links": [res.payload['uri']]})
951+
if json_output :
952+
print(json.dumps({"response", str(resp)}))
953+
else :
954+
print(resp)
955+
916956
case "remove_contact" :
917957
argnum = 1
918958
await mc.ensure_contacts()

0 commit comments

Comments
 (0)