# Path: montanha/models.py
# class PoliticalParty(models.Model):
# 
#     class Meta:
#         verbose_name = _("Political Party")
#         verbose_name_plural = _("Political Parties")
# 
#     siglum = models.CharField(max_length=15,
#                               verbose_name=_("Siglum"),
#                               unique=True)
# 
#     name = models.CharField(max_length=2048,
#                             verbose_name=_("Full name"),
#                             blank=True,
#                             null=True)
# 
#     logo = ThumbnailerImageField(
#         verbose_name=_('Logo'),
#         upload_to='political_party',
#         blank=True,
#         null=True)
# 
#     wikipedia = models.URLField(
#         verbose_name=_('Wikipedia'),
#         blank=True,
#         null=True)
# 
#     def __unicode__(self):
#         return u"%s" % (self.siglum)


import os
import urllib2
import urllib
from BeautifulSoup import BeautifulSoup
from django.core.files import File
from montanha.models import PoliticalParty
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
##





for pp in PoliticalParty.objects.all():
    if not pp.wikipedia:
        continue
    req = urllib2.Request(pp.wikipedia, headers={"User-Agent": "Mozilla/5.0"})
    html = urllib2.urlopen(req)
    doc = BeautifulSoup(html)
    table = doc.find("table", {"class": "infobox_v2"})
    if table:
        img = table.find("a", {"class": "image"})
        if img:

# Path: montanha/models.py
# class PoliticalParty(models.Model):
# 
#     class Meta:
#         verbose_name = _("Political Party")
#         verbose_name_plural = _("Political Parties")
# 
#     siglum = models.CharField(max_length=15,
#                               verbose_name=_("Siglum"),
#                               unique=True)
# 
#     name = models.CharField(max_length=2048,
#                             verbose_name=_("Full name"),
#                             blank=True,
#                             null=True)
# 
#     logo = ThumbnailerImageField(
#         verbose_name=_('Logo'),
#         upload_to='political_party',
#         blank=True,
#         null=True)
# 
#     wikipedia = models.URLField(
#         verbose_name=_('Wikipedia'),
#         blank=True,
#         null=True)
# 
#     def __unicode__(self):
#         return u"%s" % (self.siglum)


# Path: scripts/get_wikipedia_politicalparty_logo.py
import os
import urllib2
import urllib
from BeautifulSoup import BeautifulSoup
from django.core.files import File
from montanha.models import PoliticalParty

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
##





for pp in PoliticalParty.objects.all():
    if not pp.wikipedia:
        continue
    req = urllib2.Request(pp.wikipedia, headers={"User-Agent": "Mozilla/5.0"})
    html = urllib2.urlopen(req)
    doc = BeautifulSoup(html)
    table = doc.find("table", {"class": "infobox_v2"})
    if table:
        img = table.find("a", {"class": "image"})
        if img:

            logo_url = img.find("img")["src"]