new functions

master
Your Name 6 years ago
parent 138b75009f
commit d8bfa3108f

@ -1,7 +1,7 @@
import requests import requests
import json import json
r = requests.get("http://127.0.0.1:5000/api/getcontent") r = requests.get("http://127.0.0.1:1234/api/getcontent")
data = r.json() data = r.json()
def getcategory(category): def getcategory(category):
@ -25,7 +25,21 @@ def getimages(category, number):
if counter == number: if counter == number:
images = data[post]["images"] images = data[post]["images"]
for image in images: for image in images:
output.append("http://127.0.0.1:5000"+image["url"]) output.append("http://127.0.0.1:1234"+image["url"])
counter+=1
return output
def getlinks(category, number):
counter = 1
output=[]
for post in data:
if data[post]["category"] == category:
if counter == number:
links = data[post]["removedLinks"]
for link in links:
item = data.get(link)
output.append(item['title'])
output.append(item['content'])
counter+=1 counter+=1
return output return output

@ -20,8 +20,12 @@ class Printer():
ESC = b'\x1B' ESC = b'\x1B'
FORMFEED = b'\x0C' FORMFEED = b'\x0C'
UNDERLINEDON = b'\x1B'+b'\x2D'+b'\x31' UNDERLINEDON = b'\x1B'+b'\x2D'+b'\x31'
UNDERLINEDOFF = b'\x1B'+b'\x2D'+b'\x30'
ITALICON = b'\x1B'+b'\x34' ITALICON = b'\x1B'+b'\x34'
ITALICOFF = b'\x1B'+b'\x35' ITALICOFF = b'\x1B'+b'\x35'
CPITWELF = b'\x1B'+b'\x4D'
NLQ= b'\x1B'+b'\x78'+b'\x31'
NLQ2 = b'\x1B'+b'\x6B'+b'\x01'
BOLDON = b'\x1B'+b'\x45' BOLDON = b'\x1B'+b'\x45'
BOLDOFF = b'\x1B'+b'\x46' BOLDOFF = b'\x1B'+b'\x46'
DHON = b'\x1B'+b'\x77'+b'\x01' DHON = b'\x1B'+b'\x77'+b'\x01'
@ -31,21 +35,22 @@ class Printer():
CHANGE_EMULATION = ESC+b'\x7B'+b'\x65' CHANGE_EMULATION = ESC+b'\x7B'+b'\x65'
LINE_FEED = b'\n' LINE_FEED = b'\n'
CARIDGE_RET = b'\x0D' CARIDGE_RET = b'\x0D'
CHARWIDTH = 78 CHARWIDTH = 70 #78 is actual, but -8 for safty
printedheight = 0 printedheight = 0
pages = 1 pages = 1
strokes = 0 strokes = 0
debug = True lineheight = 33
debug = False
target = "/dev/usb/lp0" target = "/dev/usb/lp0"
if debug: if debug:
target = "/dev/tty" target = "/dev/tty"
def formfeed(self): def formfeed(self, exit=False):
with open(self.target, 'wb') as printer: with open(self.target, 'wb') as printer:
if not self.debug: if not self.debug:
while self.checkpagebreak(printer) == False: while self.checkpagebreak(printer, exit) == False:
self.printedheight+=(44/216) self.printedheight+=(self.lineheight/216)
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
@ -62,7 +67,7 @@ class Printer():
self.strokes += 1 self.strokes += 1
if(self.strokes>self.CHARWIDTH): if(self.strokes>self.CHARWIDTH):
self.checkpagebreak(printer) self.checkpagebreak(printer)
self.printedheight+=(44/216) self.printedheight+=(self.lineheight/216)
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
self.strokes = 0 self.strokes = 0
@ -70,47 +75,101 @@ class Printer():
strokesinline = 0 strokesinline = 0
with open(self.target, 'wb') as printer: with open(self.target, 'wb') as printer:
if self.debug: if self.debug:
if formating == "compr":
self.CHARWIDTH = 120
else:
self.CHARWIDTH = 70
if formating == "u": if formating == "u":
printer.write(b"\x1B"+b"\x5B"+b"\x34"+b"\x6D") printer.write(b"\x1B"+b"\x5B"+b"\x34"+b"\x6D")
printer.write(bytes(str(string), 'utf-8')) printer.write(bytes(str(string), 'utf-8'))
printer.write(b"\x1B"+b"\x5B"+b"\x30"+b"\x6D") printer.write(b"\x1B"+b"\x5B"+b"\x30"+b"\x6D")
else: else:
for word in re.split(r'(\s+)', string): for word in re.split(r'(\s+)', string):
if "&&ref" in word and "&&endref" not in word:
subwords = word.split("&&ref")
word = subwords[1]
printer.write(b"\x1B"+b"\x5B"+b"\x34"+b"\x6D")
if "&&endref" in word:
subwords = word.split("&&endref")
word = subwords[1]
printer.write(b"\x1B"+b"\x5B"+b"\x30"+b"\x6D")
strokesinline += len(word) strokesinline += len(word)
if "\n" in word: if "\n" in word:
strokesinline = 0 strokesinline = 0
if strokesinline > self.CHARWIDTH: if strokesinline > self.CHARWIDTH:
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
strokesinline = len(word) strokesinline = len(word)
if not (strokesinline == 1 and word == " "): if strokesinline > self.CHARWIDTH:
firstpart = word[:self.CHARWIDTH]
secondpart = word[self.CHARWIDTH:]
printer.write(bytes(str(firstpart), 'utf-8'))
printer.write(self.LINE_FEED)
printer.write(bytes(str(secondpart), 'utf-8'))
elif not (strokesinline == 1 and word == " "):
printer.write(bytes(str(word), 'utf-8')) printer.write(bytes(str(word), 'utf-8'))
else: else:
printer.write(self.ESC+b"\x7B"+b"\x41") printer.write(self.ESC+b"\x7B"+b"\x41")
printer.write(self.ESC + b"\x33" + bytes([44])); printer.write(self.ESC + b"\x33" + bytes([self.lineheight]));
#printer.write(self.NLQ)
#printer.write(self.NLQ2)
self.CHARWIDTH = 70
if formating == "u": if formating == "u":
printer.write(self.BOLDON) printer.write(self.BOLDON)
if formating == "p":
printer.write(self.CPITWELF)
if formating == "i": if formating == "i":
printer.write(self.ITALICON) printer.write(self.ITALICON)
if formating == "dh": if formating == "dh":
printer.write(self.DHON) printer.write(self.DHON)
if formating == "compr": if formating == "compr":
printer.write(self.COMPRON) printer.write(self.COMPRON)
if self.printedheight > 11.69: self.CHARWIDTH = 120
printer.write(bytes(str("NEW PAGE YESY"), 'utf-8')); if formating == "compru":
self.printedheight=0 printer.write(self.UNDERLINEDON)
printer.write(self.COMPRON)
self.CHARWIDTH = 120
for word in re.split(r'(\s+)', string): for word in re.split(r'(\s+)', string):
if "&&ref" in word:
subwords = word.split("&&ref")
word = subwords[1]
printer.write(self.COMPRON)
if "&&endref" in word:
subwords = word.split("&&endref")
word = subwords[1]
printer.write(self.COMPROFF)
if "&&uline" in word:
subwords = word.split("&&uline")
word = subwords[1]
printer.write(self.UNDERLINEDON)
if "&&enduline" in word:
subwords = word.split("&&enduline")
word = subwords[1]
printer.write(self.UNDERLINEDOFF)
strokesinline += len(word) strokesinline += len(word)
if "\n" in word: if "\n" in word:
for _ in range(word.count("\n")):
strokesinline = 0 strokesinline = 0
self.printedheight+=(44/216) self.checkpagebreak(printer)
self.printedheight+=(self.lineheight/216)
if strokesinline > self.CHARWIDTH: if strokesinline > self.CHARWIDTH:
self.checkpagebreak(printer) self.checkpagebreak(printer)
self.printedheight+=(44/216) self.printedheight+=(self.lineheight/216)
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
strokesinline = len(word) strokesinline = len(word)
if not (strokesinline == 1 and word == " "): if strokesinline > self.CHARWIDTH:
printer.write(bytes(str(word), 'utf-8')) firstpart = word[:self.CHARWIDTH]
secondpart = word[self.CHARWIDTH:]
printer.write(bytes(str(firstpart), 'utf-8'))
self.checkpagebreak(printer)
self.printedheight+=(self.lineheight/216)
printer.write(self.LINE_FEED)
printer.write(bytes(str(secondpart), 'utf-8'))
elif not (strokesinline == 1 and word == " "):
printer.write(str(word).encode("ascii","ignore"))
if formating == "u": if formating == "u":
printer.write(self.BOLDOFF) printer.write(self.BOLDOFF)
if formating == "i": if formating == "i":
@ -119,7 +178,10 @@ class Printer():
printer.write(self.DHOFF) printer.write(self.DHOFF)
if formating == "compr": if formating == "compr":
printer.write(self.COMPROFF) printer.write(self.COMPROFF)
printer.write(self.ESC+b"\x25"+b"\x46"+b"\x0F"+b"\x00"+b"\x04"+b"\x08"+b"\x00") if formating == "compru":
printer.write(self.COMPROFF)
printer.write(self.UNDERLINEDOFF)
#printer.write(self.ESC+b"\x25"+b"\x46"+b"\x0F"+b"\x00"+b"\x04"+b"\x08"+b"\x00")
try: try:
self.newline() self.newline()
except: except:
@ -131,26 +193,31 @@ class Printer():
with open(self.target, 'wb') as printer: with open(self.target, 'wb') as printer:
if not self.debug: if not self.debug:
self.checkpagebreak(printer) self.checkpagebreak(printer)
printer.write(self.ESC + b"\x33" + bytes([44])); printer.write(self.ESC + b"\x33" + bytes([self.lineheight]));
self.printedheight+=(44/216) self.printedheight+=(self.lineheight/216)
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
self.strokes = 0 self.strokes = 0
def checkpagebreak(self, printer): def checkpagebreak(self, printer, exit=False):
if self.printedheight+(44/216)*4 > 11.69: print(self.printedheight)
if self.printedheight+(self.lineheight/216)*4 > 11.69:
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
printer.write(bytes(str("PAGE "+str(self.pages)), 'utf-8')); printer.write(bytes(str("PAGE "+str(self.pages)), 'utf-8'));
printer.write(self.ESC + b"\x33" + bytes([44])); printer.write(self.ESC + b"\x33" + bytes([self.lineheight]));
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
if not exit:
printer.write(self.COMPRON) printer.write(self.COMPRON)
printer.write(bytes(str("------------------------------------------------------ POETIC SOFTWARE PUBLICATION -----------------------------------------------------"), 'utf-8')); printer.write(bytes(str("------------------------------------------------------ POETIC SOFTWARE PUBLICATION -----------------------------------------------------"), 'utf-8'));
printer.write(self.COMPROFF) printer.write(self.COMPROFF)
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
self.printedheight=(44/216) self.printedheight=(self.lineheight/216)
self.pages+=1 self.pages+=1
else:
self.printedheight=0
self.pages=1
return True return True
else: else:
return False return False
@ -163,26 +230,28 @@ class Printer():
f.write(page.content) f.write(page.content)
if self.debug: if self.debug:
rows, columns = os.popen('stty size', 'r').read().split() #rows, columns = os.popen('stty size', 'r').read().split()
#subprocess.call(["catimg","-w",columns,f_name]) #subprocess.call(["catimg","-w",columns,f_name])
subprocess.call(["feh",f_name]) subprocess.call(["feh",f_name])
else: else:
imagelines = imageprinter.print(f_name,True) imagelines = imageprinter.print(f_name,True)
isodd = False #((imagelines*22)%self.lineheight)/11
if imagelines % 2 == 1:
isodd = True if self.printedheight + (22/216)*imagelines +(self.lineheight/216)*4 > 11.69:
imagelines+=1
if self.printedheight + (22/216)*imagelines +(44/216)*4 > 11.69:
self.formfeed() self.formfeed()
self.printedheight += (22/216)*imagelines self.printedheight += (22/216)*imagelines
imageprinter.print(f_name) imageprinter.print(f_name)
if isodd:
with open('/dev/usb/lp0', 'wb') as printer: with open('/dev/usb/lp0', 'wb') as printer:
printer.write(ESC + b"\x33" + bytes([22])); printer.write(self.ESC + b"\x33" + bytes([11]));
for _ in range(int(((imagelines*22)%self.lineheight)/11)):
printer.write(self.LINE_FEED) printer.write(self.LINE_FEED)
printer.write(ESC + b"\x33" + bytes([44])); self.printedheight += (11/216)
print(imagelines)
print(((imagelines*22)%self.lineheight)/11)
printer.write(self.ESC + b"\x33" + bytes([self.lineheight]));
self.newline()
# 10 lines 220
class Terminal(): class Terminal():
@ -251,16 +320,16 @@ class Terminal():
self.printer.printstring(out.decode("utf-8")) self.printer.printstring(out.decode("utf-8"))
def list(self): def list(self):
printer.printstring("theses on POETIC SOFTWARE", "u") self.printer.printstring("theses on POETIC SOFTWARE", "u")
result = apirequest.getcategory("thesis") result = apirequest.getcategory("thesis")
for i, line in enumerate(result): for i, line in enumerate(result):
printer.printstring(str(i+1)+" "+line) printer.printstring(str(i+1)+" "+line)
printer.newline() self.printer.newline()
printer.printstring("exercises in POETIC SOFTWARE","u") self.printer.printstring("exercises in POETIC SOFTWARE","u")
result = apirequest.getcategory("exercise") result = apirequest.getcategory("exercise")
for i, line in enumerate(result): for i, line in enumerate(result):
printer.printstring(str(i+1)+" "+line) printer.printstring(str(i+1)+" "+line)
printer.newline() self.printer.newline()
def command(self, command): def command(self, command):
#print("received command: "+str(command)) #print("received command: "+str(command))
@ -278,7 +347,7 @@ class Terminal():
main() main()
elif "ff" == str(command): elif "ff" == str(command):
printer.formfeed() self.printer.formfeed()
elif str(command).split(" ")[0] == "exercise" or str(command).split(" ")[0] == "thesis": elif str(command).split(" ")[0] == "exercise" or str(command).split(" ")[0] == "thesis":
part = str(command).split(" ")[0] part = str(command).split(" ")[0]
@ -293,17 +362,26 @@ class Terminal():
if number > len(apirequest.getcategory(part)): if number > len(apirequest.getcategory(part)):
self.printer.printstring("Number must be inbetween 1 and "+ str(len(apirequest.getcategory(part)))) self.printer.printstring("Number must be inbetween 1 and "+ str(len(apirequest.getcategory(part))))
else: else:
result = apirequest.getimages(part, number)
for img in result:
printer.printimagefromurl(img)
result = apirequest.gettitle(part, number) result = apirequest.gettitle(part, number)
for line in result: for line in result:
self.printer.printstring(line, "u") self.printer.printstring(line, "u")
result = apirequest.getimages(part, number)
for img in result:
self.printer.printimagefromurl(img)
#get and print content of thesis or exercise
result = apirequest.getcontent(part, number) result = apirequest.getcontent(part, number)
for line in result: for line in result:
self.printer.printstring(line) self.printer.printstring(line)
#check for specific things like the wifi
if apirequest.gettitle(part, number)[0] == "Wifi Poem": if apirequest.gettitle(part, number)[0] == "Wifi Poem":
self.scanwifi() self.scanwifi()
result = apirequest.getlinks(part, number)
self.printer.newline()
for i, line in enumerate(result):
if i%2 == 0:
self.printer.printstring(line, "compru")
else:
self.printer.printstring(line, "compr")
self.printer.newline() self.printer.newline()
else: else:
self.printer.printstring("not a number") self.printer.printstring("not a number")
@ -324,12 +402,11 @@ class Terminal():
self.waitforinput(nocommand=True) self.waitforinput(nocommand=True)
self.printer.newline() self.printer.newline()
self.printer.printstring("Special thanks to Aymeric Mansoux, Marloes de Valk, Michael Murtaugh, André Castro, Clara Balaguer, Amy Suo Wu, Leslie Robbins, Angeliki, Alice, Tash, Zalan, Joca, Jule") self.printer.printstring("Special thanks to Aymeric Mansoux, Marloes de Valk, Michael Murtaugh, André Castro, Clara Balaguer, Amy Suo Wu, Leslie Robbins, Angeliki, Alice, Tash, Zalan, Joca, Jule")
self.printer.newline() self.printer.formfeed(True)
main() main()
else: else:
self.printer.printstring("~ command not found. try help for a list of available commands") self.printer.printstring("~ command not found. type help for a list of available commands")
self.printer.newline() self.printer.newline()
#if the command is valid we want to execute the command and continue the story #if the command is valid we want to execute the command and continue the story
@ -338,34 +415,58 @@ class Terminal():
persons = { persons = {
"Kittler":"Friedrich A. Kittler (June 12, 1943 October 18, 2011) was a literary scholar and a media theorist. His works relate to media, technology, and the military. ", "Kittler":"Friedrich A. Kittler (June 12, 1943 October 18, 2011) was a literary scholar and a media theorist. His works relate to media, technology, and the military. ",
"Alex":"Alexander Roidl created Poetic Software as part of his Master's thesis.", "Alex":"Alexander Roidl created Poetic Software as part of his Master's thesis.",
"Michael":"Michael Murtaugh is an independent computer programmer (automatist.org) and a member of Constant Art & Media (constantvzw.org) in Brussels where he lives.",
"Aymeric":"Aymeric Mansoux (FR) is an artist, musician and media researcher, with a background in economics, fine art, graphic design, and computer programming. ",
"Jule":"Jule Ulrych is an evironmental activist and passionate vegan food lover living in Den Haag." "Jule":"Jule Ulrych is an evironmental activist and passionate vegan food lover living in Den Haag."
} }
printer = Printer() printer = Printer()
term = Terminal(printer, persons) term = Terminal(printer, persons)
now = datetime.datetime.now() now = datetime.datetime.now()
ascii = '''::::::::: :::::::: :::::::::: ::::::::::: ::::::::::: ::::::::
:+: :+: :+: :+: :+: :+: :+: :+: :+:
+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+
+#++:++#+ +#+ +:+ +#++:++# +#+ +#+ +#+
+#+ +#+ +#+ +#+ +#+ +#+ +#+
#+# #+# #+# #+# #+# #+# #+# #+#
### ######## ########## ### ########### ########
:::::::: :::::::: :::::::::: ::::::::::: ::: ::: ::: ::::::::: ::::::::::
:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:
+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+
+#++:++#++ +#+ +:+ :#::+::# +#+ +#+ +:+ +#+ +#++:++#++: +#++:++#: +#++:++#
+#+ +#+ +#+ +#+ +#+ +#+ +#+#+ +#+ +#+ +#+ +#+ +#+ +#+
#+# #+# #+# #+# #+# #+# #+#+# #+#+# #+# #+# #+# #+# #+#
######## ######## ### ### ### ### ### ### ### ### ##########
SOFTWARE & ART'''
def main(): def main():
term.waittostart() term.waittostart()
printer.printstring(ascii, "compr")
printer.formfeed();
printer.newline()
printer.printstring("W E L C O M E !", "dh") printer.printstring("W E L C O M E !", "dh")
printer.newline() printer.newline()
printer.printstring(now.strftime("%Y-%m-%d %H:%M"), "compr") printer.printstring(now.strftime("%Y-%m-%d %H:%M"), "compr")
printer.newline() printer.newline()
# printer.formfeed() #
printer.printimagefromurl("https://www.sanfranciscobaycoffee.com/wp-content/uploads/2017/03/52279468.jpg") # # printer.formfeed()
# printer.printstring("---------------") printer.printstring("---------------")
# printer.printstring("POETIC SOFTWARE") printer.printstring("POETIC SOFTWARE")
# printer.printstring("---------------") printer.printstring("---------------")
# printer.printstring("type help for help") printer.printstring("type help for help")
# printer.newline() printer.newline()
# result = apirequest.gettitle("introduction", 1) result = apirequest.gettitle("introduction", 1)
# for line in result: for line in result:
# printer.printstring(line, "u") printer.printstring(line, "u")
# result = apirequest.getcontent("introduction", 1) result = apirequest.getcontent("introduction", 1)
# for line in result: for line in result:
# printer.printstring(line) printer.printstring(line)
printer.newline() printer.newline()
# term.list() term.list()
printer.printstring("SELECT which one to see, for exercise type: exercise <number> and for thesis type: thesis <number>") printer.printstring("SELECT which one to see, for exercise type: exercise <number> and for thesis type: thesis <number>")
printer.newline() printer.newline()
term.waitforinput() term.waitforinput()

Loading…
Cancel
Save