Exemple #1
0
def view_group(group):
    period, start, end, cache_time = get_period(request, "day")
    params = {
        "start": start.strftime(time_format),
        "end": end.strftime(time_format),
        "group": group
    }
    keywords = cache(tweety.get_keywords,
                     cache_time=cache_time,
                     path=get_req_path(request),
                     **params)
    if isinstance(keywords, Response):
        return keywords
    total = sum([entry["count"] for entry in keywords])
    for keyword in keywords:
        keyword["percentage"] = "{:.2f}".format(keyword["count"] / total * 100)
        keyword["count"] = display_number(keyword["count"])
    nums = range(1, len(keywords) + 1)
    template_data = {
        "nums_keywords": zip(nums, keywords),
        "group": group,
        "disp_group": display_group(group),
        "nums": nums,
        "total": display_number(total),
        "period": period,
        "start": display_datetime(start),
        "end": display_datetime(end)
    }
    return render_template("group.html",
                           title=make_title(template_data["disp_group"]),
                           **template_data)
Exemple #2
0
 def draw(self):
     self.draw_legend()
     utils.display_number(self.count, (g.sx(16), g.sy(8)), g.font2)
     img = self.scales[self.state]
     utils.centre_blit(g.screen, img, self.c)
     g.screen.blit(self.light_img, self.light_xy)
     g.screen.blit(self.heavy_img, self.heavy_xy)
     for ball in self.z:
         if ball.active:
             if ball != self.carry:
                 img = self.ball_img(ball)
                 utils.centre_blit(g.screen, img, ball.c)
     if self.carry != None:
         ball = self.carry
         img = self.ball_img(ball)
         x, y = g.pos
         x -= self.mdx
         y -= self.mdy
         utils.centre_blit(g.screen, self.shadow,
                           (x + g.sy(.35), y + g.sy(1.1)))
         utils.centre_blit(g.screen, img, (x, y))
         if utils.mouse_on_img(self.light_img, self.light_xy):
             self.drop_ball('light')
         if utils.mouse_on_img(self.heavy_img, self.heavy_xy):
             self.drop_ball('heavy')
     if self.result != None:
         utils.centre_blit(g.screen, self.result[0], self.result[1])
 def display(self):
     g.screen.fill(utils.BLACK)
     self.board.draw()
     utils.display_number(g.score, (g.sx(22.6), g.yc), g.font2, utils.CREAM)
     utils.centre_blit(g.screen, g.star, (g.sx(27.6), g.yc))
     utils.display_number1(g.best, (g.sx(28.6), g.yc), g.font2, utils.CREAM)
     buttons.draw()
 def display(self):
     g.screen.fill((255, 255, 192))
     g.screen.blit(g.bgd, (g.x0, 0))
     self.acr.draw()
     utils.centre_blit(g.screen, g.scores, g.scores_c)
     utils.display_number(g.score, g.score_c, g.font1)
     pygame.draw.rect(g.screen, utils.BLACK, g.vinc)
     utils.display_number(g.target, g.target_c, g.font1)
     utils.text_blit1(g.screen,g.percent,g.font1,g.percent_xy,\
                      utils.BLACK,False)
     if g.best > 0:
         s = 'Best: ' + str(g.best) + '%'
         utils.text_blit1(g.screen, s, g.font1, g.best_xy, utils.BLACK,
                          False)
     if g.count == 2:
         utils.text_blit(g.screen, 'twice', g.font3, g.count_c,
                         utils.ORANGE, False)
     if g.count > 2:
         s = str(g.count) + ' times'
         utils.text_blit(g.screen, s, g.font3, g.count_c, utils.ORANGE,
                         False)
     buttons.draw()
     if self.acr.message != None:
         utils.message1(g.screen, g.font1, self.acr.message, g.message_c)
     if g.help_on:
         utils.centre_blit(g.screen, g.help_img, g.help_cxy)
