Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93004

Re: Issuing a sqilte query, picking a random result, and copying to the system clipboard

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.021
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'win32': 0.03; 'plenty': 0.07; 'subject:query': 0.07; 'sqlite': 0.09; '(either': 0.16; '-tkc': 0.16; 'conn': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'sqlite3': 0.16; 'subject: \n ': 0.16; 'subject:random': 0.16; 'wrote:': 0.16; 'first,': 0.20; 'trying': 0.22; 'libraries': 0.22; 'tkinter': 0.22; 'select': 0.23; 'bit': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'appreciated.': 0.27; 'figure': 0.27; 'have,': 0.27; 'specify': 0.27; "i'm": 0.29; 'record': 0.29; 'random': 0.29; 'query': 0.31; 'source': 0.31; 'skip:s 30': 0.31; 'table': 0.32; 'another': 0.34; 'to:addr:python-list': 0.35; 'done': 0.35; 'something': 0.35; 'but': 0.36; 'too': 0.36; 'there': 0.36; 'quite': 0.37; 'received:10': 0.37; 'subject:: ': 0.37; 'charset:us-ascii': 0.37; 'doing': 0.38; 'things': 0.39; 'to:addr:python.org': 0.39; 'system.': 0.39; 'data': 0.40; 'subject:the': 0.40; 'your': 0.60; 'john': 0.61; 'simple': 0.61; 'limit': 0.65; 'elsewhere': 0.66; 'received:50': 0.66; 'facilities': 0.73; 'add-on': 0.84; 'anywhere.': 0.84; 'piping': 0.84; 'subject:system': 0.84; 'tricky': 0.93
X-Sender-Id wwwh|x-authuser|tim@thechases.com
X-Sender-Id wwwh|x-authuser|tim@thechases.com
X-MC-Relay Neutral
X-MailChannels-SenderId wwwh|x-authuser|tim@thechases.com
X-MailChannels-Auth-Id wwwh
X-MC-Loop-Signature 1434973898993:4213081756
X-MC-Ingress-Time 1434973898992
Date Mon, 22 Jun 2015 06:51:46 -0500
From Tim Chase <python.list@tim.thechases.com>
To python-list@python.org
Subject Re: Issuing a sqilte query, picking a random result, and copying to the system clipboard
In-Reply-To <CAJGLaBJvbJzYLTVoP0Vh4wWiCqzruUvPspo1QSA7g=V=JfSWTQ@mail.gmail.com>
References <CAJGLaBJvbJzYLTVoP0Vh4wWiCqzruUvPspo1QSA7g=V=JfSWTQ@mail.gmail.com>
X-Mailer Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu)
MIME-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AuthUser tim@thechases.com
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.706.1434978637.13271.python-list@python.org> (permalink)
Lines 32
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1434978637 news.xs4all.nl 2914 [2001:888:2000:d::a6]:44572
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:93004

Show key headers only | View raw


On 2015-06-21 17:08, John T. Haggerty wrote:
> I'm looking to just have a simple program that will do a SQLite
> query pull a random record and then copy that record too the
> clipboard the system. I'm not quite seeing how to do this perhaps
> this is already been done elsewhere but I spent quite a bit of time
> trying to figure out how to do that and I'm not seeing a listing
> anywhere. any help would be greatly appreciated.

First, connect to your data source and obtain a cursor:

  import sqlite3
  conn = sqlite3.connect('file.sqlite')
  cur = conn.cursor()

then select a random row:

  cur.execute("SELECT * FROM table ORDER BY RANDOM() LIMIT 1")
  data = cur.fetchone()

then things get tricky because you don't specify what OS you have, as
there are plenty of occasions when there is no system clipboard.

On Win32, you'd need the Win32 add-on libraries to shove things onto
the clipboard, while under X, you'd need other facilities (either
using Tkinter or piping to something like xclip(1)), and yet another
way of doing things on MacOS.

-tkc



Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Issuing a sqilte query, picking a random result, and copying to the system clipboard Tim Chase <python.list@tim.thechases.com> - 2015-06-22 06:51 -0500

csiph-web