Commit 303c8a75 authored by Jonathan Harker's avatar Jonathan Harker

Update to work with Python 3

 - Replace Mechanize with BeautifulSoup.
 - Adjust requirements.txt for updated dependencies.
parent 3c366bb5
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): ...@@ -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 = ''
......
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
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