Update to work with Python 3

- Replace Mechanize with BeautifulSoup.
 - Adjust requirements.txt for updated dependencies.
This commit is contained in:
Jonathan Harker 2015-11-23 11:52:45 +13:00
parent 3c366bb5e2
commit 303c8a7584
2 changed files with 14 additions and 12 deletions

View file

@ -1,5 +1,13 @@
from mechanize import Browser #! /usr/bin/env python
"""
Database models for lolbot.
"""
from __future__ import print_function, unicode_literals
import requests
from datetime import datetime from datetime import datetime
from bs4 import BeautifulSoup
from sqlalchemy import (Column, String, Text, Integer, DateTime) from sqlalchemy import (Column, String, Text, Integer, DateTime)
from sqlalchemy.ext.declarative import (declarative_base) from sqlalchemy.ext.declarative import (declarative_base)
@ -59,9 +67,8 @@ class Url(Model):
# populate the title from the URL if not given. # populate the title from the URL if not given.
if title is None: if title is None:
try: try:
br = Browser() dom = BeautifulSoup(requests.get(self.url), 'html.parser')
br.open(self.url) self.title = dom.title.string
self.title = br.title()
except Exception: except Exception:
self.title = '' self.title = ''

View file

@ -1,9 +1,4 @@
SQLAlchemy==1.0.9 SQLAlchemy==1.0.9
argparse==1.2.1 beautifulsoup4==4.4.1
irc==11.0.1 irc==13.2
jaraco.timing==1.1.5 requests==2.8.1
jaraco.util==10.6
mechanize==0.2.5
more-itertools==2.2
six==1.10.0
wsgiref==0.1.2