Ejemplo n.º 1
0
    def __init__(self, charset='cp1251', *args, **kwargs):
        self.charset = charset
        self.cookie = cookielib.CookieJar()

        self.headers = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36'),
                        ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8')]

        try:
            media = Media.objects.get(parser=kwargs.get("parser"))

            media.group = kwargs.get("group")
            media.name = kwargs.get("name")
            media.link = kwargs.get("link")
            media.tags = kwargs.get("tags", [])
            media.save()

        except db.DoesNotExist:
            media = Media(group=kwargs.get("group"),
                          name=kwargs.get("name"),
                          link=kwargs.get("link"),
                          tags=kwargs.get("tags", []),
                          parser=kwargs.get("parser"))
            media.save()

        self.media = media.parser
        self.id = media.id
Ejemplo n.º 2
0
 def __init__(self, parser=None):
     if parser:
         self.__run(parser)
     else:
         for media in Media.objects():
             self.__run(media.parser)