aktuelle Scripte rein
This commit is contained in:
parent
f385bd0cbc
commit
77c5d31afc
4 changed files with 183 additions and 717 deletions
|
@ -6,111 +6,119 @@ from time import *
|
|||
from datetime import *
|
||||
|
||||
class DataBase:
|
||||
def connect(self):
|
||||
self.db = MySQLdb.connect(db="szene",\
|
||||
host="localhost", \
|
||||
user="szene", \
|
||||
passwd="szene", \
|
||||
use_unicode=1)
|
||||
print "Verbunden"
|
||||
def connect(self):
|
||||
self.db = MySQLdb.connect(db="szene",\
|
||||
host="localhost", \
|
||||
user="szene", \
|
||||
passwd="szene", \
|
||||
use_unicode=1)
|
||||
print "Verbindung zur DB steht"
|
||||
|
||||
def close (self):
|
||||
self.db.close()
|
||||
print "Verbindung getrennt"
|
||||
def close (self):
|
||||
self.db.close()
|
||||
print "Verbindung getrennt"
|
||||
|
||||
def get_latest_uid_category(self, type):
|
||||
c = self.db.cursor()
|
||||
sqlqueue="SELECT uid FROM tx_skcalendar_" + type
|
||||
c.execute(sqlqueue)
|
||||
j=1
|
||||
for i in c:
|
||||
if i[0] > j:
|
||||
j = i[0]
|
||||
print "latest uid for %s is: %i" % (type, j)
|
||||
return j
|
||||
def get_latest_uid_category(self, type):
|
||||
c = self.db.cursor()
|
||||
sqlqueue="SELECT uid FROM tx_skcalendar_" + type
|
||||
c.execute(sqlqueue)
|
||||
j=1
|
||||
for i in c:
|
||||
if i[0] > j:
|
||||
j = i[0]
|
||||
print "latest uid for %s is: %i" % (type, j)
|
||||
return j
|
||||
|
||||
def prepare_new_month(self):
|
||||
#TODO Monatsvorlage rekursiv kopieren
|
||||
# IDs der Kategorien aus config
|
||||
next_month = "Februar"
|
||||
parentid = 34
|
||||
doktype = 254
|
||||
perms_user = 31
|
||||
perms_group = 27
|
||||
hidden = 1
|
||||
tx_rgmenu_special = 5
|
||||
tstamp = str(int(mktime(datetime.now().timetuple())))
|
||||
sqlqueue="INSERT INTO `pages` (`pid`, `title`, `doktype`, `tstamp`, `perms_user`, `perms_group`, `hidden`, `tx_rgmenu_special`) \
|
||||
VALUES (" \
|
||||
+ "'" + parentid + "'" \
|
||||
+ "'" + next_month + "'" \
|
||||
+ "'" + doktype + "'" \
|
||||
+ "'" + tstamp + "'" \
|
||||
+ "'" + perms_user + "'" \
|
||||
+ "'" + perms_group + "'" \
|
||||
+ "'" + hidden + "'" \
|
||||
+ "'" + tx_rgmenu_special + "'" \
|
||||
+ "');"
|
||||
c.execute(sqlqueue)
|
||||
def prepare_new_month(self, month):
|
||||
#TODO Monatsvorlage rekursiv kopieren
|
||||
# IDs der Kategorien aus config
|
||||
next_month = str(month)
|
||||
parentid = str(34)
|
||||
doktype = str(254)
|
||||
perms_user = str(31)
|
||||
perms_group = str(27)
|
||||
hidden = str(1)
|
||||
tx_rgmenu_special = str(5)
|
||||
tstamp = str(int(mktime(datetime.now().timetuple())))
|
||||
sqlqueue="INSERT INTO `pages` (`pid`, `title`, `doktype`, `tstamp`, `perms_user`, `perms_group`, `hidden`, `tx_rgmenu_special`) \
|
||||
VALUES (" \
|
||||
+ "'" + parentid + "', " \
|
||||
+ "'" + next_month + "', " \
|
||||
+ "'" + doktype + "', " \
|
||||
+ "'" + tstamp + "', " \
|
||||
+ "'" + perms_user + "', " \
|
||||
+ "'" + perms_group + "', " \
|
||||
+ "'" + hidden + "', " \
|
||||
+ "'" + tx_rgmenu_special \
|
||||
+ "');"
|
||||
print sqlqueue
|
||||
c = self.db.cursor()
|
||||
c.execute(sqlqueue)
|
||||
|
||||
def prepare_event(self):
|
||||
'''hiermit wird eine neue Veranstaltung in passender Form
|
||||
fuer die VCE Extension vorbereitet'''
|
||||
## Testdatensaetze
|
||||
event_pid = "29"
|
||||
event_title = "Test2888888"
|
||||
event_title2= "Test2345345"
|
||||
event_description = "blablabla"
|
||||
event_startdate = str(int(mktime((datetime(2008,01,31,11,11,00)).timetuple())))
|
||||
event_targetgroup = "5"
|
||||
event_category = "1"
|
||||
event_organizer = "1"
|
||||
event_location = "1"
|
||||
event_tstamp = str(int(mktime(datetime.now().timetuple())))
|
||||
event_crdate = str(int(mktime(datetime.now().timetuple())))
|
||||
# felder ohne default wert mit leerem string besetzen
|
||||
event_image = ""
|
||||
event_link = ""
|
||||
event_exeptions = ""
|
||||
event_l18n_diffsource = ""
|
||||
# liste fuer alle datensaetze zusammenstellen
|
||||
#TODO aus xml holen
|
||||
event1 = (event_pid, event_title, event_description, event_startdate, event_targetgroup, event_category, event_organizer, event_location, event_tstamp, event_crdate, event_image, event_link, event_exeptions, event_l18n_diffsource)
|
||||
event2 = (event_pid, event_title2, event_description, event_startdate, event_targetgroup, event_category, event_organizer, event_location, event_tstamp, event_crdate, event_image, event_link, event_exeptions, event_l18n_diffsource)
|
||||
event_data = [ event1, event2 ]
|
||||
return event_data
|
||||
def prepare_event(self, event_dic):
|
||||
'''hiermit wird eine neue Veranstaltung in passender Form
|
||||
fuer die VCE Extension vorbereitet'''
|
||||
event_pid = "29"
|
||||
event_title = event_dic["WAS_XML"]
|
||||
event_description = event_dic["INFORMATION"]
|
||||
event_startdate = str(int(mktime((datetime(2008,01,31,11,11,00)).timetuple())))
|
||||
event_targetgroup = "5"
|
||||
event_category = "1"
|
||||
event_organizer = "1"
|
||||
event_location = "1"
|
||||
event_tstamp = str(int(mktime(datetime.now().timetuple())))
|
||||
event_crdate = str(int(mktime(datetime.now().timetuple())))
|
||||
## felder ohne default wert mit leerem string besetzen
|
||||
event_image = ""
|
||||
event_link = ""
|
||||
event_exeptions = ""
|
||||
event_l18n_diffsource = ""
|
||||
event1 = (event_pid, event_title, event_description, event_startdate, event_targetgroup, event_category, event_organizer, event_location, event_tstamp, event_crdate, event_image, event_link, event_exeptions, event_l18n_diffsource)
|
||||
#event2 = (event_pid, event_title2, event_description, event_startdate, event_targetgroup, event_category, event_organizer, event_location, event_tstamp, event_crdate, event_image, event_link, event_exeptions, event_l18n_diffsource)
|
||||
## liste fuer alle datensaetze zusammenstellen
|
||||
#event_data = [ event1, event2 ]
|
||||
#return event_data
|
||||
print event1
|
||||
return event1
|
||||
|
||||
def insert_event(self):
|
||||
'''den MySQL Befehl absetzen'''
|
||||
#sqlqueue="INSERT INTO `tx_skcalendar_event` (`pid`) VALUES ('29');"
|
||||
#c.execute(sqlqueue)
|
||||
"""
|
||||
sqlqueue="INSERT INTO `tx_skcalendar_event` (`pid` , `title`, `description`, `targetgroup`, `category`, `organizer`, `location`, `tstamp` , `crdate` ) VALUES (" \
|
||||
+ "'" + self.event_pid + "', "\
|
||||
+ "'" + self.event_title + "', "\
|
||||
+ "'" + self.event_description + "', "\
|
||||
+ "'" + self.event_targetgroup + "', "\
|
||||
+ "'" + self.event_category + "', "\
|
||||
+ "'" + self.event_organizer + "', "\
|
||||
+ "'" + self.event_location + "', "\
|
||||
+ "'" + self.event_tstamp + "', "\
|
||||
+ "'" + self.event_crdate \
|
||||
+ "');"
|
||||
"""
|
||||
c = self.db.cursor()
|
||||
data = self.prepare_event()
|
||||
print "folgende Datensaetze einfuegen:"
|
||||
for i in data:
|
||||
print i
|
||||
c.executemany("""INSERT INTO `tx_skcalendar_event` (`pid` , `title`, `description`, `startdate`, `targetgroup`, `category`, `organizer`, `location`, `tstamp` , `crdate`, `image`, `link`, `exeptions`, `l18n_diffsource`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""", data)
|
||||
def insert_event(self, dataset):
|
||||
'''den MySQL Befehl absetzen'''
|
||||
#sqlqueue="INSERT INTO `tx_skcalendar_event` (`pid`) VALUES ('29');"
|
||||
#c.execute(sqlqueue)
|
||||
'''
|
||||
sqlqueue="INSERT INTO `tx_skcalendar_event` (`pid` , `title`, `description`, `targetgroup`, `category`, `organizer`, `location`, `tstamp` , `crdate` ) VALUES (" \
|
||||
+ "'" + self.event_pid + "', "\
|
||||
+ "'" + self.event_title + "', "\
|
||||
+ "'" + self.event_description + "', "\
|
||||
+ "'" + self.event_targetgroup + "', "\
|
||||
+ "'" + self.event_category + "', "\
|
||||
+ "'" + self.event_organizer + "', "\
|
||||
+ "'" + self.event_location + "', "\
|
||||
+ "'" + self.event_tstamp + "', "\
|
||||
+ "'" + self.event_crdate \
|
||||
+ "');"
|
||||
print "folgende Datensaetze einfuegen:"
|
||||
for i in dataset:
|
||||
print i
|
||||
#c.executemany("""INSERT INTO `tx_skcalendar_event` (`pid` , `title`, `description`, `startdate`, `targetgroup`, `category`, `organizer`, `location`, `tstamp` , `crdate`, `image`, `link`, `exeptions`, `l18n_diffsource`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""", data)
|
||||
'''
|
||||
#data = self.prepare_event()
|
||||
c = self.db.cursor()
|
||||
c.executemany("""INSERT INTO `tx_skcalendar_event` (`pid` , `title`, `description`, `startdate`, `targetgroup`, `category`, `organizer`, `location`, `tstamp` , `crdate`, `image`, `link`, `exeptions`, `l18n_diffsource`) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)""", dataset)
|
||||
|
||||
def insert_organizer(self):
|
||||
#get_organizers_from_config()
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test = DataBase()
|
||||
test.connect()
|
||||
#test.get_latest_uid_category("organizer")
|
||||
test.insert_event()
|
||||
test.close()
|
||||
sys.exit(0)
|
||||
test = DataBase()
|
||||
test.connect()
|
||||
#test.get_latest_uid_category("organizer")
|
||||
datasource = XMLSource()
|
||||
#test.insert_event()
|
||||
test.close()
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
'''
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,6 +1,8 @@
|
|||
[Kategorien]
|
||||
## IDs der Kategorienvorlage
|
||||
Monatsvorlage = 58
|
||||
[Monat]
|
||||
pid = 89
|
||||
|
||||
[Kategorie]
|
||||
pid = 58
|
||||
Live = 67
|
||||
Sonstiges = 66
|
||||
Lesungen = 65
|
||||
|
@ -10,3 +12,11 @@ Familie = 61
|
|||
Party = 60
|
||||
Kino = 59
|
||||
|
||||
[Veranstalter]
|
||||
pid = 1
|
||||
|
||||
[Ort]
|
||||
pid = 1
|
||||
|
||||
[Zielgruppe]
|
||||
pid = 1
|
||||
|
|
|
@ -2,7 +2,67 @@
|
|||
"""
|
||||
this script fetches single nodes from a eventmanagement xml file
|
||||
"""
|
||||
from optparse import OptionParser
|
||||
from xml.dom.minidom import parse
|
||||
import mysql_connect
|
||||
|
||||
def main():
|
||||
usage = "usage: %prog [options] arg"
|
||||
parser = OptionParser(usage)
|
||||
parser.add_option("-f", "--file", dest="filename",
|
||||
help="read xml data from FILENAME")
|
||||
parser.add_option("-c", "--config", dest="configfile",
|
||||
help="read DB config from FILENAME")
|
||||
(options, args) = parser.parse_args()
|
||||
if options.filename:
|
||||
print "reading XML file: %s " % options.filename
|
||||
else:
|
||||
print parser.print_help()
|
||||
return
|
||||
dic = readXML(options.filename)
|
||||
|
||||
xmltags = ["INFORMATION", "WANN_START_XML", "WANN_ENDE", "WO_XML", "WAS_XML", "RUBRIK_XML", "SONSTIGES"]
|
||||
print
|
||||
print "XML Quelle: ", dic["FMPDSORESULT"]["DATABASE"]
|
||||
#print "Data 0", dic["FMPDSORESULT"]["ROW"][0]
|
||||
#print "Data 1", dic["FMPDSORESULT"]["ROW"][1]
|
||||
entry = 0
|
||||
days = 0
|
||||
data = []
|
||||
test = mysql_connect.DataBase()
|
||||
|
||||
for item in dic["FMPDSORESULT"]["ROW"]:
|
||||
entry += 1
|
||||
if len(item["DATUM"]) > 1:
|
||||
days +=1
|
||||
text = "\tDatum: %s" % item["DATUM"]
|
||||
#filename = "/tmp/szene"+str(days)
|
||||
#f = open(filename,mode="a")
|
||||
#f.write(text)
|
||||
#print text
|
||||
data.append(test.prepare_event(item))
|
||||
'''
|
||||
for content in xmltags:
|
||||
text = ("%s: %s") % (content, item[content])
|
||||
#f.write(text)
|
||||
print text
|
||||
'''
|
||||
|
||||
#f.close()
|
||||
|
||||
print "Tage durchlaufen: %i" % days
|
||||
entries = len(dic["FMPDSORESULT"]["ROW"])
|
||||
print "Eintraege insgesamt: %i" % entries
|
||||
if entries != entry:
|
||||
print "Es gibt %i Eintraege in der xml Datei aber nur %i wurden durchlaufen" % (entries, entry)
|
||||
|
||||
## finally put the mess into mysql db
|
||||
test.connect()
|
||||
print "Datenbank fuellen.."
|
||||
#test.prepare_new_month("Mai")
|
||||
#test.insert_event(data)
|
||||
test.close()
|
||||
|
||||
|
||||
|
||||
class NotTextNodeError:
|
||||
|
@ -74,28 +134,12 @@ def nodeToDic(node):
|
|||
return dic
|
||||
|
||||
|
||||
def readConfig(filename):
|
||||
def readXML(filename):
|
||||
dom = parse(filename)
|
||||
return nodeToDic(dom)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
dic = readConfig("source.xml")
|
||||
xmltags = ["INFORMATION", "WANN_START_XML", "WANN_ENDE", "WO_XML", "WAS_XML", "RUBRIK_XML", "SONSTIGES"]
|
||||
print
|
||||
print "Database", dic["FMPDSORESULT"]["DATABASE"]
|
||||
#for item in dic["Config"]["Items"]["Item"]:
|
||||
entry = 0
|
||||
days = 0
|
||||
for item in dic["FMPDSORESULT"]["ROW"]:
|
||||
entry += 1
|
||||
print entry
|
||||
if len(item["DATUM"]) > 1:
|
||||
days +=1
|
||||
print "Datum: %s" % item["DATUM"]
|
||||
for content in xmltags:
|
||||
print ("%s: %s") % (content, item[content])
|
||||
print
|
||||
|
||||
print "Tage: %s" % days
|
||||
main()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue