Sammlung
This commit is contained in:
3
Sammlung/Praktikum/3/ias_p2_b0.1/app/__init__.py
Normal file
3
Sammlung/Praktikum/3/ias_p2_b0.1/app/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
# coding: utf-8
|
||||
|
||||
# hier können Paket-Initialisierungen eingetragen werden
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
33
Sammlung/Praktikum/3/ias_p2_b0.1/app/chargen.py
Normal file
33
Sammlung/Praktikum/3/ias_p2_b0.1/app/chargen.py
Normal file
@@ -0,0 +1,33 @@
|
||||
# coding: utf-8
|
||||
|
||||
import time
|
||||
import codecs
|
||||
import json
|
||||
|
||||
from app import stream
|
||||
|
||||
class chargen_cl(object):
|
||||
exposed = True
|
||||
|
||||
chargenCounter = 1
|
||||
|
||||
def __init__(self):
|
||||
self.stream = stream.stream_cl()
|
||||
|
||||
def NEXT(self):
|
||||
if(self.chargenCounter > self.stream.anzChargen()):
|
||||
self.chargenCounter = 1
|
||||
|
||||
# timeout = 0
|
||||
# while(self.chargenCounter > self.stream.anzChargen()):
|
||||
# print(self.stream.anzChargen())
|
||||
# time.sleep(1)
|
||||
# timeout += 1
|
||||
# if(timeout > 3600):
|
||||
# return -1
|
||||
|
||||
newCharge = self.stream.loadCharge(self.chargenCounter)
|
||||
self.chargenCounter += 1
|
||||
|
||||
return json.dumps(newCharge)
|
||||
|
47
Sammlung/Praktikum/3/ias_p2_b0.1/app/log.py
Normal file
47
Sammlung/Praktikum/3/ias_p2_b0.1/app/log.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# coding: utf-8
|
||||
|
||||
import os
|
||||
import time
|
||||
import codecs
|
||||
import json
|
||||
|
||||
from app import stream
|
||||
|
||||
class log_cl(object):
|
||||
exposed = True
|
||||
|
||||
def __init__(self):
|
||||
self.stream = stream.stream_cl()
|
||||
|
||||
def SEND(self, user, charge, los, preis):
|
||||
|
||||
file = codecs.open(os.path.join('data', 'log.txt'), 'r', 'utf-8')
|
||||
log = json.loads(file.read())
|
||||
file.close()
|
||||
|
||||
counter = 1
|
||||
|
||||
for x in log:
|
||||
counter += 1
|
||||
|
||||
counter = str(counter)
|
||||
|
||||
log[counter] = {}
|
||||
log[counter]['user'] = user
|
||||
log[counter]['charge'] = charge
|
||||
log[counter]['los'] = los
|
||||
log[counter]['preis'] = preis
|
||||
log[counter]['time'] = time.time()
|
||||
|
||||
print(log)
|
||||
|
||||
file = codecs.open(os.path.join('data', 'log.txt'), 'w', 'utf-8')
|
||||
file.write(json.dumps(log, indent=3, ensure_ascii=True))
|
||||
file.close()
|
||||
|
||||
def REQ(self):
|
||||
file = codecs.open(os.path.join('data', 'log.txt'), 'r', 'utf-8')
|
||||
log = json.loads(file.read())
|
||||
file.close()
|
||||
|
||||
return json.dumps(log)
|
72
Sammlung/Praktikum/3/ias_p2_b0.1/app/manager.py
Normal file
72
Sammlung/Praktikum/3/ias_p2_b0.1/app/manager.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# coding: utf-8
|
||||
|
||||
import os
|
||||
import time
|
||||
import codecs
|
||||
import json
|
||||
|
||||
from app import stream
|
||||
|
||||
class manager_cl(object):
|
||||
exposed = True
|
||||
|
||||
def __init__(self):
|
||||
self.stream = stream.stream_cl()
|
||||
|
||||
def LIST(self):
|
||||
chargenliste = {}
|
||||
filenames = os.listdir('data')
|
||||
for filename in filenames:
|
||||
if filename.endswith('.json'):
|
||||
charge = codecs.open(os.path.join('data', filename), 'r', 'utf-8')
|
||||
chargeData = eval(charge.read())
|
||||
charge.close()
|
||||
|
||||
charge_id = filename[:-5]
|
||||
chargenliste[charge_id]={}
|
||||
chargenliste[charge_id]['chargeName'] = chargeData['info']['name']
|
||||
print(chargenliste)
|
||||
return json.dumps(chargenliste)
|
||||
|
||||
def GET(self, nr):
|
||||
data = {}
|
||||
data = self.stream.loadCharge(nr)
|
||||
return json.dumps(data)
|
||||
|
||||
def RECEIVE(self, dieCharge):
|
||||
dieCharge = json.loads(dieCharge)
|
||||
if dieCharge['info']['chargenNr'] == -1:
|
||||
filenames = os.listdir('data')
|
||||
maxNr = 0
|
||||
for filename in filenames:
|
||||
if filename.endswith('.json'):
|
||||
charge = codecs.open(os.path.join('data', filename), 'r', 'utf-8')
|
||||
chargeData = eval(charge.read())
|
||||
charge.close()
|
||||
|
||||
if maxNr < chargeData['info']['chargenNr']:
|
||||
maxNr = chargeData['info']['chargenNr']
|
||||
|
||||
dieCharge['info']['chargenNr'] = maxNr + 1
|
||||
name = str(maxNr + 1)
|
||||
name += '.json'
|
||||
|
||||
file = codecs.open(os.path.join('data', name), 'w', 'utf-8')
|
||||
file.write(json.dumps(dieCharge, indent = 3, ensure_ascii = True))
|
||||
file.close()
|
||||
|
||||
else:
|
||||
name = str(dieCharge['info']['chargenNr'])
|
||||
name += '.json'
|
||||
|
||||
file = codecs.open(os.path.join('data', name), 'w', 'utf-8')
|
||||
file.write(json.dumps(dieCharge, indent = 3, ensure_ascii = True))
|
||||
file.close()
|
||||
|
||||
def DELETE(self, nr):
|
||||
path = 'data/'
|
||||
path += str(nr)
|
||||
path += '.json'
|
||||
print(path)
|
||||
|
||||
os.remove(path)
|
31
Sammlung/Praktikum/3/ias_p2_b0.1/app/stream.py
Normal file
31
Sammlung/Praktikum/3/ias_p2_b0.1/app/stream.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# coding: utf-8
|
||||
import os
|
||||
import os.path
|
||||
import codecs
|
||||
import json
|
||||
|
||||
class stream_cl(object):
|
||||
exposed = True
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def loadCharge(self, id):
|
||||
filename = str(id)
|
||||
filename += '.json'
|
||||
|
||||
file = codecs.open(os.path.join('data', filename), 'r', 'utf-8')
|
||||
charge = file.read()
|
||||
file.close()
|
||||
|
||||
return charge
|
||||
|
||||
def anzChargen(self):
|
||||
files = os.listdir('data')
|
||||
fileCounter = 0
|
||||
|
||||
for file in files:
|
||||
if file.endswith('.json'):
|
||||
fileCounter += 1
|
||||
|
||||
return fileCounter
|
55
Sammlung/Praktikum/3/ias_p2_b0.1/app/template.py
Normal file
55
Sammlung/Praktikum/3/ias_p2_b0.1/app/template.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# coding: utf-8
|
||||
|
||||
|
||||
#not planned
|
||||
|
||||
import json
|
||||
|
||||
import os
|
||||
import codecs
|
||||
|
||||
import cherrypy
|
||||
|
||||
# Method-Dispatching!
|
||||
|
||||
# Übersicht Anforderungen / Methoden
|
||||
# (beachte: / relativ zu /template, siehe Konfiguration Server!)
|
||||
|
||||
"""
|
||||
|
||||
Anforderung GET PUT POST DELETE
|
||||
----------------------------------------------------------------
|
||||
/ Alle - - -
|
||||
Templates
|
||||
liefern
|
||||
|
||||
"""
|
||||
|
||||
#----------------------------------------------------------
|
||||
class Template_cl(object):
|
||||
#----------------------------------------------------------
|
||||
|
||||
exposed = True # gilt für alle Methoden
|
||||
|
||||
#-------------------------------------------------------
|
||||
def __init__(self):
|
||||
#-------------------------------------------------------
|
||||
pass
|
||||
|
||||
#-------------------------------------------------------
|
||||
def GET(self):
|
||||
#-------------------------------------------------------
|
||||
retVal_o = {
|
||||
'templates': {}
|
||||
}
|
||||
|
||||
files_a = os.listdir('templates/engine')
|
||||
for fileName_s in files_a:
|
||||
file_o = codecs.open(os.path.join('templates/engine', fileName_s), 'rU', 'utf-8')
|
||||
content_s = file_o.read()
|
||||
file_o.close()
|
||||
retVal_o["templates"][fileName_s] = content_s
|
||||
|
||||
return json.dumps(retVal_o)
|
||||
|
||||
# EOF
|
Reference in New Issue
Block a user