def home():
    import dao
    import re
    p = re.compile('.*philosophy.sexy', re.IGNORECASE)
    if ('Host' in request.headers):
        host = request.headers['Host']
        m = p.match(host)
        if (m):
            return sexyRandom()
    return serveComic(dao.getMaxComic())
Beispiel #2
0
def home():
    import dao
    import re
    p = re.compile('.*philosophy.sexy', re.IGNORECASE)
    if ('Host' in request.headers):
        host = request.headers['Host']
        m = p.match(host)
        if (m):
            return sexyRandom()
    return serveComic(dao.getMaxComic())
Beispiel #3
0
def random():
    import dao
    import random
    maxComic = dao.getMaxComic()
    curComic = random.randint(1, maxComic)

    seenComics = request.cookies.get('seen')
    seenSet = set()
    seenAry = list()
    if seenComics != None:
        seenAry = seenComics.split(':')
        for i in seenAry:
            seenSet.add(int(i))
        if len(seenSet) + 1 >= maxComic:
            seenAry = list()
        while curComic in seenSet:
            if curComic == maxComic:
                curComic = 1
            else:
                curComic += 1
    return redirect("/comic/" + str(curComic))
def random():
    import dao
    import random
    maxComic = dao.getMaxComic()
    curComic = random.randint(1,maxComic)

    seenComics = request.cookies.get('seen')
    seenSet = set()
    seenAry = list()
    if seenComics != None:
        seenAry = seenComics.split(':');
        for i in seenAry:
            seenSet.add(int(i))
        if len(seenSet) + 1 >= maxComic:
            seenAry = list()
        while curComic in seenSet:
            if curComic == maxComic:
                curComic = 1
            else:
                curComic += 1
    return redirect("/comic/" + str(curComic))
def serveComic(curComicInput=None, lang='en'):
    import dao

    d0 = date(2013, 11, 12)
    today = date.today()
    delta = today - d0
    kantDays = delta.days

    # cookie which tracks which comics have been seen already   
    seenComics = request.cookies.get('seen')

    curComic = None
    try:
        curComic = long(curComicInput)
    except ValueError:
        return page_not_found(None) 

    maxComic = dao.getMaxComic()
    if curComic is None:
        curComic = maxComic

    comic = dao.getComic(curComic, lang)
    if comic is None:
        return page_not_found(None) 
   
    philosophers = dao.getPhilosophersByComic(comic.comicId)

    joke = dao.getRandomJoke()

    navMaps = []
    titleMaps = []

    langUrl = ""
    if (lang != 'en'):
        langUrl = lang + '/'

    nextComic = int(comic.comicId) + 1
    firstComic = 1
    prevComic = int(comic.comicId) - 1
    lastComic = int(maxComic)
    if int(comic.comicId) == int(maxComic):
        titleImg = s.STATIC_URL + '/title_last.jpg'
        navImg   = s.STATIC_URL + '/nav_last.jpg'
        lastComic = None
        nextComic = None
    elif int(comic.comicId) == 1:
        titleImg = s.STATIC_URL + '/title_first.jpg'
        navImg   = s.STATIC_URL + '/nav_first.jpg'
        firstComic = None
        prevComic = None
    else:
        titleImg = s.STATIC_URL + '/title.jpg'
        navImg   = s.STATIC_URL + '/nav.jpg'

    seenSet = set()
    seenAry = list()
    seen = 0
    if seenComics != None:
        seenAry = seenComics.split(':');
        for i in seenAry:
            if i.isdigit():
                if i == curComic:
                    seen = 1
                seenSet.add(int(i))
        if len(seenSet) + 1 >= maxComic:
            seenAry = list()
    if seen == 0:
        seenAry.append(curComic)     

    resp = make_response(render_template('comic.html', comic=comic, philosophers=philosophers,titleImg=titleImg, navImg=navImg, titleMaps=titleMaps, firstComic=firstComic, prevComic=prevComic, nextComic=nextComic, lastComic=lastComic, langUrl = langUrl, static=s.STATIC_URL, showAds = s.SHOW_ADS, kantDays=kantDays, joke=joke))
    resp.set_cookie('seen', ':'.join(str(x) for x in seenAry))
    resp.set_cookie('len', str(len(seenSet)))
    return resp
Beispiel #6
0
def serveComic(curComicInput=None, lang='en'):
    import dao

    d0 = date(2013, 11, 12)
    today = date.today()
    delta = today - d0
    kantDays = delta.days

    # cookie which tracks which comics have been seen already
    seenComics = request.cookies.get('seen')

    curComic = None
    try:
        curComic = long(curComicInput)
    except ValueError:
        return page_not_found(None)

    maxComic = dao.getMaxComic()
    if curComic is None:
        curComic = maxComic

    comic = dao.getComic(curComic, lang)
    if comic is None:
        return page_not_found(None)

    philosophers = dao.getPhilosophersByComic(comic.comicId)

    joke = dao.getRandomJoke()

    navMaps = []
    titleMaps = []

    langUrl = ""
    if (lang != 'en'):
        langUrl = lang + '/'

    nextComic = int(comic.comicId) + 1
    firstComic = 1
    prevComic = int(comic.comicId) - 1
    lastComic = int(maxComic)
    if int(comic.comicId) == int(maxComic):
        titleImg = s.STATIC_URL + '/title_last.jpg'
        navImg = s.STATIC_URL + '/nav_last.jpg'
        lastComic = None
        nextComic = None
    elif int(comic.comicId) == 1:
        titleImg = s.STATIC_URL + '/title_first.jpg'
        navImg = s.STATIC_URL + '/nav_first.jpg'
        firstComic = None
        prevComic = None
    else:
        titleImg = s.STATIC_URL + '/title.jpg'
        navImg = s.STATIC_URL + '/nav.jpg'

    seenSet = set()
    seenAry = list()
    seen = 0
    if seenComics != None:
        seenAry = seenComics.split(':')
        for i in seenAry:
            if i.isdigit():
                if i == curComic:
                    seen = 1
                seenSet.add(int(i))
        if len(seenSet) + 1 >= maxComic:
            seenAry = list()
    if seen == 0:
        seenAry.append(curComic)

    resp = make_response(
        render_template('comic.html',
                        comic=comic,
                        philosophers=philosophers,
                        titleImg=titleImg,
                        navImg=navImg,
                        titleMaps=titleMaps,
                        firstComic=firstComic,
                        prevComic=prevComic,
                        nextComic=nextComic,
                        lastComic=lastComic,
                        langUrl=langUrl,
                        static=s.STATIC_URL,
                        showAds=s.SHOW_ADS,
                        kantDays=kantDays,
                        joke=joke))
    resp.set_cookie('seen', ':'.join(str(x) for x in seenAry))
    resp.set_cookie('len', str(len(seenSet)))
    return resp
Beispiel #7
0
def home():
    import dao
    return serveComic(dao.getMaxComic())
def home():
    import dao
    return serveComic(dao.getMaxComic())