Exemple #5
0
 def numbers(self):
     cy = int(self.y0 + g.sy(.1))
     dx = g.sy(.05)
     cyn = int(self.y0 + g.sy(.05))
     for i in range(1, 7):
         cx = self.dishes[i].cxy[0] - dx
         utils.display_number(str(i), (cx, cy), g.font1, utils.CYAN)
         if i == self.dish_n:
             utils.centre_blit(g.screen, g.ring, (cx, cyn))
     cy = int(self.y0 + 2 * self.dy - g.sy(.1))
     k = 150
     colr = (k, k, k)
     for ind in range(1, 7):
         cx = self.dishes[ind].cxy[0]
         utils.display_number(self.dishes[ind].n, (cx, cy), g.font1, colr)
     cy = int(self.y0 - 2 * self.dy - g.sy(.1))
     for ind in range(8, 14):
         cx = self.dishes[ind].cxy[0]
         utils.display_number(self.dishes[ind].n, (cx, cy), g.font1, colr)
     ind = 0
     n = self.dishes[ind].n
     cx, cy = self.dishes[ind].cxy
     cxy = (cx, cy - self.dy - g.sy(.8))
     if g.state in (8, 9): utils.centre_blit(g.screen, g.blue, cxy)
     utils.display_number(n, cxy, g.font2, utils.CREAM)
     ind = 7
     n = self.dishes[ind].n
     cx, cy = self.dishes[ind].cxy
     cxy = (cx, cy + self.dy + g.sy(.7))
     if g.state in (7, 9): utils.centre_blit(g.screen, g.blue, cxy)
     utils.display_number(n, cxy, g.font2, utils.CREAM)
Exemple #6
0
 def display(self):
     g.screen.fill((0,0,70))
     buttons.draw()
     self.grid.draw()
     self.slider.draw()
     utils.display_number(g.score,self.score_cxy,g.font2,utils.CREAM)
     if self.grid.complete():
         utils.centre_blit(g.screen,g.smiley,self.smiley_cxy)
 def display(self):
     g.screen.fill((0, 0, 0))
     buttons.draw()
     self.slider.draw()
     self.omm.draw()
     utils.display_number(self.omm.n, g.number_c, g.font2, self.omm.colr_n)
     s = str(len(om.found[g.level - 1])) + ' / ' + str(self.omm.total)
     utils.text_blit(g.screen, s, g.font1, g.progress_c, utils.CREAM)
     if self.omm.complete():
         utils.centre_blit(g.screen, g.smiley, g.smiley_c)
Exemple #8
0
 def draw_nos(self):
     s=self.sss; s2=self.ss/2
     font=g.font1
     if g.level>1: font=g.font2
     if g.level>4: font=g.font3
     for sq in self.nos:
         x=sq.x; y=sq.y
         colour=COLOURS[sq.colour]
         pygame.draw.rect(g.screen,colour,(x,y,s,s))
         cx=x+s2; cy=y+s2
         utils.display_number(sq.area,(cx,cy),font,(0,0,0))
Exemple #9
0
 def display(self):
     g.screen.fill((0, 255, 255))
     utils.display_number(g.player, g.player_c, g.font3, utils.ORANGE)
     utils.display_number1(g.wizard, g.wizard_lc, g.font3, utils.ORANGE)
     img = g.xo_grey
     if g.state in (1, 2, 3): img = g.xo
     g.screen.blit(img, g.xo_xy)
     img = g.magician_grey
     if g.state in (4, 5, 6): img = g.magician
     g.screen.blit(img, g.magician_xy)
     buttons.draw()
     self.manc.draw()
Exemple #10
0
 def display(self):
     grey = 100
     g.screen.fill((grey, grey, grey))
     buttons.draw()
     g.screen.blit(g.help1, g.help1_xy)
     utils.display_number(g.count, (g.xc, g.yc), g.font2, utils.CREAM)
     colour = utils.YELLOW
     if g.helped > 5: colour = utils.RED
     utils.display_number(g.helped, (g.xc, g.yc + g.sy(6)), g.font1, colour)
     if g.finished:
         utils.centre_blit(g.screen, g.smiley, (g.sx(4), g.smiley_y))
     self.board.draw()
Exemple #11
0
 def display(self):
     g.screen.fill((128, 0, 0))
     self.grid.draw()
     buttons.draw()
     g.screen.blit(g.panel, g.panel_xy)
     utils.display_number(g.count, g.count_c, g.font2, utils.CREAM)
     if self.grid.yes: utils.centre_blit(g.screen, g.yes, g.smiley_cxy)
     if self.grid.no or self.grid.count > 2:
         utils.centre_blit(g.screen, g.no, g.smiley_cxy)
     if self.grid.count > 0 and not self.grid.yes:
         utils.display_number(self.grid.count,(g.smiley_cxy[0],g.wrong_cy),\
                              g.font1,utils.RED)
     if g.ms <> None: utils.centre_blit(g.screen, g.glow, g.glow_c)
Exemple #12
0
 def display(self,wait=False):
     g.screen.fill((0,0,100))
     if wait:
         utils.centre_blit(g.screen,g.wait,(g.sx(16),g.sy(10)))
     else:
         self.rects.draw()
     buttons.draw()
     self.slider.draw()
     if g.magic_show:
         utils.centre_blit(g.screen,g.magic,(g.sx(27.8),g.sy(3.2)))
     if g.score>0:
         x=g.sx(29.5); y=g.sy(8)
         utils.display_number(g.score,(x,y),g.font2,utils.CREAM)
 def draw(self):
     ind = 0
     for item in self.items:
         g.screen.blit(item.img, (item.x, item.y))
         xn, yn = item.x + self.pic_w / 2, int(item.y + self.pic_h +
                                               self.gutter_y / 2.5)
         if item == self.green:
             pygame.draw.rect(g.screen,utils.GREEN,\
                     (item.x,item.y,self.pic_w,self.pic_h),self.edge)
         if g.best[ind] == 3:
             utils.centre_blit(g.screen, g.star, (xn, yn))
         utils.display_number(g.best[ind], (xn, yn), g.font1,
                              (135, 191, 47))
         ind += 1
Exemple #14
0
 def display(self):
     g.screen.fill((220, 64, 64))
     g.grid.draw()
     buttons.draw()
     x = 5
     cy = g.sy(3)
     np = g.grid.counts[1]
     nw = g.grid.counts[2]
     if nw > 0:
         utils.display_number(nw, (g.sx(x), cy), g.font2, utils.ORANGE)
     if np > 0:
         utils.display_number(np, (g.sx(32 - x), cy), g.font2, utils.CYAN)
     x = 3.3
     cy = g.sy(13.2)
     if g.lost > 0: utils.display_number(g.lost, (g.sx(x), cy), g.font1)
     cy = g.sy(14.6)
     if g.won > 0: utils.display_number(g.won, (g.sx(32 - x), cy), g.font1)
     cy = g.sy(18.7)
     img = g.magician
     if g.state != 2: img = g.magician_grey
     utils.centre_blit(g.screen, img, (g.sx(x), cy))
     img = g.xo2
     if g.state != 1: img = g.xo2_grey
     utils.centre_blit(g.screen, img, (g.sx(32 - x), cy))
     cy = g.sy(9)
     if g.result != None:  # smiley
         utils.centre_blit(g.screen, g.result, (g.sx(32 - x), cy))
Exemple #15
0
 def display(self):
     g.screen.fill(g.bgd)
     g.screen.blit(g.tscreen, g.txy)
     if g.grid_on:
         g.screen.blit(g.grid, g.txy)
         if g.grid_nos:
             g.screen.blit(g.x_nos, g.x_nos_xy)
             g.screen.blit(g.y_nos, g.y_nos_xy)
             x, y = g.txy
             utils.display_number(0, (x, y + g.side), g.font2)
     pygame.draw.rect(g.screen, (0, 0, 150), (g.txy, (g.side, g.side)), 2)
     my_turtle2.draw()
     self.panel()
     buttons.draw()
 def display(self):
     if g.help_on:
         if g.help_img==None:
             g.help_img=utils.load_image('help.png')
         g.screen.blit(g.help_img,(0,0))
         return
     g.screen.fill((70,0,70))
     self.sim.draw()
     if not g.running: buttons.clear()
     buttons.draw()
     self.slider.draw()
     if g.load_n>0:
         utils.display_number(g.load_n,self.load_c,g.font1,utils.CYAN)
     utils.display_number(g.save_n,self.save_c,g.font1,utils.ORANGE)
