Difference between revisions of "User:Stefan/sqlite"

From Scribus Wiki
Jump to: navigation, search
(Mac Ports installed)
Line 1: Line 1:
 +
A notebook about my scripting experiments with scribus, python, python-sqlite bindings & sqlite one-file database.
 +
 +
==Why?==
 +
 +
Document creation automation
 +
 +
==Setup testing==
 +
 +
I want to use it on Mac Snow Lep. Tested & works so far
 +
 +
==Document Creation==
 +
 +
What the script should do:
 +
- Fill a scribus document, the "workdoc", with content from a sqlite database
 +
- Use another scribus doc, the "template", for general layout setup eg. fonts, page sizes
 +
- Use database to create pages, text and image frames in workdoc
 +
- Import text from a wiki, where the authors edit on it
 +
- Export text back to wiki, with wiki markup und frame info as needed
 +
 +
==Data Structure==
 +
<pre>
 +
 
 +
  create table if not exists beitrag(
 +
      id,
 +
      titel,
 +
      untertitel1,
 +
      untertitel2,
 +
      intro,
 +
      outro,
 +
      byline,
 +
      deadline,
 +
      notiz
 +
  );
 +
  create table if not exists beitragelement(
 +
      id,
 +
      typ,
 +
      untertitel,
 +
      seite,
 +
      x,y,h,b,
 +
      notiz
 +
  );
 +
  create table if not exists bildspeicher(
 +
      id,
 +
      rohdaten,
 +
      arbeitskopie
 +
  );
 +
  create table if not exists scribuselement(
 +
      id,
 +
      scribusname,
 +
      scribustyp,
 +
      notiz
 +
  );
 +
  create table if not exists geschrieben_von(
 +
      beitrag,
 +
      autor
 +
  );
 +
  create table if not exists textspeicher(
 +
      id,
 +
      text,
 +
      notiz
 +
  );
 +
  create table if not exists steht_auf(
 +
      beitrag,
 +
      seite
 +
  );
 +
  create table if not exists autor(
 +
      id,
 +
      name,
 +
      nick,
 +
      mail,
 +
      fon,
 +
      twitter,
 +
      wiki,
 +
      notiz
 +
  );
 +
  create table if not exists seite(
 +
      id,
 +
      seitenzahl,
 +
      inhalt,
 +
      notiz
 +
  );
 +
  """)
 +
</pre>
 +
 
This works in scribus scripter console
 
This works in scribus scripter console
  
<pre>
 
###############
 
  
import sqlite3
+
==Works with Windows==
+
at least with the bundled python and sqlite in Scribus 1.4.0rc5
con = sqlite3.connect('mydatabase.db')
+
 
cur = con.cursor()
+
==Works with Mac OS==
# cur.execute('CREATE TABLE foo (o_id INTEGER PRIMARY KEY, fruit VARCHAR(20), veges VARCHAR(30))')
+
Snow Leopard. The Scribus dmg package does not include working sqlite python bindings. Instead I use Scribus from Mac Ports.
# con.commit()
+
Scribus auto-compiled with Mac Ports, together with python and sqlite from Mac Ports.
cur.execute('INSERT INTO foo (o_id, fruit, veges) VALUES(NULL, "apple", "broccoli")')
 
con.commit()
 
print cur.lastrowid
 
cur.execute('SELECT * FROM foo')
 
print cur.fetchall()
 
</pre>
 

Revision as of 08:58, 25 June 2011

A notebook about my scripting experiments with scribus, python, python-sqlite bindings & sqlite one-file database.

Why?

Document creation automation

Setup testing

I want to use it on Mac Snow Lep. Tested & works so far

Document Creation

What the script should do: - Fill a scribus document, the "workdoc", with content from a sqlite database - Use another scribus doc, the "template", for general layout setup eg. fonts, page sizes - Use database to create pages, text and image frames in workdoc - Import text from a wiki, where the authors edit on it - Export text back to wiki, with wiki markup und frame info as needed

Data Structure

  
  create table if not exists beitrag(
      id,
      titel,
      untertitel1,
      untertitel2,
      intro,
      outro,
      byline,
      deadline,
      notiz
   );
   create table if not exists beitragelement(
      id,
      typ,
      untertitel,
      seite,
      x,y,h,b,
      notiz
   );
   create table if not exists bildspeicher(
      id,
      rohdaten,
      arbeitskopie
   );
   create table if not exists scribuselement(
      id,
      scribusname,
      scribustyp,
      notiz
   );
   create table if not exists geschrieben_von(
      beitrag,
      autor
   );
   create table if not exists textspeicher(
      id,
      text,
      notiz
   );
   create table if not exists steht_auf(
      beitrag,
      seite
   );
   create table if not exists autor(
      id,
      name,
      nick,
      mail,
      fon,
      twitter,
      wiki,
      notiz
   );
   create table if not exists seite(
      id,
      seitenzahl,
      inhalt,
      notiz
   );
   """)

This works in scribus scripter console


Works with Windows

at least with the bundled python and sqlite in Scribus 1.4.0rc5

Works with Mac OS

Snow Leopard. The Scribus dmg package does not include working sqlite python bindings. Instead I use Scribus from Mac Ports. Scribus auto-compiled with Mac Ports, together with python and sqlite from Mac Ports.