Turbowolf Turbowolf - 7 months ago 36
JSON Question

Import .json to Database

I successfully downloaded tweets into a json file. Now I try to import it in a database with this function:

def import_json(fi):

logging.warning("Loading tweets from json file {0}".format(fi))
for line in open(fi, "rb"):
data = json.loads(line.decode('utf-8'))

the json-file "keywords_BVBS04.json" lays in a folder called data which is in the current directory. The function is in a file called BVBS04.py

to start the import I type BVBS04.import_json(keywords_BVBS04.json) in ipython in the console. this is what I get back:

NameError Traceback (most recent call
last) in ()
----> 1 BVBS04.import_json(keywords_BVBS04.json)

NameError: name 'keywords_BVBS04' is not defined

Now here comes the is a beginner's question: Where/how do I have to define "keywords_BVBS04"? I tried a lot :(



This is what you want,

1) you need to import the function from the script, not use dot-notation on the script.

2) Quote the filename.

>>> from BVBS04 import import_json
>>> import_json("keywords_BVBS04.json")

Good luck with the rest of things