Exemple #1
0
def crawler():
    print "开始任务 [%s] -- \r\n" % (time.strftime("%Y-%m-%d %H:%M:%S",
                                               time.localtime(time.time())))
    resp = requests.get(
        "http://movie.youku.com/?spm=a2hww.20023042.topNav.5~1~3!3~A")
    resp.encoding = "utf-8"
    soup = BeautifulSoup(resp.text, "html5lib")
    div = soup.find(id="m_86988")
    cols = div.findAll("div", attrs={"class": "yk-col4"})
    for col in cols:

        is_hovers = col.findAll("div", attrs={"class": "v ishover"})
        for is_hover in is_hovers:
            # print col
            link = is_hover.find("div", attrs={"class": "v-link"}).a['href']
            # print link
            cover = is_hover.div.img["_src"]
            title = is_hover.find("div", attrs={"class": "v-meta-title"}).text
            has = movies.movies.query.filter(
                movies.movies.title == title).first()
            if not has:
                new_data = movies.movies(
                    title, cover, "优酷",
                    time.strftime("%Y-%m-%d %H:%M:%S",
                                  time.localtime(time.time())), link, "院线热映")
                dbSession.add(new_data)
                dbSession.commit()
                dbSession.close()
                time.sleep(0.5)
Exemple #2
0
def pages():
    if request.method == 'POST': # put page
        title = request.form['title']
        menuId = request.form['menuId']
        page = Page(title=title, menuId=menuId)
        dbSession.add(page)
        dbSession.commit()
        return 'done'
    else:
        return 'done'
Exemple #3
0
def menus():
    if request.method == 'POST':
        menu = Menu(title=request.form['title'])
        dbSession.add(menu)
        dbSession.commit()

        return 'done'
    else:        
        menus = getMenusWithPages()

        data = {
            "menus" : menus
        }
        return flask.jsonify(**data)
Exemple #4
0
def reorderMenu(menuId, pageId=None, targetOrder=None):
    menu = dbSession.query(Menu).get(menuId)

    pages = dbSession.query(Page).order_by(Page.order).all()

    # make sure the page is in the correct spot
    if pageId:
        index = map(lambda page: page.id, pages).index(pageId)
        if index != targetOrder:
            pages.insert(targetOrder, pages.pop(index))

    for i,page in enumerate(pages):
        page.order = i
    dbSession.commit()
Exemple #5
0
def pageOrder(pageId):
    page = dbSession.query(Page).get(pageId)

    prevOrder = int(request.form['srcIndex'])
    targetOrder = int(request.form['targetIndex'])

    srcMenuId = request.form['srcMenuId']
    targetMenuId = request.form['targetMenuId']

    # remove from one, put in another
    if targetMenuId != srcMenuId:
        page.menuId = targetMenuId
        dbSession.commit()

    reorderMenu(targetMenuId, pageId, targetOrder)

    return 'done'
Exemple #6
0
def header(forcedName=None):
    if request.method == 'POST':
        fileName = secure_filename(urlparse.unquote(request.headers['X-File-Name']))
        if allowed_file(fileName):
            filePath = os.path.join(app.config['UPLOAD_FOLDER'], fileName)
            with open(filePath, 'w') as fd:
                fd.write(request.data)

            # delete existing header
            dbSession.query(ImageTag).filter(ImageTag.tag == "header").delete()

            tag = ImageTag(hash=md5(filePath), tag='header', path=fileName)
            dbSession.add(tag)
            dbSession.commit()

        return 'done'
    else:
        imageTag = dbSession.query(ImageTag).filter(ImageTag.tag == "header").first()
        data = { 'url' : _getHeaderUrl() }

        return flask.jsonify(**data)
Exemple #7
0
#coding=utf-8
from models import Posts,dbSession



new = Posts.Posts("搞","萌")

dbSession.add(new)
dbSession.commit()
dbSession.close()

Exemple #8
0
def page(pageId):
    page = dbSession.query(Page).get(pageId)
    page.title = request.form['title']
    dbSession.commit()

    return 'done'
Exemple #9
0
def menu(menuId):
    menu = dbSession.query(Menu).get(menuId)
    menu.title = request.form['title']
    dbSession.commit()

    return 'done'