Exemple #17
0
    def display(self, wait=False):
        if g.state == 1:
            self.menu_display()
            #utils.display_number(g.success,(g.sx(.2),g.sy(.15)),g.font2,utils.ORANGE)
        else:
            if self.pj.complete():
                g.screen.blit(g.bgd, (g.sx(0), 0))

            else:
                #                g.screen.fill((g.red,g.green,g.blue))
                g.screen.fill(utils.CYAN)
            self.pj.draw()
            buttons.draw()
            utils.display_number(g.success, (g.sx(.2), g.sy(.3)), g.font1,
                                 utils.ORANGE)
Exemple #18
0
def ladder():
    if g.score>g.best: g.best=g.score
    if g.best>11:
        cx=g.sx(30.55); cy=g.sy(13.25)
        utils.centre_blit(g.screen,g.star,(cx,cy))
        utils.display_number(g.best,(cx,cy))
    if g.score>0:
        n=g.score-1
        if n>11: n=11
        g.screen.blit(g.ladder,(g.sx(26.95),g.sy(13.7)))
        x=g.man_x0+n*g.man_dx; y=g.man_y0+n*g.man_dy
        g.screen.blit(g.man,(x,y))
        cx=x+g.man_sc_dx; cy=y+g.man_sc_dy
        if g.score<g.best or g.best<12:
            utils.centre_blit(g.screen,g.star,(cx,cy))
            utils.display_number(g.score,(cx,cy))
Exemple #19
0
 def draw_legend(self):
     g.screen.blit(self.legend, self.legend_xy)
     x, y = self.legend_xy
     x += g.sy(2)
     y += g.sy(.05)
     utils.text_blit1(g.screen,'3     6     9    12',\
                      g.font2,(x,y),utils.BLUE,False)
     y += g.sy(1.25)
     utils.text_blit1(g.screen,'2     3     3     3',\
                      g.font2,(x,y),utils.BLACK,False)
     x = g.sx(14.2)
     y += g.sy(1.75)
     dx = g.sy(1.77)
     for n in g.scores:
         utils.display_number(n, (x, y), g.font2, utils.ORANGE)
         x += dx
 def draw(self):
     g.screen.blit(self.base, (self.x, self.y))
     for sq in squares:
         if sq.visible:
             v = sq.v
             if v == 0: v = 6
             g.screen.blit(imgs[v], (sq.x, sq.y))
     colr = utils.CYAN
     g.screen.blit(self.top, (self.x, self.y))
     for rn in row_ns:
         utils.display_number1(rn.n, (rn.x, rn.y), g.font1, colr)
     for cn in col_ns:
         utils.display_number(cn.n, (cn.x, cn.y), g.font1, colr)
     if not self.complete() and g.ms == None:
         sq = self.green
         pygame.draw.rect(g.screen,utils.GREEN,\
                          (sq.x,sq.y,self.side,self.side),8)
Exemple #21
0
 def draw(self, demo=False):
     w = g.sy(.02)
     for cell in self.cells:
         if cell.show:
             rect = (cell.x, cell.y, self.d + 1, self.d + 1)
             pygame.draw.rect(g.screen, utils.BLUE, rect, w)
             cxy = (cell.x + self.d2, cell.y + self.d2)
             if cell.star:
                 utils.centre_blit(g.screen, g.stars[cell.colour], cxy)
             else:
                 if cell.val != None:
                     utils.display_number(str(cell.val), cxy, g.font2)
         else:
             g.screen.blit(g.gold, (cell.x, cell.y))
     if not demo:
         for star in self.stars:
             utils.centre_blit(g.screen, g.stars[star.colour], star.cxy)
         rect = pygame.Rect(self.green.x, self.green.y, self.d, self.d)
         pygame.draw.rect(g.screen, utils.GREEN, rect, self.green_w)
