shutil module (directory input)

2009-01-26 Thread klia

hello folks

i am trying to tweak the current codes so that later when i call it from the
terminal i can provide sourcefile and the destination file rather being
fixed in the code.becuase now i have to specify the sourcefile and the
destinationfile in codes and not left to be specified from the terminal. i
want to be able to do this.

python shutil_copy.py sourcefile, destinationfile

code
import shutil
shutil.copyfile(srcfile, dstfile) # copy data only

-- 
View this message in context: 
http://www.nabble.com/shutil-module-%28directory-input%29-tp21679178p21679178.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list


pysqlite smart search

2009-02-23 Thread klia

 Hey guys;

I am trying to develop a tiny program using python to search inside sqlite
database with file extension is .db in which the program will ask users to
enter their search query and base on that it will retrieve the results But

I need the program to have some smartness in search mechanism in which the
program will guess that the user is looking for these key words in the
database.

so far i came up with this but the search ain't smart, i have to write the
full key word in order to retrieve specific information.

from pysqlite2 import dbapi2 as sqlite3

connection = sqlite3.connect('Photos.db')
memoryConnection = sqlite3.connect(':memory:')
cursor = connection.cursor()
prompt = 'Enter your search query?\n'
keyword = raw_input(prompt)
if cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?',[keyword]):
print cursor.fetchall()
else:
cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', [keyword])
print cursor.fetchall()

Any ideas and
thanks in advance
Reply
-- 
View this message in context: 
http://www.nabble.com/pysqlite-smart-search-tp22157116p22157116.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list


importing csv file into sqlite

2008-12-17 Thread klia

hey guys, i have a hug .csv file which i need to insert it into sqlite
database using python.
my csv data looks like this 
Birthday2,12/5/2008,HTC,this is my birthday
Sea,12/3/2008,kodak,sea
birthday4,14/3/2009,samsung,birthday
love,17/4/2009,SONY,view of island

can any one give me a head start codes.

thanks in advance
-- 
View this message in context: 
http://www.nabble.com/importing-csv-file-into-sqlite-tp21067453p21067453.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list


Re: importing csv file into sqlite

2008-12-17 Thread klia



klia wrote:
> 
> hey guys, i have a hug .csv file which i need to insert it into sqlite
> database using python.
> my csv data looks like this 
> Birthday2,12/5/2008,HTC,this is my birthday
> Sea,12/3/2008,kodak,sea
> birthday4,14/3/2009,samsung,birthday
> love,17/4/2009,SONY,view of island
> 
> can any one give me a head start codes.
> 
> thanks in advance
> 
guys so far i came out with this but i get this error
was...@linux:~/Project2$ python experment.py 
Traceback (most recent call last):
  File "experment.py", line 13, in 
curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item)
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current
statement uses 4, and there are 1 supplied.

here's the codes

import sqlite3
import csv

f = open('/home/waseem/Project2/photos.txt')
csv.field_size_limit(10) #see below!
input = csv.reader(f, delimiter='\t')
conn = sqlite3.connect('/home/waseem/Project2/picutres.db')
curse = conn.cursor()

curse.execute('CREATE TABLE photos (Name VARCHAR(100) PRIMARY KEY, Date
INTEGER, Make VARCHAR(50), Tag VARCHAR(100))')

for item in input:
curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item)
curse.commit()

-- 
View this message in context: 
http://www.nabble.com/importing-csv-file-into-sqlite-tp21067453p21068111.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list


Re: importing csv file into sqlite

2008-12-19 Thread klia


John Machin wrote:
> 
> On Dec 18, 6:20 pm, klia  wrote:
>> klia wrote:
>>
>> > hey guys, i have a hug .csv file which i need to insert it into sqlite
>> > database using python.
>> > my csv data looks like this
>> > Birthday2,12/5/2008,HTC,this is my birthday
>> > Sea,12/3/2008,kodak,sea
>> > birthday4,14/3/2009,samsung,birthday
>> > love,17/4/2009,SONY,view of island
>>
>> > can any one give me a head start codes.
>>
>> > thanks in advance
>>
>> guys so far i came out with this but i get this error
>> was...@linux:~/Project2$ python experment.py
>> Traceback (most recent call last):
>>   File "experment.py", line 13, in 
>>     curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item)
>> sqlite3.ProgrammingError: Incorrect number of bindings supplied. The
>> current
>> statement uses 4, and there are 1 supplied.
>>
>> here's the codes
>>
>> import sqlite3
>> import csv
>>
>> f = open('/home/waseem/Project2/photos.txt')
>> csv.field_size_limit(10) #see below!
> 
> I see nothing "below" that looks at all like an attempt to justify
> setting the field size limit to 10 -- why are you doing that?
> Tends to make one suspect a problem with your delimiter and/or your
> line separator.
> 
>> input = csv.reader(f, delimiter='\t')
> 
> Why \t??? Your data examples show commas -- could this be why you are
> getting one field per line (as Peter has pointed out)?
> 
>> conn = sqlite3.connect('/home/waseem/Project2/picutres.db')
> 
> Is it really called "picutres" instead of "pictures", or are you
> typing the code that you ran again from (your) memory?
> 
>> curse = conn.cursor()
>>
>> curse.execute('CREATE TABLE photos (Name VARCHAR(100) PRIMARY KEY, Date
>> INTEGER, Make VARCHAR(50), Tag VARCHAR(100))')
> 
> [OT but to save the next question]
> The column named "Date" is defined to be INTEGER but the data from the
> CSV file will be a str object e.g. "12/5/2008" ... I know sqlite
> cheerfully regards column types as vague reminders rather than
> enforceable constraints on your input, but wouldn't you like to
> convert your dates to e.g. "2008-05-12" before you poke them in? You
> may want to use "ORDER BY Date" at some stage, and so that ORDER BY
> isn't whacked and GROUP BY doesn't give ludicrous results, wouldn't it
> be a good idea to crunch 12/5/2008 and 12/05/2008 into a common format
> so that they compare equal?
>>
>> for item in input:
> 
> I strongly suggest that you try to get a clue about exactly what you
> are getting from the csv reader e.g.
> 
> for line_num, item in enumerate(input_renamed_as_suggested_by_anor):
>print line_num, repr(item)
> 
>>         curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item)
>> curse.commit()
>>
> 
> HTH,
> John
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
> 

