コード例 #1
0
def new_picture(picid):
    pic = Rawpicture.objects(id=picid).first()
    piclinkb64 = base64encode(pic.piclink)
    token = ''
    if request.method == 'GET':
        if 'token' in session:
            token = session['token']
        if 'picid' in session:
            if ("'" + picid + "'") in session['picid']:
                unsavelink = session['picid'].replace("'" + picid + "'", '')
                del session['picid']
                return render_template('new_picture.html',
                                       piclinkb64=unsavelink,
                                       resetlinkb64=piclinkb64,
                                       token=token)
            else:
                return render_template('new_picture.html',
                                       piclinkb64=piclinkb64,
                                       resetlinkb64=piclinkb64,
                                       token=token)
        else:
            return render_template('new_picture.html',
                                   piclinkb64=piclinkb64,
                                   resetlinkb64=piclinkb64,
                                   token=token)
    elif request.method == 'POST':
        form = request.form
        # nếu người dùng chưa đăng nhập:
        if 'token' not in session:
            unsavelink = form['unsavelink']
            session[
                'picid'] = "'" + picid + "'" + unsavelink  # thêm dấu nháy bọc quanh picid để phòng trường hợp trong chuỗi base64 có 1 đoạn ký tự trùng với picid
            return redirect(url_for('login'))
        # nếu người dùng đã đăng nhập:
        if 'token' in session:
            token = session['token']
            picname = form['picname']
            piclink = form['piclink']
            picstatus = form['picstatus']
            picartist = token
            picartistfullname = User.objects(username=token).first().fullname
            newlink = Savepicture(piclink=piclink,
                                  picname=picname.strip(),
                                  picstatus=picstatus,
                                  picartist=picartist,
                                  picartistfullname=picartistfullname,
                                  picrawid=picid)
            newlink.save()
            newid = Savepicture.objects(piclink=piclink).first().id
            # Update database của user tương ứng:
            working_arts = User.objects(username=token).first().working_arts
            finished_arts = User.objects(username=token).first().finished_arts
            if picstatus == 'working':
                User.objects(username=token).first().update(
                    set__working_arts=working_arts + 1)
            elif picstatus == 'finished':
                User.objects(username=token).first().update(
                    set__finished_arts=finished_arts + 1)
            return redirect(url_for('saved', picid=newid))
コード例 #2
0
def full_category():
    # Lấy id của 1 random pic, sử dụng trong mục Get me a random pic:
    pic_list = Rawpicture.objects()
    random_pic = choice(pic_list)
    categories = [
        'Aladdin', 'Christmas', 'Cinderella', 'Angry-Birds', 'Dragon Ball Z',
        'Ben-10', 'Adiboo', '101 Dalmatians'
    ]
    category_list = []
    for c in categories:
        piclink = Rawpicture.objects(category__icontains=c).first().piclink
        category = {
            'category': c,
            'name': c.replace('-', ' ').title(),
            'label': piclink
        }
        category_list.append(category)
    return render_template('category.html',
                           random_pic=random_pic,
                           category_list=category_list)
コード例 #3
0
def one_category(category):
    pic_list = Rawpicture.objects(category__icontains=category)
    cap_category = category.replace('-', ' ').title()
    button_list = []
    later_list = []
    if 'token' in session:
        later_list = Mylistpicture.objects(user=session['token'],
                                           art_type='colorlater')
        for l in later_list:
            a = Rawpicture.objects(id=l.art_id).first()
            button_list.append(a.id)
    if request.method == 'GET':
        return render_template('one_category.html',
                               pic_list=pic_list,
                               category=cap_category,
                               button_list=button_list)
    if request.method == 'POST':
        form = request.form
        for pic in pic_list:
            a = 'a' + str(pic.id)
            if a in form:
                a_id = form[a]
                colorlater_check = Mylistpicture.objects(
                    user=session['token'], art_id=a_id,
                    art_type='colorlater').first()
                a_pic = Rawpicture.objects(id=a_id).first()
                if colorlater_check is None:
                    new_later = Mylistpicture(user=session['token'],
                                              art_id=a_id,
                                              art_type='colorlater')
                    new_later.save()
                    button_list.append(a_pic.id)
                else:
                    colorlater_check.delete()
                    button_list.remove(a_pic.id)
        return render_template('one_category.html',
                               pic_list=pic_list,
                               category=cap_category,
                               button_list=button_list)