Exemple #22
0
 def draw(self):
     g.screen.blit(self.bgd,(g.sx(0),0))
     cxy=(g.sx(30.5),g.sy(20))
     utils.display_number(g.count,cxy,g.font2,utils.CREAM)
     for lf in lookFor:
         if not lf.found:
             utils.centre_blit(g.screen,lf.img,(lf.cx,lf.cy))
     if not self.complete and not g.setup_on:
         img=lookFor[self.find_ind[self.current_ind]].img
         cxy=(self.frame_cx,self.frame_cy)
         utils.centre_blit(g.screen,self.frame,cxy)
         utils.centre_blit(g.screen,img,cxy)
         x,y=cxy; x-=self.frame.get_width()/2;x+=g.sy(.24)
         y+=self.frame.get_height()/2; y-=g.sy(.76)
         n=self.found; s=str(n)+' / '+str(self.find_n)
         utils.text_blit1(g.screen,s,g.font1,(x,y),utils.BLACK)
     if self.complete:
         cxy=(self.frame_cx,self.frame_cy)
         utils.centre_blit(g.screen,self.frame,cxy)
         utils.centre_blit(g.screen,self.smiley,cxy)
Exemple #23
0
 def display(self, wait=False):
     if g.state == 1:
         self.menu_display()
         utils.display_number(g.success, (g.sx(.2), g.sy(.15)), g.font2)
     else:
         if self.pj.complete():
             g.screen.blit(g.bgd, (g.sx(0), 0))
             utils.display_number(g.success, (g.sx(.5), g.sy(.5)), g.font1)
         else:
             #                g.screen.fill((g.red,g.green,g.blue))
             g.screen.fill(utils.CYAN)
         self.pj.draw()
         buttons.draw()
         if self.bu2.active:
             if self.pj.all_rotated():
                 self.bu2.off()
             else:
                 utils.centre_blit(g.screen, g.smiley1,
                                   (g.smiley1_x, g.smiley_y))
                 utils.centre_blit(g.screen, g.smiley2,
                                   (g.smiley2_x, g.smiley_y))
Exemple #24
0
 def ladder(self):
     if g.score > g.best:
         g.best = g.score
     if g.best > 11:
         cx = g.sx(30.55)
         cy = g.sy(13.25)
         utils.centre_blit(g.screen, g.star, (cx, cy))
         utils.display_number(g.best, (cx, cy), g.font2)
     if g.score > 0:
         n = g.score - 1
         if n > 11:
             n = 11
         g.screen.blit(g.ladder, (g.sx(26.95), g.sy(13.7)))
         x = g.man_x0 + n * g.man_dx
         y = g.man_y0 + n * g.man_dy
         g.screen.blit(g.man, (x, y))
         cx = x + g.man_sc_dx
         cy = y + g.man_sc_dy
         if g.score < g.best or g.best < 12:
             utils.centre_blit(g.screen, g.star, (cx, cy))
             utils.display_number(g.score, (cx, cy), g.font2)
