Commit a187045c authored by Jonathan Harker's avatar Jonathan Harker

URLs are now unique.

parent eb6357a3
......@@ -78,7 +78,7 @@ class Url(SqlBase):
id = Column(Integer, primary_key=True)
timestamp = Column(DateTime)
nickname = Column(String(20))
url = Column(String(200))
url = Column(String(200), unique=True)
title = Column(Text)
def __init__(self, nickname, url, title=None, timestamp=None):
......@@ -193,10 +193,18 @@ class LolBot(SingleServerIRCBot):
return datetime.today().strftime("%Y-%m-%d %H:%M:%S")
def save_url(self, nickname, url):
theurl = Url(nickname, url)
db = self.get_session()
db.add(theurl)
db.commit()
if not db.query(Url).filter(Url.url == url).count():
theurl = Url(nickname, url)
db.add(theurl)
db.commit()
else:
try:
theurl = db.query(Url).filter(Url.url == url).one()
except MultipleResultsFound, ex:
print ex #wtf
except NoResultsFound, ex:
print ex #wtf
print theurl
return theurl.title
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment