From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Wed, 3 Sep 2003 19:11:45 +0400 From: "Alexey I. Froloff" To: ALT Devel discussion list Subject: Re: [devel] Re: new fortune package? Message-ID: <20030903151145.GA7019@hell.devel.altlinux.ru> Mail-Followup-To: ALT Devel discussion list References: <20030831124626.GC27873@altlinux.ru> <20030901074218.GU32290@inferno.immo> <20030901140715.47af1e1a.vyt@vzljot.ru> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="qlTNgmc+xy1dBmNv" Content-Disposition: inline In-Reply-To: <20030901140715.47af1e1a.vyt@vzljot.ru> User-Agent: Mutt/1.4.1i X-BeenThere: devel@altlinux.ru X-Mailman-Version: 2.1.2 Precedence: list Reply-To: ALT Devel discussion list List-Id: ALT Devel discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Sep 2003 15:18:24 -0000 Archived-At: List-Archive: List-Post: --qlTNgmc+xy1dBmNv Content-Type: multipart/mixed; boundary="0F1p//8PRICkK4MW" Content-Disposition: inline --0F1p//8PRICkK4MW Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Sep 01, 2003 at 02:07:15PM +0400, Vitaly Ostanin wrote: > > =F1 =D3=CF =D3=D7=CF=C5=CA =D3=D4=CF=D2=CF=CE=D9 =CD=CF=C7=D5 =D0=CF=C4= =C5=CC=C9=D4=D8=D3=D1 =D3=D4=D2=D5=CB=D4=D5=D2=CF=CA =D0=CF=D3=D4=D2=C5=D3= =CF=D7=CF=CA =C2=C1=DA=D9 > > =C9 =CE=C1=CB=CF=CC=C5=CE=CE=D9=CD =D3=CB=D2=C9=D0=D4=C9=CB=CF=CD =CE= =C1 ruby =C4=CC=D1 =C4=CF=C2=C1=D7=CC=C5=CE=C9=D1 =C9 =CF=C2=D2=C1=C2=CF=D4= =CB=C9 > > =C3=C9=D4=C1=D4;-) > =ED=CF=D6=CE=CF =D7 =CD=C5=CE=D1 =C2=D2=CF=D3=C9=D4=D8? =E4=CC=D1 =C4=D2= =D5=C7=C9=C8 =C3=C9=D4=C1=D4 :) =F7=CF=D4 =D0=D2=D1=CD =D7 =D2=C1=D3=D3=D9=CC=CB=D5 =C9 =C2=D2=CF=DB=D5. =F0=CF=D3=D4=C7=D2=C5=D3=CF=D7=C1=D1 =C2=C1=DA=C1 (=CF=C4=CE=C1 =D4=C1=C2= =CC=C9=C3=C1): CREATE TABLE altlinux ( id serial NOT NULL, text text NOT NULL, author character varying(20) NOT NULL, list character varying(20) NOT NULL, confirmed boolean DEFAULT false NOT NULL ); CREATE UNIQUE INDEX text_altlinux_ukey ON altlinux USING btree (text); =F3=CB=D2=C9=D0=D4 =D7 =C1=D4=D4=C1=DE=C5. --=20 Regards, Sir Raorn. --0F1p//8PRICkK4MW Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=quotes #! /usr/bin/ruby -w require 'postgres' if ARGV.size < 2 then puts "Usage: quotes TABLE command [args...]" exit(1) end pghost = nil pgport = nil pgoptions = nil pgtty = nil dbname = "fortunes" table = ARGV[0] command = ARGV[1] begin conn = PGconn.connect(pghost,pgport,pgoptions,pgtty,dbname) case command when "get" res = conn.exec("SELECT convert(\"text\", 'KOI8-R', 'UTF-8') as \"text\", \"author\", \"list\" FROM \"#{table}\" WHERE \"confirmed\" = 't' ORDER BY \"id\" ASC") if res.status == PGresult::TUPLES_OK then res.result.each { |q| puts "#{q[0]}\n\t\t-- #{q[1]} in #{q[2]}@\n%" } end when "show" if ARGV.size != 3 then printf "Usage: quotes TABLE show ID" else res = conn.exec("SELECT \"id\", \"text\", \"author\", \"list\", \"confirmed\" FROM \"#{table}\" WHERE \"id\" = #{ARGV[2]}") if res.status == PGresult::TUPLES_OK and res.result.size == 1 then puts "Id: #{res.result[0][0]}" puts "Author: #{res.result[0][2]}" puts "List: #{res.result[0][3]}@" puts "Status: #{res.result[0][4] == 't' ? "OK" : "UNCONFIRMED"}" puts "Text:\n#{res.result[0][1]}" else if res.result.size == 0 then puts "No such quote" else printf(STDERR, conn.error) end end end when "stats" res = conn.exec("SELECT \"author\", \"list\" FROM \"#{table}\" WHERE \"confirmed\" = 't'") if res.status == PGresult::TUPLES_OK and res.result.size > 0 then qpa = Hash.new(0) qpl = Hash.new(0) total = 0 res.result.each { |q| qpa[q[0]] += 1 qpl[q[1]] += 1 total += 1 } puts "Quotes per author:" qpa.keys.sort.each { |k| printf "%-10s - %d\n", k, qpa[k] } puts "\nQuotes per list:" qpl.keys.sort.each { |k| printf "%-15s - %d\n", k, qpl[k] } puts "\nTotal: #{total}" end when "unconfirmed" res = conn.exec("SELECT \"id\", \"author\", \"list\" FROM \"#{table}\" WHERE \"confirmed\" = 'f' ORDER BY \"id\" ASC") if res.status == PGresult::TUPLES_OK and res.result.size > 0 then total = 0 res.result.each { |q| printf "%5d - %s in %s@\n", q[0], q[1], q[2] total += 1 } puts "Total: #{total}" else if res.result.size == 0 then puts "No unconfirmed quotes" else printf(STDERR, conn.error) end end when "add" if ARGV.size != 4 then printf "Usage: quotes TABLE add AUTHOR LIST" else author = ARGV[2] list = ARGV[3] text = "" puts "Adding quote by #{author} from #{list}@" puts "Enter text, end with ^D" $stdin.each_line { |l| text << l } text.chomp! puts "\nAdding:" puts text puts "\t\t-- #{author} in #{list}@" #puts "INSERT INTO \"#{table}\" (\"text\", \"author\", \"list\") VALUES ('#{text.gsub(/([\\'])/, '\\\\\1')}', '#{author}', '#{list}')" conn.exec("INSERT INTO \"#{table}\" (\"text\", \"author\", \"list\") VALUES ('#{text.gsub(/([\\'])/, '\\\\\1')}', '#{author}', '#{list}')") end when "confirm" if ARGV.size != 3 then printf "Usage: quotes TABLE confirm ID" else conn.exec("UPDATE \"#{table}\" SET \"confirmed\"='t' WHERE \"id\" = #{ARGV[2]}") end end conn.close rescue PGError if (conn == nil or conn.status == PGconn::CONNECTION_BAD) printf(STDERR, "We have lost the connection to the backend, so ") printf(STDERR, "further processing is impossible.\n") printf(STDERR, "Terminating.\n") else printf(STDERR, conn.error) end exit(1) end --0F1p//8PRICkK4MW-- --qlTNgmc+xy1dBmNv Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.2 (GNU/Linux) iD8DBQE/VgSxVqT7+fkT8woRAq29AKDWCfcGT9bAeRlRlznkaCBk7U4TzACg4vuQ PZ+qYssWN+KbzoePqQfcPIc= =fi27 -----END PGP SIGNATURE----- --qlTNgmc+xy1dBmNv--