Пример #1
0
def createComic(user, title, panel1Id, panel2Id, panel3Id, panel4Id, panel5Id,
                panel6Id):
    try:
        comic = Comic.objects.get(panel1=panel1Id,
                                  panel2=panel2Id,
                                  panel3=panel3Id,
                                  panel4=panel4Id,
                                  panel5=panel5Id,
                                  panel6=panel6Id)
        return {'comicExisted': True, 'comic': comic}
    except Comic.DoesNotExist:
        if not verifyComicPanelIds(
            [panel1Id, panel2Id, panel3Id, panel4Id, panel5Id, panel6Id]):
            return None

        comic = Comic(panel1=panel1Id,
                      panel2=panel2Id,
                      panel3=panel3Id,
                      panel4=panel4Id,
                      panel5=panel5Id,
                      panel6=panel6Id,
                      title=title,
                      createdby=user,
                      datecreated=datetime.datetime.now())
        comic.save()
        return {'comicExisted': False, 'comic': comic}
Пример #2
0
def createComic(user, title, panel1Id, panel2Id, panel3Id, panel4Id, panel5Id, panel6Id):
    try:
        comic = Comic.objects.get(panel1=panel1Id, panel2=panel2Id, panel3=panel3Id, panel4=panel4Id, panel5=panel5Id, panel6=panel6Id)
        return { 'comicExisted' : True, 'comic' : comic }
    except Comic.DoesNotExist:
        if not verifyComicPanelIds([panel1Id, panel2Id, panel3Id, panel4Id, panel5Id, panel6Id]):            
            return None
               
        comic = Comic(panel1=panel1Id, panel2=panel2Id, panel3=panel3Id, panel4=panel4Id, panel5=panel5Id, panel6=panel6Id, title=title, createdby=user, datecreated=datetime.datetime.now())
        comic.save()
        return { 'comicExisted' : False, 'comic' : comic }
Пример #3
0
def create_comic():
    fake = Faker()

    comic = Comic(
        # the random values are imported from data.py
        name=random.choice(data.names),
        publisher=random.choice(data.publishers),
        description=fake.paragraph(nb_sentences=10, variable_nb_sentences=True),
        cover=random.choice(data.covers),
        price=random.uniform(0, 99)
    )

    comic.save()
 def test_details_url(self):
     pk = 2
     name = "Spider-Man (2019) #1"
     expected_result = '/comics/details/' + str(pk)
     comic = Comic(pk=pk, name=name)
     result = '/comics/details/2'
     self.assertEqual(result, expected_result)
Пример #5
0
 def get(self):
     all = Comic.query().order(Comic.number).fetch()
     return make_response(
         render_template("../client/partials/comics/list.html",
                         title="Comics",
                         comics=all,
                         form=ComicCreateForm()))
Пример #6
0
def random_comic(posted):
    words = random_name.special_thing()

    c = Comic(title=words,
              image_url="http://curtis.lassam.net/comics/cube_drone/{}.gif".format(random.choice(range(0, 140))),
              promo_text= "Promo text for {}".format(words)[:79],
              posted=posted,
              secret_text = "Secret text for {}".format(words),
              alt_text = "Alt text for {}".format(words),
              tags = [random_name.thing(), random_name.adjective(), random_name.noun()])
    if random.choice([False, False, False, True]):
        c.title = "Hidden {}".format(c.title)
        c.hidden = True
    c.save()
    print("Creating {}".format(c))
    return c
Пример #7
0
def create_video(item):
    hero = Comic.hero()

    v = Video(comic=hero,
              title=item['title'],
              youtube_video_code=item['youtube'],
              hidden= not item['visible'])
    v.save()
    print("Created {}".format(v))
Пример #8
0
def create_image(title, image):
    hero = Comic.hero()
    print(hero)

    i = Image(comic=hero,
              title=title,
              image_url=image)
    i.save()
    print("Created {}".format(i))
Пример #9
0
def publish():
    publog = []

    hero = Comic.hero()
    if hero.published:
        print("Nothing to see here!")
        return

    publog.append("We're publishing a comic! Hooray!")
    publog.append(str(hero))
    hero.published = True
    # this should trigger a cache-clear and re-order operation
    hero.save()

    hero = Comic.hero()
    assert(hero.order > 0)

    # send hero e-mail to subscribers
    subscribers = EmailSubscriber.subscribers()

    mails = []
    for subscriber in subscribers:
        try:
            publog.append("Sending comic to {}".format(subscriber.email))
            subscriber.send_promo_email(hero)
        except SpamSpamSpamSpam:
            publog.append("\tCan't send: SPAM limit!")
        except Exception as e:
            publog.append(e)

    # tweet hero tweet
    twitter_message = hero.twitter_message()
    publog.append("\n")
    publog.append("Tweeting: {}".format(twitter_message))
    try:
        tweet(twitter_message)
    except Exception as e:
        publog.append(e)

    # send printed report to admin
    mail_admins(subject="Published!",
                message="\n".join(publog))

    return
