2323 film.py http://www.imdb.com/title/tt0105236/
2424 Review the movie "Reservoir Dogs"
2525"""
26- import datetime , os , sys , re , time
26+ import datetime
27+ import os
28+ import sys
29+ import re
30+ import time
2731
2832try :
2933 import imdb
3640
3741storefn = os .path .expanduser ('~/movies.n3' )
3842#storefn = '/home/simon/codes/film.dev/movies.n3'
39- storeuri = 'file://' + storefn
43+ storeuri = 'file://' + storefn
4044title = 'Movies viewed by %s'
4145
4246r_who = re .compile ('^(.*?) <([a-z0-9_-]+(\.[a-z0-9_-]+)*@[a-z0-9_-]+(\.[a-z0-9_-]+)+)>$' )
4347
4448IMDB = Namespace ('http://www.csd.abdn.ac.uk/~ggrimnes/dev/imdb/IMDB#' )
4549REV = Namespace ('http://purl.org/stuff/rev#' )
4650
51+
4752class Store :
4853 def __init__ (self ):
4954 self .graph = ConjunctiveGraph ()
@@ -61,12 +66,14 @@ def who(self, who=None):
6166 if who is not None :
6267 name , email = (r_who .match (who ).group (1 ), r_who .match (who ).group (2 ))
6368 self .graph .add ((URIRef (storeuri ), DC ['title' ], Literal (title % name )))
64- self .graph .add ((URIRef (storeuri + '#author' ), RDF .type , FOAF ['Person' ]))
65- self .graph .add ((URIRef (storeuri + '#author' ), FOAF ['name' ], Literal (name )))
66- self .graph .add ((URIRef (storeuri + '#author' ), FOAF ['mbox' ], Literal (email )))
69+ self .graph .add ((URIRef (storeuri + '#author' ), RDF .type , FOAF ['Person' ]))
70+ self .graph .add ((URIRef (storeuri + '#author' ),
71+ FOAF ['name' ], Literal (name )))
72+ self .graph .add ((URIRef (storeuri + '#author' ),
73+ FOAF ['mbox' ], Literal (email )))
6774 self .save ()
6875 else :
69- return self .graph .objects (URIRef (storeuri + '#author' ), FOAF ['name' ])
76+ return self .graph .objects (URIRef (storeuri + '#author' ), FOAF ['name' ])
7077
7178 def new_movie (self , movie ):
7279 movieuri = URIRef ('http://www.imdb.com/title/tt%s/' % movie .movieID )
@@ -76,14 +83,14 @@ def new_movie(self, movie):
7683 self .save ()
7784
7885 def new_review (self , movie , date , rating , comment = None ):
79- review = BNode () # @@ humanize the identifier (something like #rev-$date)
86+ review = BNode () # @@ humanize the identifier (something like #rev-$date)
8087 movieuri = URIRef ('http://www.imdb.com/title/tt%s/' % movie .movieID )
8188 self .graph .add ((movieuri , REV ['hasReview' ], URIRef ('%s#%s' % (storeuri , review ))))
8289 self .graph .add ((review , RDF .type , REV ['Review' ]))
8390 self .graph .add ((review , DC ['date' ], Literal (date )))
8491 self .graph .add ((review , REV ['maxRating' ], Literal (5 )))
8592 self .graph .add ((review , REV ['minRating' ], Literal (0 )))
86- self .graph .add ((review , REV ['reviewer' ], URIRef (storeuri + '#author' )))
93+ self .graph .add ((review , REV ['reviewer' ], URIRef (storeuri + '#author' )))
8794 self .graph .add ((review , REV ['rating' ], Literal (rating )))
8895 if comment is not None :
8996 self .graph .add ((review , REV ['text' ], Literal (comment )))
@@ -92,9 +99,11 @@ def new_review(self, movie, date, rating, comment=None):
9299 def movie_is_in (self , uri ):
93100 return (URIRef (uri ), RDF .type , IMDB ['Movie' ]) in self .graph
94101
102+
95103def help ():
96104 print (__doc__ .split ('--' )[1 ])
97105
106+
98107def main (argv = None ):
99108 if not argv :
100109 argv = sys .argv
@@ -136,6 +145,7 @@ def main(argv=None):
136145 else :
137146 help ()
138147
148+
139149if __name__ == '__main__' :
140150 if not imdb :
141151 raise Exception ('This example requires the IMDB library! Install with "pip install imdbpy"' )
0 commit comments