Exemple #25
0
 def mouse_over(self):
     for i in range(10):
         c = self.centres[i]
         cx = c[0]
         cy = c[1]
         w2 = self.w2
         h2 = self.h2
         if utils.mouse_in(cx - w2, cy - h2, cx + w2, cy + h2):
             n = self.yes[i]
             v = value(n)
             s = suit(n)
             h = self.help1()
             if h == 'nos':
                 utils.display_number(v, c, g.font1, utils.CYAN,
                                      utils.ORANGE)
             elif h == 'odd_even':
                 if odd(v):
                     utils.display_number(v, c, g.font1, utils.CYAN,
                                          utils.RED)
                 else:
                     utils.display_number(v, c, g.font1, utils.RED,
                                          utils.CYAN)
             elif h == 'suit':
                 utils.centre_blit(g.screen, g.suits[s], c)
             elif h == 'colour':
                 img = g.red
                 if colour(n) == 'b': img = g.black
                 utils.centre_blit(g.screen, img, c)
             elif h == 'castle':
                 utils.centre_blit(g.screen, g.castle, c)
             elif h == 'castle_x':
                 utils.centre_blit(g.screen, g.castle_x, c)
             elif h == 'xo1':
                 utils.centre_blit(g.screen, g.xo1, c)
             return
 def display(self):
     if g.state == 1:  # normal
         g.screen.fill(g.bgd_colour)
         self.castle.current_room.display()
         self.castle.health_display()
         utils.centre_blit(g.screen, g.bag_current_img, g.bag_cxy)
         if g.wishes > 0:
             utils.centre_blit(g.screen, g.wish_current_img, g.wish_cxy)
             x = g.wish_x
             y = g.wish_y
             utils.display_number(g.wishes, (x + g.sy(2.2), y + g.sy(.9)),
                                  g.font1)
         buttons.draw()
         if g.best > 0:
             x = g.sx(16)
             y = g.sy(20)
             utils.text_blit1(g.screen, str(g.best), g.font1, (x, y),
                              (255, 128, 255))
             x -= g.sy(1.5)
             y -= g.sy(.3)
             g.screen.blit(g.star, (x, y))
     elif g.state == 2:  # inside bag
         grey = 180
         g.screen.fill((grey, grey, grey))
         utils.centre_blit(g.screen, g.bag_base, (g.sx(16), g.sy(11.2)))
         ind = 0
         for obj in g.bag:
             if obj <> None:
                 utils.centre_blit(g.screen, obj.img0,
                                   g.inside_bag_cxy[ind])
             ind += 1
         g.screen.blit(g.inside_bag, (g.sx(0), g.sy(0)))
     elif g.state == 3:  # wishes
         self.castle.wish_display()
     elif g.state == 4:  # map
         self.castle.map_display()
Exemple #27
0
 def centre(self):  # displays entrances/objects if mouse over
     # 1=open door, 2=closed door, 3=high window
     if g.box_ms == None:  # don't cover box glow
         for v in 'NSEW':
             img = None
             if self.connect[v] == 1: img = g.open_door
             if self.connect[v] == 2: img = g.door
             if self.connect[v] == 3: img = g.window
             if img == g.window and in_bag('ladder'): img = g.window_ladder
             if img <> None:
                 b = connect_box(v)
                 if utils.mouse_in(b[0], b[1], b[2], b[3]):
                     utils.centre_blit(g.screen, img, (g.cx, g.cy))
                     return True
         for corner in corners:
             top_left = self.obj_top_left(corner)
             if top_left <> None:
                 obj = self.corner[corner]
                 if utils.mouse_on_img(obj.img, top_left):
                     img = obj.img0
                     if obj.name == 'token': img = g.token
                     if obj.name == 'fuel': img = g.fuel
                     utils.centre_blit(g.screen, img, (g.cx, g.cy))
                     if obj.name in jewel_names:
                         v = value(obj.name)
                         utils.display_number(v,(g.cx,g.cy),g.font2\
                                              ,utils.CREAM,None,g.font3)
                     return True
     if self.name == 'entrance':
         if utils.mouse_on_img(g.box_closed, (g.box_x, g.box_c_y)):
             g.screen.blit(g.box_open, (g.box_x, g.box_o_y))
             utils.display_number(g.score, g.score_c, g.font2, utils.CREAM)
         else:
             utils.centre_blit(g.screen, g.box_current_img, g.box_cxy)
         return True
     return False
