Working barebones app
This commit is contained in:
parent
0913f6d2ce
commit
c6793902a1
116
.idea/workspace.xml
generated
116
.idea/workspace.xml
generated
@ -2,8 +2,11 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="7e2ff7f2-75de-431f-9457-e0d648b65015" name="Default Changelist" comment="">
|
<list default="true" id="7e2ff7f2-75de-431f-9457-e0d648b65015" name="Default Changelist" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/config.py" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/api.py" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/note.class.py" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/termcolors.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/config.py" beforeDir="false" afterPath="$PROJECT_DIR$/config.py" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/notepost.py" beforeDir="false" afterPath="$PROJECT_DIR$/notepost.py" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/notepost.py" beforeDir="false" afterPath="$PROJECT_DIR$/notepost.py" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||||
@ -14,23 +17,57 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="FileEditorManager">
|
<component name="FileEditorManager">
|
||||||
<leaf>
|
<leaf>
|
||||||
<file pinned="false" current-in-tab="false">
|
<file pinned="false" current-in-tab="true">
|
||||||
<entry file="file://$PROJECT_DIR$/notepost.py">
|
<entry file="file://$PROJECT_DIR$/notepost.py">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="270">
|
<state relative-caret-position="570">
|
||||||
<caret line="18" column="17" lean-forward="true" selection-start-line="17" selection-start-column="8" selection-end-line="18" selection-end-column="17" />
|
<caret line="141" column="31" selection-start-line="141" selection-start-column="31" selection-end-line="141" selection-end-column="31" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#24#35#0" expanded="true" />
|
<element signature="e#23#34#0" expanded="true" />
|
||||||
|
<element signature="e#902#2295#0" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
</file>
|
</file>
|
||||||
<file pinned="false" current-in-tab="true">
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/termcolors.py">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="285">
|
||||||
|
<caret line="19" column="22" lean-forward="true" selection-start-line="19" selection-start-column="22" selection-end-line="19" selection-end-column="22" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/api.py">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state>
|
||||||
|
<caret selection-end-column="22" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#23#34#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/note.class.py">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="225">
|
||||||
|
<caret line="15" selection-start-line="15" selection-end-line="15" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#24#39#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
<entry file="file://$PROJECT_DIR$/config.py">
|
<entry file="file://$PROJECT_DIR$/config.py">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="426">
|
<state relative-caret-position="495">
|
||||||
<caret line="54" lean-forward="true" selection-start-line="54" selection-end-line="54" />
|
<caret line="33" column="20" selection-start-line="33" selection-start-column="20" selection-end-line="33" selection-end-column="20" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#25#36#0" expanded="true" />
|
<element signature="e#25#36#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
@ -53,16 +90,18 @@
|
|||||||
<component name="IdeDocumentHistory">
|
<component name="IdeDocumentHistory">
|
||||||
<option name="CHANGED_PATHS">
|
<option name="CHANGED_PATHS">
|
||||||
<list>
|
<list>
|
||||||
<option value="$PROJECT_DIR$/notepost.py" />
|
|
||||||
<option value="$PROJECT_DIR$/config.py" />
|
<option value="$PROJECT_DIR$/config.py" />
|
||||||
|
<option value="$PROJECT_DIR$/note.class.py" />
|
||||||
|
<option value="$PROJECT_DIR$/api.py" />
|
||||||
|
<option value="$PROJECT_DIR$/termcolors.py" />
|
||||||
|
<option value="$PROJECT_DIR$/notepost.py" />
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectFrameBounds" extendedState="6">
|
<component name="ProjectFrameBounds">
|
||||||
<option name="x" value="260" />
|
<option name="x" value="4" />
|
||||||
<option name="y" value="21" />
|
<option name="width" value="1912" />
|
||||||
<option name="width" value="1400" />
|
<option name="height" value="1038" />
|
||||||
<option name="height" value="1000" />
|
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
||||||
<component name="ProjectView">
|
<component name="ProjectView">
|
||||||
@ -88,6 +127,9 @@
|
|||||||
</pane>
|
</pane>
|
||||||
</panes>
|
</panes>
|
||||||
</component>
|
</component>
|
||||||
|
<component name="PropertiesComponent">
|
||||||
|
<property name="settings.editor.selected.configurable" value="consents" />
|
||||||
|
</component>
|
||||||
<component name="RunDashboard">
|
<component name="RunDashboard">
|
||||||
<option name="ruleStates">
|
<option name="ruleStates">
|
||||||
<list>
|
<list>
|
||||||
@ -142,15 +184,15 @@
|
|||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="ToolWindowManager">
|
<component name="ToolWindowManager">
|
||||||
<frame x="0" y="0" width="1920" height="1042" extended-state="6" />
|
<frame x="4" y="0" width="1912" height="1038" extended-state="0" />
|
||||||
<editor active="true" />
|
<editor active="true" />
|
||||||
<layout>
|
<layout>
|
||||||
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18028466" />
|
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.18104817" />
|
||||||
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
||||||
<window_info id="Favorites" order="2" side_tool="true" />
|
<window_info id="Favorites" order="2" side_tool="true" />
|
||||||
<window_info anchor="bottom" id="Message" order="0" />
|
<window_info anchor="bottom" id="Message" order="0" />
|
||||||
<window_info anchor="bottom" id="Find" order="1" />
|
<window_info anchor="bottom" id="Find" order="1" />
|
||||||
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32932165" />
|
<window_info anchor="bottom" id="Run" order="2" weight="0.545055" />
|
||||||
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
|
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
|
||||||
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
|
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
|
||||||
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
||||||
@ -175,25 +217,53 @@
|
|||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/notepost.py">
|
<entry file="file://$PROJECT_DIR$/note.class.py">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="270">
|
<state relative-caret-position="225">
|
||||||
<caret line="18" column="17" lean-forward="true" selection-start-line="17" selection-start-column="8" selection-end-line="18" selection-end-column="17" />
|
<caret line="15" selection-start-line="15" selection-end-line="15" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#24#35#0" expanded="true" />
|
<element signature="e#24#39#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
<entry file="file://$PROJECT_DIR$/config.py">
|
<entry file="file://$PROJECT_DIR$/config.py">
|
||||||
<provider selected="true" editor-type-id="text-editor">
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
<state relative-caret-position="426">
|
<state relative-caret-position="495">
|
||||||
<caret line="54" lean-forward="true" selection-start-line="54" selection-end-line="54" />
|
<caret line="33" column="20" selection-start-line="33" selection-start-column="20" selection-end-line="33" selection-end-column="20" />
|
||||||
<folding>
|
<folding>
|
||||||
<element signature="e#25#36#0" expanded="true" />
|
<element signature="e#25#36#0" expanded="true" />
|
||||||
</folding>
|
</folding>
|
||||||
</state>
|
</state>
|
||||||
</provider>
|
</provider>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/api.py">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state>
|
||||||
|
<caret selection-end-column="22" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#23#34#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/termcolors.py">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="285">
|
||||||
|
<caret line="19" column="22" lean-forward="true" selection-start-line="19" selection-start-column="22" selection-end-line="19" selection-end-column="22" />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/notepost.py">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="570">
|
||||||
|
<caret line="141" column="31" selection-start-line="141" selection-start-column="31" selection-end-line="141" selection-end-column="31" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#23#34#0" expanded="true" />
|
||||||
|
<element signature="e#902#2295#0" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
23
api.py
Normal file
23
api.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import i18n
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from config import getconfig
|
||||||
|
|
||||||
|
|
||||||
|
def do(action, data={}):
|
||||||
|
conf = getconfig()
|
||||||
|
try:
|
||||||
|
r = requests.post(conf["url"] + "/api/" + action, data=data, auth=(conf["username"], conf["password"]))
|
||||||
|
except:
|
||||||
|
print(i18n.t("Could not connect to the server. Try again."))
|
||||||
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
resp = r.json()
|
||||||
|
if resp["status"] == "ERROR":
|
||||||
|
raise Exception(resp["msg"])
|
||||||
|
return resp
|
||||||
|
except ValueError:
|
||||||
|
raise Exception(i18n.t("Invalid response from server."))
|
@ -1,10 +1,8 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import appdirs
|
import appdirs
|
||||||
import os
|
import os
|
||||||
import validators
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
appname = "NotePostCLI"
|
appname = "NotePostCLI"
|
||||||
|
118
notepost.py
118
notepost.py
@ -1,14 +1,22 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import math
|
||||||
|
import tempfile
|
||||||
|
|
||||||
import i18n
|
import i18n
|
||||||
import validators
|
import validators
|
||||||
import requests
|
import requests
|
||||||
|
import api
|
||||||
from config import *
|
from config import *
|
||||||
|
from termcolors import *
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
|
|
||||||
|
|
||||||
|
editor = "/usr/bin/editor"
|
||||||
|
|
||||||
|
notes = {}
|
||||||
|
|
||||||
|
|
||||||
def firstsetup(url="", username=""):
|
def firstsetup(url="", username=""):
|
||||||
config = getconfig()
|
|
||||||
# Get URL
|
# Get URL
|
||||||
while True:
|
while True:
|
||||||
if url != "":
|
if url != "":
|
||||||
@ -62,13 +70,119 @@ def firstsetup(url = "", username = ""):
|
|||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def loadnotes():
|
||||||
|
global notes
|
||||||
|
notes = api.do("getnotes")["notes"]
|
||||||
|
|
||||||
|
|
||||||
|
def savenote(note):
|
||||||
|
api.do("savenote", {
|
||||||
|
"id": note["noteid"],
|
||||||
|
"text": note["content"]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
def editnote(note):
|
||||||
|
global editor
|
||||||
|
content = note["content"]
|
||||||
|
f = tempfile.NamedTemporaryFile(mode='w+')
|
||||||
|
f.write(content)
|
||||||
|
f.flush()
|
||||||
|
command = editor + " " + f.name
|
||||||
|
status = os.system(command)
|
||||||
|
f.seek(0, 0)
|
||||||
|
text = f.read()
|
||||||
|
f.close()
|
||||||
|
assert not os.path.exists(f.name)
|
||||||
|
note["content"] = text
|
||||||
|
clearscreen()
|
||||||
|
print(i18n.t("Saving..."))
|
||||||
|
savenote(note)
|
||||||
|
print(i18n.t("Note saved!"))
|
||||||
|
|
||||||
|
|
||||||
|
def editmenu():
|
||||||
|
global notes
|
||||||
|
clearscreen()
|
||||||
|
loadnotes()
|
||||||
|
i = 1
|
||||||
|
notelist = {}
|
||||||
|
for note in notes:
|
||||||
|
notelist[str(i)] = note
|
||||||
|
print(chr(27) + "[0m", end='')
|
||||||
|
print("\n\nNote #" + str(i) + ":")
|
||||||
|
setbghexcolor(note["color"])
|
||||||
|
setfgbybghex(note["color"])
|
||||||
|
linecount = 0
|
||||||
|
for line in note["content"].splitlines():
|
||||||
|
if linecount > 5:
|
||||||
|
print("\n(" + str(len(note["content"].splitlines())) + " more lines" + ")", end='')
|
||||||
|
break
|
||||||
|
print("\n " + line[0:70].ljust(70), end='')
|
||||||
|
if len(line) > 70:
|
||||||
|
print("...", end='')
|
||||||
|
linecount += 1
|
||||||
|
i += 1
|
||||||
|
resetcolor()
|
||||||
|
print("\n======================")
|
||||||
|
noteid = input(i18n.t("Note to edit (M for main menu): "))
|
||||||
|
if noteid.upper() == "M":
|
||||||
|
clearscreen()
|
||||||
|
return
|
||||||
|
editnote(notelist[noteid])
|
||||||
|
|
||||||
|
|
||||||
|
def newnote():
|
||||||
|
global editor
|
||||||
|
print()
|
||||||
|
f = tempfile.NamedTemporaryFile(mode='w+')
|
||||||
|
f.write("")
|
||||||
|
f.flush()
|
||||||
|
command = editor + " " + f.name
|
||||||
|
status = os.system(command)
|
||||||
|
f.seek(0, 0)
|
||||||
|
text = f.read()
|
||||||
|
f.close()
|
||||||
|
assert not os.path.exists(f.name)
|
||||||
|
if text == "":
|
||||||
|
clearscreen()
|
||||||
|
print(i18n.t("Nothing to do."))
|
||||||
|
return
|
||||||
|
print(i18n.t("Saving..."))
|
||||||
|
api.do("savenote", {
|
||||||
|
"text": text
|
||||||
|
})
|
||||||
|
print(i18n.t("Note created!"))
|
||||||
|
|
||||||
|
|
||||||
|
def mainmenu():
|
||||||
|
print("\n======================")
|
||||||
|
print(i18n.t("Main Menu"))
|
||||||
|
print("======================")
|
||||||
|
print("E. " + i18n.t("View and edit notes"))
|
||||||
|
print("C. " + i18n.t("Create a new note"))
|
||||||
|
print("Q. " + i18n.t("Exit"))
|
||||||
|
option = input(i18n.t("Choose an option: ")).upper()
|
||||||
|
clearscreen()
|
||||||
|
if option == "E":
|
||||||
|
editmenu()
|
||||||
|
elif option == "C":
|
||||||
|
newnote()
|
||||||
|
elif option == "Q":
|
||||||
|
exit(0)
|
||||||
|
else:
|
||||||
|
print(i18n.t("Unrecognized selection, try again."))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
print("NotePostCLI v1.0")
|
||||||
if not checkconfig():
|
if not checkconfig():
|
||||||
print(i18n.t("No valid settings file found, running setup wizard."))
|
print(i18n.t("No valid settings file found, running setup wizard."))
|
||||||
firstsetup()
|
firstsetup()
|
||||||
else:
|
else:
|
||||||
loadconfig()
|
loadconfig()
|
||||||
print(getconfig())
|
while True:
|
||||||
|
mainmenu()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
28
termcolors.py
Normal file
28
termcolors.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
from math import sqrt
|
||||||
|
|
||||||
|
|
||||||
|
def clearscreen():
|
||||||
|
print(chr(27) + "[2J", end='')
|
||||||
|
|
||||||
|
|
||||||
|
def resetcolor():
|
||||||
|
print(chr(27) + "[0m", end='')
|
||||||
|
|
||||||
|
|
||||||
|
def setbghexcolor(hex):
|
||||||
|
r = int(hex[0:2], 16)
|
||||||
|
g = int(hex[2:4], 16)
|
||||||
|
b = int(hex[4:6], 16)
|
||||||
|
print(chr(27) + "[48;2;" + str(r) + ";" + str(g) + ";" + str(b) + "m", end='')
|
||||||
|
|
||||||
|
|
||||||
|
def setfgbybghex(hex):
|
||||||
|
r = int(hex[0:2], 16)
|
||||||
|
g = int(hex[2:4], 16)
|
||||||
|
b = int(hex[4:6], 16)
|
||||||
|
contrast = sqrt(r * r * .241 + g * g * .691 + b * b * .068)
|
||||||
|
if contrast > 130:
|
||||||
|
print(chr(27) + "[38;30m", end='')
|
||||||
|
else:
|
||||||
|
print(chr(27) + "[38;97m", end='')
|
Loading…
x
Reference in New Issue
Block a user