You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.2 KiB
Python
56 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
from os import read
|
|
|
|
import i18n
|
|
import validators
|
|
import json
|
|
import requests
|
|
from pathlib import Path
|
|
from getpass import getpass
|
|
|
|
CONFIG_FILE = "~/.config/notepostcli.json"
|
|
|
|
|
|
def checkconfig():
|
|
config_path = Path(CONFIG_FILE)
|
|
if config_path.is_file():
|
|
try:
|
|
# Attempt to read and parse the config file
|
|
config_file = open(CONFIG_FILE, 'r')
|
|
json.load(config_file)
|
|
return True
|
|
except Exception:
|
|
return False
|
|
else:
|
|
return False
|
|
|
|
|
|
def firstsetup():
|
|
while True:
|
|
url = input(i18n.t("Server URL: "))
|
|
if validators.url(url):
|
|
break
|
|
else:
|
|
print(i18n.t("That doesn't look right, try again."))
|
|
while True:
|
|
username = input(i18n.t("Username: "))
|
|
if username != "":
|
|
break
|
|
while True:
|
|
password = getpass(i18n.t("Password: "))
|
|
if password != "":
|
|
break
|
|
|
|
r = requests.post(url + "/api/ping", data = {"username": username, "password": password})
|
|
print(r.json())
|
|
|
|
|
|
def main():
|
|
if not checkconfig():
|
|
print(i18n.t("No valid settings file found, running setup wizard."))
|
|
firstsetup()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|