Exemple #28
0
 def draw(self):
     for locn in self.locns:
         if locn.state == 0:
             g.screen.blit(self.back, (locn.x, locn.y))
         elif locn.state in (1, 3):
             if locn.pic or not g.words:
                 g.screen.blit(self.pics[locn.card], (locn.x, locn.y))
             else:
                 g.screen.blit(self.front, (locn.x, locn.y))
                 cxy = (locn.x + self.w / 2, locn.y + self.h / 2)
                 utils.text_blit(g.screen, words[locn.card],
                                 g.font1, cxy, utils.BLACK, False)
     if self.green is not None:
         pygame.draw.rect(g.screen, self.colors,
                          (self.green.x, self.green.y, self.w, self.h), 5)
     if self.tries > 0:
         if not self.sugar:
             utils.display_number(self.tries, self.tries_cxy, g.font2,
                                  utils.CREAM)
     if g.best > 0 and not self.sugar:
         g.screen.blit(self.star, (self.star_xy))
         utils.display_number1(g.best, self.best_xcy, g.font2, utils.ORANGE)
     if self.sugar:
         self.label.set_markup(
             '<span><big><b> %s (%s)</b></big></span>' % (
                 str(int(float(self.tries))),
                 str(int(float(g.best)))))
     if len(self.clicks) == 3:
         locn = self.clicks[0]
         g.screen.blit(self.grey, (locn.x, locn.y))
     if g.numbers:
         x = self.xn
         y = self.h / 2 + self.gutter
         for r in range(self.nr):
             n = self.nr - r
             utils.display_number(n, (x, y), g.font1, utils.CREAM)
             y += self.h + self.gutter
         x = self.xn * 2 + self.w / 2
         y = self.yn + g.sy(.4)
         for c in range(self.nc):
             n = c + 1
             utils.display_number(n, (x, y), g.font1, utils.CREAM)
             x += self.w + self.gutter
Exemple #29
0
def view_keyword(keyword):
    deluxe = is_deluxe(
        current_user
    )  # users in the "deluxe" group can specify their own time period

    period, start, end, cache_time = get_period(request, "week")
    if period == "custom":
        if not deluxe:
            flash(
                "Deze functionaliteit is alleen beschikbaar voor goedgekeurde gebruikers.",
                "error")
            return redirect(url_for("horti.home"))
        if (end - start).days > 31:
            flash("Periode langer dan een maand is niet toegestaan", "error")
            return redirect(url_for("horti.home"))
        if start > end:
            flash("De einddatum moet na de begindatum zijn.", "error")
            return redirect(url_for("horti.home"))
    params = {
        "start": start.strftime(time_format),
        "end": end.strftime(time_format)
    }
    keyword_data = cache(process_details,
                         keyword,
                         params,
                         cache_time=cache_time,
                         path=get_req_path(request))
    if isinstance(keyword_data, Response):
        return keyword_data

    urls = keyword_data["URLs"][:16]
    for url in urls:
        url["display_url"] = shorten(url["link"], 80)
    del keyword_data["URLs"]

    keyword_data["tagCloud"] = keyword_data["tagCloud"][:200]

    photos = enumerate(keyword_data["photos"]
                       )  # number of photo's is limited in processing.py
    del keyword_data["photos"]

    display_tweets = 11
    max_tweets = 200
    keyword_data["tweets"] = keyword_data["tweets"][:max_tweets]
    keyword_data["retweets"] = keyword_data["retweets"][:display_tweets]
    keyword_data["interaction_tweets"] = keyword_data[
        "interaction_tweets"][:max_tweets]

    num_tweets = keyword_data["num_tweets"]
    del keyword_data["num_tweets"]

    graph = keyword_data["graph"]
    del keyword_data["graph"]

    polarity = keyword_data["polarity"]
    del keyword_data["polarity"]

    polarity_face = display_polarity(polarity)

    gtrends_period = {
        "day": "now 1-d",
        "week": "now 7-d",
        "month": "today 1-m"
    }.get(period, "now 1-d")
    period_name = {
        "day": "dag",
        "week": "week",
        "month": "maand"
    }.get(period, "dag")

    news = []
    for item in keyword_data["news"]:
        item["pubdate"] = display_datetime(item["pubdate"])
        del item["nid"]
        news.append(item)
    del keyword_data["news"]

    template_data = {
        "keyword": keyword,
        "keyword_data": json.dumps(keyword_data),
        "deluxe": deluxe,
        "num_tweets": display_number(num_tweets),
        "urls": urls,
        "graph": json.dumps(graph),
        "photos": photos,
        "display_tweets": display_tweets,
        "start": display_datetime(start),
        "end": display_datetime(end),
        "period": period,
        "period_name": period_name,
        "polarity": polarity,
        "polarity_face": polarity_face,
        "gtrends_period": gtrends_period,
        "news": news
    }
    return render_template("keyword.html",
                           title=make_title(keyword),
                           **template_data)