-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.py
67 lines (47 loc) · 1.25 KB
/
fetch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python2.6
import warnings
warnings.simplefilter("ignore",DeprecationWarning)
# Just testing now
import rdflib
from rdflib.Graph import ConjunctiveGraph as Graph
from rdflib import Namespace
from rdflib import Literal
from rdflib import URIRef
from rdflib import plugin
from rdflib.store import Store, NO_STORE, VALID_STORE
from rdflib.store import SQLite
from rdfstore.RdfStore import RdfStore
from web2rdf.Web2Rdf import Web2Rdf
import sys
# Return string IO
def rdfString(string):
from cStringIO import StringIO
return StringIO(string)
# Main function
def main():
"""Main Function
Simple command-line procedure for web2rdf."""
if len(sys.argv) != 2:
print "Must call with a URI parameter."
print "Usage: %s uriSrc" % sys.argv[0]
return
uri = sys.argv[1]
# Get the RDF
wrdf = Web2Rdf(uri)
rdf = wrdf.getRdf()
if not rdf:
print "No RDF returned!"
return False
print "Got RDF..."
rdf = rdfString(rdf)
# Open Storage
print "Opening store..."
db = "./testdb.sqlite"
rstore = RdfStore('sqlite', db)
rstore.open()
print "Storing..."
graph = Graph(rstore.get(), identifier = URIRef("http://slashdot/Test2"))
#graph.parse("example.rdf")
graph.parse(rdf, publicID=uri)
graph.commit()
if __name__ == '__main__': main()