Пример #10
0
def create_comic(item, posted, comic_url):
    secrettext = ""
    if 'secret-text' in item:
        secrettext = item['secret-text']
    alttext = ""
    if 'alt-text' in item:
        alttext = item['alt-text']

    tags = []
    for category in item['categories']:
        tags.append(slugify(category))

    if 'cube-drone' in tags:
        tags.remove('cube-drone')

    if '-' in item['title']:
        things = [thing.strip(" ") for thing in item['title'].split("-")]
        if "Interlude" in things or "interlude" in things:
            tags.append('interlude')
            things = things[1:]
        try:
            int(things[0])
            things = things[1:]
        except ValueError:
            pass
        item['title'] = " ".join(things)

    c = Comic(title=item['title'],
              posted=posted,
              image_url=comic_url,
              secret_text=secrettext,
              alt_text=alttext,
              promo_text="",
              hidden=not item['visible'],
              published=True,
              tags=tags)
    c.save()
    print("Created {}".format(c))
Пример #11
0
def create_blog(item):
    hero = Comic.hero()
    content = ""
    if "markdown" in item:
        content = item['markdown']
    elif "content" in item:
        content = item['content']

    b = Blog(comic=hero,
             title=item['title'],
             markdown=content,
             hidden= not item['visible'])
    b.save()
    print("Created {}".format(b))
Пример #12
0
    def post(self):
        form = ComicCreateForm(data=request.get_json())
        if form.validate():
            pass
        else:
            abort(400)
        qry = Comic.query(Comic.number == form.number.data)
        if len(qry.fetch(1)) > 0:
            return make_response(render_template("409.html"))

        comic = Comic()
        comic.number = form.number.data
        comic.title = crawler.findTitle(comic.number)
        image = crawler.findImage(comic.number)
        comic.image = b64encode(image) if image is not None else image
        comic.put()
        return redirect(api.url_for(ComicList), 301)
Пример #13
0
def comic(request, comic_id):
    follows = ComicFollows.objects.filter(comic=comic_id,
                                          user_id=request.user).count()

    if Comic.objects.filter(pk=comic_id).count():
        return render(request, 'comics/comic.html', {
            'comic': Comic.objects.get(pk=comic_id),
            'follows': follows
        })
    else:
        headers = {'User-Agent': 'PintGrupo10'}
        field_list = 'id,issue_number,name,volume,cover_date,description,image'
        response = requests.get(
            'https://comicvine.gamespot.com/api/issue/4000-' + comic_id,
            params={
                'format': 'json',
                'api_key': settings.COMICVINE_KEY
            },
            headers=headers)
        if response.status_code == 200:
            son = json.loads(response.text)
            results = son['results']
            if results:
                comic_id = results['id']
                issue_number = results['issue_number']
                if not issue_number:
                    issue_number = 0
                title = results['name']
                if not title or title == 'None':
                    title = son['results']['volume']['name']
                    if not title:
                        title = "Title not available"
                image = results['image']['small_url']
                store_date = results['cover_date']
                if not store_date:
                    store_date = "0000-00-00"
                synopsis = results['description']
                if not synopsis:
                    synopsis = "Synopsis not available"
                Comic(comic_id, issue_number, title, image, store_date,
                      synopsis).save()

                return render(request, 'comics/comic.html', {
                    'comic': Comic.objects.get(pk=comic_id),
                    'follows': follows
                })

        return render(request, 'comics/404.html')
Пример #14
0
    def post(self):
        form = ComicCreateForm(data=request.get_json())
        if form.validate():
            pass
        else:
            abort(400)
        qry = Comic.query(Comic.number == form.number.data)
        if len(qry.fetch(1)) > 0:
            return make_response(render_template("409.html"))

        comic = Comic()
        comic.number = form.number.data
        comic.title = crawler.findTitle(comic.number)
        image = crawler.findImage(comic.number)
        comic.image = b64encode(image) if image is not None else image
        comic.put()
        return redirect(api.url_for(ComicList), 301)
Пример #15
0
 def get(self, id):
     Comic.get_by_id(id).key.delete()
     return redirect(api.url_for(ComicList), 301)
 def test_string_representation(self):
     comic = Comic(name="Spider-Man (2019) #1")
     self.assertEqual(str(comic), comic.name)
Пример #17
0
 def get(self, id):
     comic = Comic.get_by_id(id)
     return make_response(
         render_template('../client/partials/comics/detail.html',
                         comic=comic))
Пример #18
0
 def get(self, id):
     Comic.get_by_id(id).key.delete()
     return redirect(api.url_for(ComicList), 301)
Пример #19
0
    def process_item(self, item, spider):
        comic = Comic()
        comic.comic_strip = self.comic_strip
        comic.date = item['date']
        if 'title' in item:
            comic.title = item['title']
        else:
            comic.title = None

        if comic.title is None:
            comic.title = "{} : {}/{}/{}".format(self.comic_strip.name,
                                                 comic.date.month,
                                                 comic.date.day,
                                                 comic.date.year)

        comic.comic_page_url = item['comic_page_url']
        comic.comic_url = item['comic_url']
        if 'alt_text' in item:
            comic.alt_text = item['alt_text']
        if 'alt_comic_url' in item:
            comic.alt_comic_url = item['alt_comic_url']
        try:
            comic.save()
        except IntegrityError:
            # Not needed, but we should try updating here.
            pass

        return item
Пример #20
0
 def get(self, id):
     comic = Comic.get_by_id(id)
     return make_response(render_template("../client/partials/comics/detail.html", comic=comic))
Пример #21
0
 def get(self):
     all = Comic.query().order(Comic.number).fetch()
     return make_response(
         render_template("../client/partials/comics/list.html", title="Comics", comics=all, form=ComicCreateForm())
     )