How do I ignore the errors thrown by the DB api?
Here's the code I have in place right now. cursor.execute("SELECT link FROM feeds_feed WHERE link=%s", (self.link,)) db.commit() if cursor.rowcount == 0: cursor.execute("INSERT INTO feeds_feed (release_group, title, link, category, pub_date) VALUES (%s, %s, %s, %s, now())", (self.group, self.title, self.link, self.category,)) db.commit() print "Inserting" else: print "Already Exists" Basically the uniqueness of the link attribute is enforced in the database so if I try to insert a value that already exists I get an error that breaks the program. Right now I do a SELECT query first to check if the value already exists. The insert is only executed only if the value doesn't already exist. This is a really bad way of doing things because I'm accessing the DB way more than I need to. It would be great if I could just insert values into the DB and let the uniqueness check at the DB level to either add or refuse the duplicate value. I'm not really interested if a particular value is rejected or added, I just want the most efficient way to insert values. I would really appreciate any suggestions or tips. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Help! Identical code doesn't work in Wing IDE but does in Komodo.
I create a new Python file with the following using Wing IDE. import feedparser d = feedparser.parse("http://feedparser.org/docs/examples/atom10.xml";) print d.feed.title I get this error when I debug. AssertionError: Traceback (innermost last): File "c:\Documents and Settings\abc\Application Data\Wing IDE 2\untitled-1.py", line 1, in ? import feedparser File "c:\Documents and Settings\abc\Application Data\Wing IDE 2\untitled-1.py", line 2, in ? d = feedparser.parse("http://feedparser.org/docs/examples/atom10.xml";) File "C:\Python24\Lib\feedparser.py", line 2611, in parse saxparser.parse(source) File "C:\Python24\Lib\xml\sax\expatreader.py", line 107, in parse xmlreader.IncrementalParser.parse(self, source) File "C:\Python24\Lib\xml\sax\xmlreader.py", line 123, in parse self.feed(buffer) File "C:\Python24\Lib\xml\sax\expatreader.py", line 207, in feed self._parser.Parse(data, isFinal) File "C:\Python24\Lib\xml\sax\expatreader.py", line 639, in EndElement File "C:\Python24\Lib\xml\sax\expatreader.py", line 348, in end_element_ns self._cont_handler.endElementNS(pair, None) File "C:\Python24\Lib\feedparser.py", line 1403, in endElementNS self.unknown_endtag(localname) File "C:\Python24\Lib\feedparser.py", line 476, in unknown_endtag method() File "C:\Python24\Lib\feedparser.py", line 1193, in _end_title value = self.popContent('title') File "C:\Python24\Lib\feedparser.py", line 700, in popContent value = self.pop(tag) File "C:\Python24\Lib\feedparser.py", line 685, in pop contentparams = copy.deepcopy(self.contentparams) File "C:\Python24\Lib\copy.py", line 193, in deepcopy rv = reductor(2) File "C:\Python24\Lib\feedparser.py", line 233, in __getattr__ assert not key.startswith('_') With the exact same line of code in Komodo I get the correct output which is "Sample Feed" Any idea what's wrong? -- http://mail.python.org/mailman/listinfo/python-list
i18n hell
I just spent hours trying to figure out why even after I set my SQL table attributes to UTF-8 only garbage kept adding into the database. Apparently you need to execute "SET NAMES 'utf8'" before inserting into the tables. Does anyone have experience working with other languages using Django or Turbogears? I just need to be able to retrieve and enter text to the database from my page without it being mangled. I know these frameworks employ ORM so you don't need to write SQL and that worries me because I tried this on Rails and it wouldn't work. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Elegent solution to replacing ' and " ?
I'm trying to replace the ' and " characters in the strings I get from feedparser so I can enter it in the database without getting errors. Here's what I have right now. self.title = entry.title.encode('utf-8') self.title = self.title.replace('\"', '\\\"') self.title = self.title.replace('\'', '\\\'') This works just great but is there a more elegent way to do this? It looks like maybe I could use the translate method but I'm not sure. -- http://mail.python.org/mailman/listinfo/python-list
Re: Elegent solution to replacing ' and " ?
I'm using PyGreSQL on a PostgreSQL db. I didn't even include my SQL but Serge guessed right and that's what I had. I changed it and it works now. Thanks for the help! :) -- http://mail.python.org/mailman/listinfo/python-list
Should I learn Python instead?
Hi guys, I'm a student/hobbyist programmer interested in creating a web project. It's nothing too complicated, I would like to get data from an RSS feed and store that into a database. I want my website to get the information from the database and display parts of it depending on the criteria I set. I just finished an OO programming class in Java and I thought it would be a good idea to do this in C# since ASP.NET makes web applications easier than using Java (that's what I've heard anyway). I thought it would be easy to pick up since the language syntax is very similar but I'm getting overwhelmed by the massive class library. MSDN docs are very good and thorough but the language just seems a little unwieldy and too verbose. This is how to access an RSS feed and create an XML document to manipulate it. System.Net.WebRequest myRequest = System.Net.WebRequest.Create("//feed url here"); System.Net.WebResponse myResponse = myRequest.GetResponse(); System.IO.Stream rssStream = myResponse.GetResponseStream(); System.Xml.XmlDocument rssDoc = new System.Xml.XmlDocument(); rssDoc.Load(rssStream); Here's PHP. $rss_feed = file_get_contents($rss_url); I realize that learning the library is part of the process, but as a beginner I appreciate simplicity. Is Python easier than C#? Can someone show how to access an XML document on the web and have it ready to be manipulated for comparison? Any other advice for a newbie? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Should I learn Python instead?
Thanks guys. I picked up the Apress book on Python and downloaded the Komodo IDE trial to get me started. I'm going to try using Django to build my website and since my brother already has hosting I'll just borrow some space. He does PHP for a living, so it would probably be better for me to use that instead. Unfortunately, I'm allergic to dollar signs ;) -- http://mail.python.org/mailman/listinfo/python-list