mirror of
https://github.com/meshcore-dev/meshcore-cli.git
synced 2026-04-20 22:13:48 +00:00
upload to map
This commit is contained in:
parent
2b706c7773
commit
b8e2280ed8
1 changed files with 40 additions and 0 deletions
|
|
@ -7,6 +7,7 @@ import os, sys
|
||||||
import time, datetime
|
import time, datetime
|
||||||
import getopt, json, shlex, re
|
import getopt, json, shlex, re
|
||||||
import logging
|
import logging
|
||||||
|
import requests
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from prompt_toolkit.shortcuts import PromptSession
|
from prompt_toolkit.shortcuts import PromptSession
|
||||||
from prompt_toolkit.shortcuts import CompleteStyle
|
from prompt_toolkit.shortcuts import CompleteStyle
|
||||||
|
|
@ -186,6 +187,7 @@ def make_completion_dict(contacts):
|
||||||
"classic_prompt":None},
|
"classic_prompt":None},
|
||||||
"reboot" : None,
|
"reboot" : None,
|
||||||
"card" : None,
|
"card" : None,
|
||||||
|
"upload_card" : None,
|
||||||
"login" : None,
|
"login" : None,
|
||||||
"logout" : None,
|
"logout" : None,
|
||||||
"req_status" : None,
|
"req_status" : None,
|
||||||
|
|
@ -194,6 +196,7 @@ def make_completion_dict(contacts):
|
||||||
"contact_info": None,
|
"contact_info": None,
|
||||||
"path": None,
|
"path": None,
|
||||||
"export_contact" : None,
|
"export_contact" : None,
|
||||||
|
"upload_contact" : None,
|
||||||
"reset_path" : None,
|
"reset_path" : None,
|
||||||
"change_path" : None,
|
"change_path" : None,
|
||||||
"cli" : None,
|
"cli" : None,
|
||||||
|
|
@ -321,6 +324,7 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
|
||||||
line.startswith("card") or \
|
line.startswith("card") or \
|
||||||
line.startswith("lc") or \
|
line.startswith("lc") or \
|
||||||
line.startswith("script") or \
|
line.startswith("script") or \
|
||||||
|
line.startswith("upload_card") or \
|
||||||
line == "infos" or line == "i" :
|
line == "infos" or line == "i" :
|
||||||
args = shlex.split(line)
|
args = shlex.split(line)
|
||||||
await process_cmds(mc, args)
|
await process_cmds(mc, args)
|
||||||
|
|
@ -334,6 +338,7 @@ Line starting with \"$\" or \".\" will issue a meshcli command.
|
||||||
# commands that take contact as second arg will be sent to recipient
|
# commands that take contact as second arg will be sent to recipient
|
||||||
elif line == "sc" or line == "share_contact" or\
|
elif line == "sc" or line == "share_contact" or\
|
||||||
line == "ec" or line == "export_contact" or\
|
line == "ec" or line == "export_contact" or\
|
||||||
|
line == "uc" or line == "upload_contact" or\
|
||||||
line == "rp" or line == "reset_path" or\
|
line == "rp" or line == "reset_path" or\
|
||||||
line == "contact_info" or line == "ci" or\
|
line == "contact_info" or line == "ci" or\
|
||||||
line == "path" or\
|
line == "path" or\
|
||||||
|
|
@ -903,6 +908,28 @@ async def next_cmd(mc, cmds, json_output=False):
|
||||||
else :
|
else :
|
||||||
print(res.payload['uri'])
|
print(res.payload['uri'])
|
||||||
|
|
||||||
|
case "upload_contact" | "uc" :
|
||||||
|
argnum = 1
|
||||||
|
await mc.ensure_contacts()
|
||||||
|
contact = mc.get_contact_by_name(cmds[1])
|
||||||
|
if contact is None:
|
||||||
|
if json_output :
|
||||||
|
print(json.dumps({"error" : "contact unknown", "name" : cmds[1]}))
|
||||||
|
else:
|
||||||
|
print(f"Unknown contact {cmds[1]}")
|
||||||
|
else:
|
||||||
|
res = await mc.commands.export_contact(contact)
|
||||||
|
logger.debug(res)
|
||||||
|
if res.type == EventType.ERROR:
|
||||||
|
print(f"Error exporting contact: {res}")
|
||||||
|
else :
|
||||||
|
resp = requests.post("https://map.meshcore.dev/api/v1/nodes",
|
||||||
|
json = {"links": [res.payload['uri']]})
|
||||||
|
if json_output :
|
||||||
|
print(json.dumps({"response", str(resp)}))
|
||||||
|
else :
|
||||||
|
print(resp)
|
||||||
|
|
||||||
case "card" :
|
case "card" :
|
||||||
res = await mc.commands.export_contact()
|
res = await mc.commands.export_contact()
|
||||||
logger.debug(res)
|
logger.debug(res)
|
||||||
|
|
@ -913,6 +940,19 @@ async def next_cmd(mc, cmds, json_output=False):
|
||||||
else :
|
else :
|
||||||
print(res.payload['uri'])
|
print(res.payload['uri'])
|
||||||
|
|
||||||
|
case "upload_card" :
|
||||||
|
res = await mc.commands.export_contact()
|
||||||
|
logger.debug(res)
|
||||||
|
if res.type == EventType.ERROR:
|
||||||
|
print(f"Error exporting contact: {res}")
|
||||||
|
else :
|
||||||
|
resp = requests.post("https://map.meshcore.dev/api/v1/nodes",
|
||||||
|
json = {"links": [res.payload['uri']]})
|
||||||
|
if json_output :
|
||||||
|
print(json.dumps({"response", str(resp)}))
|
||||||
|
else :
|
||||||
|
print(resp)
|
||||||
|
|
||||||
case "remove_contact" :
|
case "remove_contact" :
|
||||||
argnum = 1
|
argnum = 1
|
||||||
await mc.ensure_contacts()
|
await mc.ensure_contacts()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue