第一
错误:
ERROR 2011-04-22 23:25:15,513 __init__.py:395] unbound method put() must be called with Movie instance as first argument (got nothing instead)
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 515, in __call__
handler.get(*groups)
File "C:\Users\Jimenez\workspace\elmovieplace\src\script/crawl.py", line 86, in get
getImdbData(year, findPatGamma, findPatGamma2)
File "C:\Users\Jimenez\workspace\elmovieplace\src\script/crawl.py", line 66, in getImdbData
movie.put()
TypeError: unbound method put() must be called with Movie instance as first argument (got nothing instead)
crawl.py:
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from urllib2 import urlopen
from Classes import Movie
import re
def getImdbData(year, findPatGamma, findPatGamma2):
templistone = []
templisttwo = []
listIterator = []
listIterator[:] = range(len(findPatGamma))
for gi in listIterator:
deltaUrl = findPatGamma[gi]
deltaPage = urlopen(deltaUrl).read()
print deltaUrl
simpleone = (re.findall(re.compile("""id='hmovie'.*[^\n]src='|"(.*[^\n])'|".*[^\n]"""),deltaPage))[0]
templistone.append(simpleone)
simpletwo = (re.findall(re.compile("<title>Project Free TV - (.*) video</title>"),deltaPage))[0]
templisttwo.append(simpletwo)
movie = Movie
url = 'http://www.imdbapi.com/?plot=full&t=' + findPatGamma2[0] + '&y=' + year
imdbPage = urlopen(url).read()
imdbValues, = re.findall(re.compile('{"Title":"(.*)","Year":"(.*)","Rated":"(.*)","Released":"(.*)","Genre":"(.*)","Director":"(.*)","Writer":"(.*)","Actors":"(.*)","Plot":"(.*)","Poster":"(.*)","Runtime":"(.*)","Rating":"(.*)","Votes":"(.*)","ID":"(.*)","Response":"(.*)"}'),imdbPage)
movie.title = imdbValues[0]#done
if imdbValues[1] == 'N/A':
movie.rated = ''
else:
movie.rated = imdbValues[2]#done
if imdbValues[3] == 'N/A':
movie.releaseDate = 'jan 1 1990'
else:
movie.releaseDate = imdbValues[3]
if imdbValues[4] == 'N/A':
movie.tags = [];
else:
movie.tags = re.findall(re.compile('(\w*[^\s|,])'),imdbValues[4])#done
if imdbValues[5] == 'N/A':
movie.diector = ''
else:
movie.director = imdbValues[5],#done
if imdbValues[6] == 'N/A':
movie.writer = ''
else:
movie.writer = imdbValues[6],#done
if imdbValues[7] == 'N/A':
movie.actors = []
else:
movie.actors = re.findall(re.compile('(\w*[^\s|,])'),imdbValues[7])#done
if imdbValues[8] == 'N/A':
movie.description = ''
else:
movie.description = imdbValues[8]#done
if imdbValues[9] == 'N/A':
movie.pic = ''
else:
movie.pic = imdbValues[9]#done
if imdbValues[10] == 'N/A':
movie.length = 0
else:
movie.length = (60 * int((re.findall(re.compile('(.*) hrs .* mins'),imdbValues[10]))[0])) + int((re.findall(re.compile('.* hrs (.*) mins'),imdbValues[10]))[0])#done
movie.uniqueID = imdbValues[13]#done
movie.hostNames = templisttwo
movie.hostUrls = templistone
movie.put()
return
class MyHandler(webapp.RequestHandler):
def get(self):
year = '2011'
betaUrl = 'http://www.free-tv-video-online.me/movies/' + year + '/'
betaPage = urlopen(betaUrl).read()
patFinderBeta = re.compile('<td width="97%" class="mnlcategorylist"><a href="(.*)">')
findPatBeta = re.findall(patFinderBeta,betaPage)
listIteratorBeta = []
listIteratorBeta[:] = range(len(findPatBeta))
for bi in listIteratorBeta:
gammaUrl = betaUrl + findPatBeta[bi]
gammaPage = urlopen(gammaUrl).read()
patFinderGamma = re.compile('<a href="(.*[^\n])" target="_blank" class="mnllinklist">')
findPatGamma = re.findall(patFinderGamma,gammaPage)
patFinderGamma2 = re.compile('<meta name="keywords"content="(.*)">')
findPatGamma2 = re.findall(patFinderGamma2,gammaPage)
getImdbData(year, findPatGamma, findPatGamma2)
ip = self.request.remote_addr
template_values = {
'username': ip,
}
self.response.out.write(template.render('template\crawl.html', template_values))
def main():
app = webapp.WSGIApplication([(r'.*', MyHandler)],debug=True)
wsgiref.handlers.CGIHandler().run(app)
if __name__ == '__main__':
main()
Classes.py:
from google.appengine.ext import db
class Movie(db.Model):
title = db.StringProperty()
hostNames = db.StringProperty()
hostUrls = db.StringListProperty()
releaseDate = db.DateProperty()
uniqueID = db.StringProperty(default='000000')
playcount = db.IntegerProperty(default='0')
length = db.IntegerProperty()
rated = db.StringProperty()
description = db.StringProperty()
tags = db.StringListProperty()
director = db.StringProperty()
writer = db.StringProperty()
actors = db.StringProperty()
pic = db.StringProperty()
我环顾了一些帖子(换句话说,我现在一直在寻找一天),但我无法弄清楚我做错了什么。
顺便说一下,我的问题并没有表现出来,我对此很陌生。答案 0 :(得分:6)
从
更改movie = Movie
到
movie = Movie()
您需要实际创建Movie
类的实例,这是Movie()
所做的。 (您收到的错误消息中的关键字是“Movie
实例”。)