コード例 #4
0
ファイル: app.py プロジェクト: hoangcuong9x/abcccccc
def new_picture(picid):
    pic = Rawpicture.objects(id=picid).first()
    piclinkb64 = base64encode(pic.piclink)
    token = ''
    aftersave = ''
    if 'token' in session:
        token = session['token']
    if request.method == 'GET':
        aftersave = 'no'
        return render_template('new_picture.html',
                               piclinkb64=piclinkb64,
                               token=token,
                               aftersave=aftersave)
    elif request.method == 'POST':
        aftersave = 'yes'
        form = request.form
        picname = form['picname']
        piclink = form['piclink']
        picstatus = form['picstatus']
        picartist = token
        picartistfullname = User.objects(username=token).first().fullname
        newlink = Savepicture(piclink=piclink,
                              picname=picname,
                              picstatus=picstatus,
                              picartist=picartist,
                              picartistfullname=picartistfullname)
        newlink.save()
        # Update database của user tương ứng:
        working_arts = User.objects(username=token).first().working_arts
        finished_arts = User.objects(username=token).first().finished_arts
        if picstatus == 'working':
            User.objects(username=token).first().update(
                set__working_arts=working_arts + 1)
        elif picstatus == 'finished':
            User.objects(username=token).first().update(
                set__finished_arts=finished_arts + 1)
        return render_template('new_picture.html',
                               piclinkb64=piclink,
                               aftersave=aftersave)
コード例 #5
0
def search():
    if request.method == 'GET':
        return render_template('search.html')
    elif request.method == 'POST':
        form = request.form
        searchword = form['searchword']
        field1 = form.get(
            'field1'
        )  # form checkbox dùng form.get['inputname'] thay vì form['inputname']
        field2 = form.get(
            'field2'
        )  # kết quả trả về là none hoặc value của checkbox. nếu đặt name các checkbox giống nhau thì trả về 1 list value (?)
        field3 = form.get('field3')
        raw_list = []
        finished_list = []
        artist_list = []
        warn1 = warn2 = warn3 = ''
        display = display1 = display2 = display3 = 'no'
        s_list = []
        if searchword != '':
            display = 'yes'
            s_list = searchword.replace('-', ' ').split()
            for s in s_list:
                r_list = Rawpicture.objects(
                    Q(picname__icontains=s) | Q(category__icontains=s))
                for r in r_list:
                    if r not in raw_list:
                        raw_list.append(r)
                f_list = Savepicture.objects(picstatus='finished',
                                             picname__icontains=s)
                for f in f_list:
                    if f not in finished_list:
                        finished_list.append(f)
                a_list = User.objects(
                    Q(username__icontains=s) | Q(fullname__icontains=s))
                for a in a_list:
                    if a not in artist_list:
                        artist_list.append(a)
        if len(raw_list) == 0:
            warn1 = 'No raw picture found!'
        if len(finished_list) == 0:
            warn2 = 'No finished picture found!'
        if len(artist_list) == 0:
            warn3 = 'No artist found!'
        if field1 is not None:
            display1 = 'yes'
        if field2 is not None:
            display2 = 'yes'
        if field3 is not None:
            display3 = 'yes'
        if (field1 is None) and (field2 is None) and (field3 is None):
            display1 = display2 = display3 = 'yes'
        return render_template('search.html',
                               searchword=searchword,
                               raw_list=raw_list,
                               finished_list=finished_list,
                               artist_list=artist_list,
                               warn1=warn1,
                               warn2=warn2,
                               warn3=warn3,
                               display=display,
                               display1=display1,
                               display2=display2,
                               display3=display3)
コード例 #6
0
def profile(artist):
    artist_infor = User.objects(username=artist).first()
    working_arts = artist_infor.working_arts
    finished_arts = artist_infor.finished_arts
    totallikes = artist_infor.totallikes
    finished_list = Savepicture.objects(
        picartist=artist, picstatus='finished')  # .order_by('-piclikes')
    working_list = Savepicture.objects(picartist=artist, picstatus='working')
    colorlaters = Mylistpicture.objects(user=artist, art_type='colorlater')
    colorlater_list = []
    for c in colorlaters:
        pic = Rawpicture.objects(id=c.art_id).first()
        colorlater_list.append(pic)
    c_length = len(colorlater_list)
    favorites = Mylistpicture.objects(user=artist, art_type='favorite')
    favorite_list = []
    for m in favorites:
        pic = Savepicture.objects(id=m.art_id).first()
        favorite_list.append(pic)
    m_length = len(favorite_list)
    display = 'no'
    if 'token' in session:
        if session['token'] == artist:
            display = 'yes'
    if request.method == 'GET':
        return render_template('profile.html',
                               m_length=m_length,
                               c_length=c_length,
                               display=display,
                               artist_infor=artist_infor,
                               working_arts=working_arts,
                               finished_arts=finished_arts,
                               totallikes=totallikes,
                               finished_list=finished_list,
                               working_list=working_list,
                               colorlater_list=colorlater_list,
                               favorite_list=favorite_list)
    elif request.method == 'POST':
        form = request.form
        for fpic in finished_list:
            df = 'df' + str(fpic.id)
            if df in form:
                f_picid = form[df]
                pic = Savepicture.objects(id=f_picid).first()
                pic.delete()
                finished_arts = artist_infor.finished_arts - 1
                totallikes = artist_infor.totallikes - pic.piclikes
                artist_infor.update(
                    set__finished_arts=artist_infor.finished_arts - 1,
                    set__totallikes=artist_infor.totallikes - pic.piclikes)
        for wpic in working_list:
            up = 'up' + str(wpic.id)
            dw = 'dw' + str(wpic.id)
            if up in form:
                u_picid = form[up]
                Savepicture.objects(id=u_picid).first().update(
                    set__picstatus="finished")
                working_arts = artist_infor.working_arts - 1
                artist_infor.update(
                    set__working_arts=artist_infor.working_arts - 1)
                finished_arts = artist_infor.finished_arts + 1
                artist_infor.update(
                    set__finished_arts=artist_infor.finished_arts + 1)
            if dw in form:
                w_picid = form[dw]
                Savepicture.objects(id=w_picid).first().delete()
                working_arts = artist_infor.working_arts - 1
                artist_infor.update(
                    set__working_arts=artist_infor.working_arts - 1)
        for pic in colorlater_list:
            c = 'c' + str(pic.id)
            if c in form:
                c_id = form[c]
                art = Mylistpicture.objects(art_id=c_id).first()
                art.delete()
        for pic in favorite_list:
            m = 'm' + str(pic.id)
            if m in form:
                m_id = form[m]
                art = Mylistpicture.objects(art_id=m_id).first()
                art.delete()
        finished_list = Savepicture.objects(
            picartist=artist, picstatus='finished')  # .order_by('-piclikes')
        working_list = Savepicture.objects(picartist=artist,
                                           picstatus='working')
        colorlaters = Mylistpicture.objects(user=artist, art_type='colorlater')
        colorlater_list = []
        for c in colorlaters:
            pic = Rawpicture.objects(id=c.art_id).first()
            colorlater_list.append(pic)
        c_length = len(colorlater_list)
        favorites = Mylistpicture.objects(user=artist, art_type='favorite')
        favorite_list = []
        for m in favorites:
            pic = Savepicture.objects(id=m.art_id).first()
            favorite_list.append(pic)
        m_length = len(favorite_list)
        return render_template('profile.html',
                               m_length=m_length,
                               c_length=c_length,
                               display=display,
                               artist_infor=artist_infor,
                               working_arts=working_arts,
                               finished_arts=finished_arts,
                               totallikes=totallikes,
                               finished_list=finished_list,
                               working_list=working_list,
                               colorlater_list=colorlater_list,
                               favorite_list=favorite_list)
