Very early and buggy publishing possibility
This commit is contained in:
parent
e2b1486ea1
commit
786962980b
5 changed files with 171 additions and 3 deletions
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.3 KiB |
105
modules/Create.py
Normal file
105
modules/Create.py
Normal file
|
@ -0,0 +1,105 @@
|
|||
# AGPL 3 or any later version
|
||||
# (C) J.Y.Amihud ( Blender Dumbass )
|
||||
|
||||
import os
|
||||
import json
|
||||
import time
|
||||
|
||||
from modules.Common import *
|
||||
from modules import Set
|
||||
|
||||
def Create(name):
|
||||
|
||||
# Creates a base directory before publishing.
|
||||
|
||||
if not name.count("/") == 1:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Wrong Format!")
|
||||
print('Use: $ python3 run.py --create articles/My_Article')
|
||||
|
||||
name = Simplify(name.split("/")[0])+"/"+Simplify(name.split("/")[1])
|
||||
|
||||
folder = Set.Folder()+"/editing"
|
||||
|
||||
try:
|
||||
os.makedirs(folder+"/"+name)
|
||||
except Exception as e:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Can't Create!", e)
|
||||
|
||||
# The text file
|
||||
text = open(folder+"/"+name+"/text.md", "w")
|
||||
text.close()
|
||||
|
||||
metadata = {
|
||||
"title":name.split("/")[1],
|
||||
"timestamp":time.time(),
|
||||
"description":"",
|
||||
"author":"",
|
||||
"thumbnail":"",
|
||||
"views":{
|
||||
"amount":0,
|
||||
"viewers":[],
|
||||
"dates":{}
|
||||
},
|
||||
"recording":"",
|
||||
"comments":{
|
||||
"comments":[],
|
||||
"requests":[]
|
||||
}
|
||||
}
|
||||
|
||||
with open(folder+"/"+name+"/metadata.json", "w") as save:
|
||||
json.dump(metadata, save, indent=4)
|
||||
|
||||
print(clr["bold"]+clr["tbyl"]+name+clr["norm"]+" is created of editing.")
|
||||
print(' To write text use: $ python3 run.py --write '+name)
|
||||
print('To edit metadata use: $ python3 run.py --metadata '+name)
|
||||
print(' To publish use: $ python3 run.py --publish '+name)
|
||||
|
||||
def Write(name):
|
||||
|
||||
if not name.count("/") == 1:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Wrong Format!")
|
||||
print('Use: $ python3 run.py --write articles/My_Article')
|
||||
|
||||
name = Simplify(name.split("/")[0])+"/"+Simplify(name.split("/")[1])
|
||||
|
||||
folder = Set.Folder()+"/editing/"+name
|
||||
|
||||
os.system(Set.Load().get("editor", "nano")+" "+folder+"/text.md")
|
||||
|
||||
def Metadata(name):
|
||||
|
||||
if not name.count("/") == 1:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Wrong Format!")
|
||||
print('Use: $ python3 run.py --metadata articles/My_Article')
|
||||
|
||||
name = Simplify(name.split("/")[0])+"/"+Simplify(name.split("/")[1])
|
||||
|
||||
folder = Set.Folder()+"/editing/"+name
|
||||
|
||||
os.system(Set.Load().get("editor", "nano")+" "+folder+"/metadata.json")
|
||||
|
||||
def Publish(name):
|
||||
|
||||
if not name.count("/") == 1:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Wrong Format!")
|
||||
print('Use: $ python3 run.py --publish articles/My_Article')
|
||||
|
||||
name = Simplify(name.split("/")[0])+"/"+Simplify(name.split("/")[1])
|
||||
|
||||
folder = Set.Folder()
|
||||
|
||||
source = folder+"/editing/"+name
|
||||
destination = folder+"/tabs/"+name
|
||||
|
||||
|
||||
|
||||
|
||||
try:
|
||||
|
||||
os.makedirs(folder+"/tabs/"+name)
|
||||
os.rename(source+"/text.md", destination+"/text.md")
|
||||
os.rename(source+"/metadata.json", destination+"/metadata.json")
|
||||
|
||||
except Exception as e:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Could not publish!", e)
|
|
@ -14,6 +14,8 @@ def Help():
|
|||
print(clr["tdyl"]+"--set"+clr["norm"]+" - Use for changing settings.")
|
||||
print(clr["tdyl"]+"--account"+clr["norm"]+" - Manage Accounts.")
|
||||
print()
|
||||
print(clr["tdyl"]+"--create"+clr["norm"]+" - Start a new article.")
|
||||
print()
|
||||
print(clr["tdyl"]+"--config"+clr["norm"]+" - Edit config file directly, bypassing --set.")
|
||||
print(clr["tdyl"]+"--folder"+clr["norm"]+" - Open the folder of the website's data.")
|
||||
print()
|
||||
|
@ -38,6 +40,8 @@ def Set():
|
|||
print(clr["tdyl"]+"--add_tab"+clr["norm"]+" - Adds a category of articles.")
|
||||
print(clr["tdyl"]+"--edit_tab"+clr["norm"]+" - Edit the config of a category.")
|
||||
print()
|
||||
print(clr["tdyl"]+"--editor"+clr["norm"]+" - Set editor. Default nano.")
|
||||
print()
|
||||
|
||||
def Accounts():
|
||||
|
||||
|
|
|
@ -96,6 +96,16 @@ def Set():
|
|||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Didn't specify the tor domain.")
|
||||
print('Use: $ python3 run.py --set --domain blenderdumbass.org')
|
||||
|
||||
if "--editor" in sys.argv:
|
||||
try:
|
||||
editor = sys.argv[ sys.argv.index("--editor") + 1]
|
||||
if "--" in editor: 1/0 # Failing this for the error message.
|
||||
Editor(editor)
|
||||
|
||||
except Exception as e:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Didn't specify the editor!")
|
||||
print('Use: $ python3 run.py --set --editor emacs')
|
||||
|
||||
|
||||
if "--port" in sys.argv:
|
||||
try:
|
||||
|
@ -186,6 +196,15 @@ def Tor(domain):
|
|||
|
||||
print(clr["bold"]+clr["tbyl"]+domain+clr["norm"]+" is set as tor domain.")
|
||||
|
||||
def Editor(editor):
|
||||
|
||||
data = Load()
|
||||
data["editor"] = editor
|
||||
|
||||
Save(data)
|
||||
|
||||
print(clr["bold"]+clr["tbyl"]+editor+clr["norm"]+" is set as the editor.")
|
||||
|
||||
|
||||
def Port(port):
|
||||
|
||||
|
@ -222,7 +241,7 @@ def AddTab(tab):
|
|||
def EditTab(tab):
|
||||
|
||||
tabsFolder = Folder()+"/tabs/"+Simplify(tab)
|
||||
os.system("nano "+tabsFolder+"/config.json")
|
||||
os.system(Load().get("editor", "nano")+" "+tabsFolder+"/config.json")
|
||||
|
||||
def SetCSS(filename):
|
||||
|
||||
|
|
44
run.py
44
run.py
|
@ -23,7 +23,7 @@ elif "--config" in sys.argv:
|
|||
from modules import Set
|
||||
data = Set.Load() # Making sure
|
||||
Set.Save(data) # that config.json exists
|
||||
os.system("nano "+Set.Folder()+"/config.json")
|
||||
os.system(Set.Load().get("editor", "nano")+" "+Set.Folder()+"/config.json")
|
||||
|
||||
elif "--run" in sys.argv:
|
||||
from modules import Run
|
||||
|
@ -34,10 +34,50 @@ elif "--folder" in sys.argv:
|
|||
|
||||
elif "--transfer" in sys.argv:
|
||||
try:
|
||||
folder = title = sys.argv[ sys.argv.index("--transfer") + 1]
|
||||
folder = sys.argv[ sys.argv.index("--transfer") + 1]
|
||||
if "--" in folder: 1/0 # Failing this for the error message.
|
||||
from modules import Legacy
|
||||
Legacy.Transfer(folder)
|
||||
except Exception as e:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Folder Wasn't Specified!", e)
|
||||
print('Use: $ python3 run.py --transfer ~/Software/blenderdumbass_site/')
|
||||
|
||||
elif "--create" in sys.argv:
|
||||
try:
|
||||
name = sys.argv[ sys.argv.index("--create") + 1]
|
||||
if "--" in name: 1/0 # Failing this for the error message.
|
||||
from modules import Create
|
||||
Create.Create(name)
|
||||
except Exception as e:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Name Wasn't Specified!", e)
|
||||
print('Use: $ python3 run.py --create article/My_Article')
|
||||
|
||||
elif "--write" in sys.argv:
|
||||
try:
|
||||
name = sys.argv[ sys.argv.index("--write") + 1]
|
||||
if "--" in name: 1/0 # Failing this for the error message.
|
||||
from modules import Create
|
||||
Create.Write(name)
|
||||
except Exception as e:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Name Wasn't Specified!", e)
|
||||
print('Use: $ python3 run.py --write article/My_Article')
|
||||
|
||||
elif "--metadata" in sys.argv:
|
||||
try:
|
||||
name = sys.argv[ sys.argv.index("--metadata") + 1]
|
||||
if "--" in name: 1/0 # Failing this for the error message.
|
||||
from modules import Create
|
||||
Create.Metadata(name)
|
||||
except Exception as e:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Name Wasn't Specified!", e)
|
||||
print('Use: $ python3 run.py --metadata article/My_Article')
|
||||
|
||||
elif "--publish" in sys.argv:
|
||||
try:
|
||||
name = sys.argv[ sys.argv.index("--publish") + 1]
|
||||
if "--" in name: 1/0 # Failing this for the error message.
|
||||
from modules import Create
|
||||
Create.Publish(name)
|
||||
except Exception as e:
|
||||
print(clr["bold"]+clr["tdrd"]+"Error:"+clr["norm"]+" Name Wasn't Specified!", e)
|
||||
print('Use: $ python3 run.py --publish article/My_Article')
|
||||
|
|
Loading…
Add table
Reference in a new issue