hey guys
i took all of your suggestion but my goal ain't yet achieved :-((
these are the codes after changes, john i couldn't really catch what do you
mean by renaming input, is it just normal renaming.i am testing the code on
just simple .csv file with few data in as follows before trying on my hug
csv file but still no joy

"Bithday",12-05-08,"HTC","this is my birthday"
"Sea",12-03-08,"kodak","sea"
"girl","14-03-2009","samsung","birthday"
"love","17-04-2009","SONY","view of island"

import sqlite3
import csv

f = open('/home/waseem/Project2/photos.csv')
input = csv.reader(f, delimiter=',')
conn = sqlite3.connect('/home/waseem/Project2/pictures.db')
curse = conn.cursor()

curse.execute('CREATE TABLE photos (Name VARCHAR(100) PRIMARY KEY, Date
INTEGER, Make VARCHAR(50), Tag VARCHAR(100))')
for row in input:
curse.execute('INSERT INTO photos VALUES (?,?,?,?)', '*row')
curse.commit()

this time i got this error

was...@linux:~/Project2$ python experment.py 
Traceback (most recent call last):
  File "experment.py", line 12, in 
curse.execute('INSERT INTO photos VALUES (?,?,?,?)', '*row')
sqlite3.IntegrityError: column Name is not unique

i removed the primary key and single quotation mark for '*row' to just *row
but i got the old error which is 

was...@linux:~/Project2$ python experment.py 
Traceback (most recent call last):
  File "experment.py", line 11, in 
curse.execute('INSERT INTO photos VALUES (?,?,?,?)', *row)
TypeError: function takes at most 2 arguments (5 given)
 
-- 
View this message in context: 
http://www.nabble.com/importing-csv-file-into-sqlite-tp21067453p21090356.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list


Re: pysqlite smart search

2009-02-23 Thread klia



klia wrote:
> 
>  Hey guys;
> 
> I am trying to develop a tiny program using python to search inside sqlite
> database with file extension is .db in which the program will ask users to
> enter their search query and base on that it will retrieve the results But
> 
> I need the program to have some smartness in search mechanism in which the
> program will guess that the user is looking for these key words in the
> database.
> 
> so far i came up with this but the search ain't smart, i have to write the
> full key word in order to retrieve specific information.
> 
> from pysqlite2 import dbapi2 as sqlite3
> 
> connection = sqlite3.connect('Photos.db')
> memoryConnection = sqlite3.connect(':memory:')
> cursor = connection.cursor()
> prompt = 'Enter your search query?\n'
> keyword = raw_input(prompt)
> if cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?',[keyword]):
> print cursor.fetchall()
> else:
> cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', [keyword])
> print cursor.fetchall()
> 
> Any ideas and
> thanks in advance
> Reply
> 

thank you man, it worked perfectly but one more thing;

when i print rows it retrieves the whole rows of info which i don't need, i
need just to retrieve the name of the photo. 
so how am i gonna do that?
-- 
View this message in context: 
http://www.nabble.com/pysqlite-smart-search-tp22157116p22161119.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list


Re: pysqlite smart search

2009-02-23 Thread klia



klia wrote:
> 
>  Hey guys;
> 
> I am trying to develop a tiny program using python to search inside sqlite
> database with file extension is .db in which the program will ask users to
> enter their search query and base on that it will retrieve the results But
> 
> I need the program to have some smartness in search mechanism in which the
> program will guess that the user is looking for these key words in the
> database.
> 
> so far i came up with this but the search ain't smart, i have to write the
> full key word in order to retrieve specific information.
> 
> from pysqlite2 import dbapi2 as sqlite3
> 
> connection = sqlite3.connect('Photos.db')
> memoryConnection = sqlite3.connect(':memory:')
> cursor = connection.cursor()
> prompt = 'Enter your search query?\n'
> keyword = raw_input(prompt)
> if cursor.execute('SELECT * FROM photos WHERE Tag LIKE ?',[keyword]):
> print cursor.fetchall()
> else:
> cursor.execute('SELECT * FROM photos WHERE Date LIKE ?', [keyword])
> print cursor.fetchall()
> 
> Any ideas and
> thanks in advance
> Reply
> 

Thank you guys, it worked perfectly
Solved
-- 
View this message in context: 
http://www.nabble.com/pysqlite-smart-search-tp22157116p22175924.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list