コード例 #7
0
def one_category(category):
    pic_list = Rawpicture.objects(category__icontains=category)
    cap_category = category.title()
    return render_template('one_category.html',
                           pic_list=pic_list,
                           category=cap_category)
コード例 #8
0
def full_category():
    # Lấy id của 1 random pic, sử dụng trong mục Get me a random pic:
    pic_list = Rawpicture.objects()
    random_picid = choice(pic_list).id
    # category_list = Rawpicture.objects() # Sau sẽ xử lý hiển thị tất cả các category trong html bằng vòng for
    return render_template('category.html', random_picid=random_picid)
コード例 #9
0
ファイル: crawl_raw_data.py プロジェクト: hoangcuong9x/hihi

def make_soup(url):
    thepage = urllib.request.urlopen(url)
    soupdata = BeautifulSoup(thepage, "html.parser")
    return soupdata


# soup = make_soup("http://www.coloring-book.info/coloring/coloring_page.php?id=7")
soup = make_soup(
    "http://www.coloring-book.info/coloring/coloring_page.php?id=4")

infor_list = soup.findAll('img')
sourcelist = []
for i in infor_list:
    if '.jpg' in i.get('src'):
        sourcelist.append(i)
for img in sourcelist:
    temp = img.get('src')
    tmp = temp.replace("_m", "").replace("/thumbs", "")
    image = "http://www.coloring-book.info/coloring/" + tmp if "http" not in tmp else tmp
    category = ''
    for i in tmp:
        if i != "/":
            category += i
        else:
            break
    picname = tmp.replace(category, '').replace('.jpg', '').replace('/', '')
    rawpic = Rawpicture(picname=picname, piclink=image, category=category)
    rawpic.save()
コード例 #10
0
ファイル: app.py プロジェクト: hoangcuong9x/test
def new_picture(picid):
    pic = Rawpicture.objects(id=picid).first()
    piclinkb64 = base64encode(pic.piclink)
    return render_template('new_picture.html', piclinkb64=piclinkb64)
コード例 #11
0
ファイル: app.py プロジェクト: hoangcuong9x/test
    # 1. Thông tin của artist:
    #   - Tên đầy đủ của artist: artist_fullname
    #   - Số bức tranh đã hoàn thành: finished_arts
    #   - Số bức tranh đang vẽ: working_arts. (Cái này chỉ hiện ra nếu ở trang profile của mình, còn của người khác chỉ hiện finished_arts thôi)
    #   - Bỏ: Số bức tranh trong top 100: picsintop100 (bằng 0 là không có bức nào)
    #   - Bỏ: Thứ hạng trong 100 artist: positionintop100 (bằng 0 là không nằm trong danh sách)
    # 2. Thông tin từng bức vẽ đã hoàn thành, bao gồm:
    #   - Bỏ: Thứ hạng trong top 100 pics nếu bức đó lọt vào: positionintop100
    #   - Tên bức tranh: picname
    #   - Link ảnh để hiển thị: piclink
    #   - Số lượng like: piclikes
    #   - Số lượng comment: piccomments


# Lấy link của 1 random pic:
pic_list = Rawpicture.objects()
random_picid = choice(pic_list).id


@app.route('/category')  # Hiển thị trang Category tổng
def full_category():
    # category_list = Rawpicture.objects() # Sau sẽ xử lý hiển thị tất cả các category trong html bằng vòng for
    return render_template('category.html', random_picid=random_picid)


@app.route('/category/<category>')  # Hiển thị 1 trang category cụ thể
def one_category(category):
    pic_list = Rawpicture.objects(category__icontains=category)
    cap_category = category.title()
    return render_template('one_category.html',
                           pic_list=pic_list,